Java Reference
In-Depth Information
The class
LocalProxy
implements the
MarketProxy
interface for the single
process prototype. It has a few private attributes to keep track of the codes
of the currently connected employee, the current customer and the current
transaction. In addition the server attribute implements the association to
the
Market
interface.
This class implements all the methods of the interface. It ensures that the
normal operations are performed only after a connection has been made
(method
assertConnected()
). In addition it initiates a new transaction when
the first product is bought by a new customer.
package
Counter;
import
Market.Market;
public class
LocalProxy
implements
MarketProxy {
// code of the currently logged employee
private long
employee;
// information about the ongoing transaction
private long
customer;
private long
transaction;
// the actual server that carries on the processing
private
Market server;
// constructor
public
LocalProxy(Market server) {
this.server
#
server;
employee
#
0;
customer
#
0;
transaction
#
0;
}
// connects a terminal to the server and stores
// the code of the employee
public
String connect(
long
employee, String password)
throws
Exception{
String employeeName
#
server.authenticate(employee
,password);
if
(employeeName
##
null
)
return null
;
this
.employee
#
employee;
return
employeeName;
}
public void
disconnect() {
employee
#
0;
customer
#
0;
transaction
#
0;
}
// verify that a connection has been succesfully
// completed, otherwise throw an exception
private void
assertConnected()
throws
Exception {
if
(employee
##
0)
throw new
Exception("Not connected");
}