Java Reference
In-Depth Information
Notice that we keep a reference to the factory that created this Server instance
in the variable fFactory .Wealso keep a copy of this server object's unique
ID in the string fID ,which is useful to identify this server if we should need
to call any factory methods. In a real-world example, we might use the ID for
user authentication and authorization as described earlier. In this example, we
just keep a copy for possible later use.
We can implement collaboration sequences 1 and 2 during the constructor.
Sequence 1 is to create an instance of SimData :
fSimData = new SimData ();
Sequence 2 is to create an instance of SimulationThread ,giving it a copy of
the SimData reference:
fSimulationThread = new SimulationThread (fSimData);
That completes the Server constructor. To complete the implementation of the
ServerInterface ,wemust also implement initialize() , initial-
izeSimulation() , start() , and retrieveData() .
20.5.1.2 The initialize() method
Our initialize() method is quite simple. It receives a single String
initparam and does nothing at all with it. As explained above, initialize()
is provided to initialize the server object with information that is unknown at
Server construction time but available later. In this example, no additional
information is required. The initparam parameter is provided as a placeholder
for more complicated client/server problems that the reader may develop. It is a
good idea to keep track of whether or not the Server object has been initialized.
Therefore we set an instance variable fInitialized to true and then return
true to indicate a successful initialization:
public boolean initialize (String initparam)
throws RemoteException
{
// Log initparam here if desired
fInitialized = true;
return true;
}
20.5.1.3 The initializeSimulation() method
Our initializeSimulation() method is also quite simple. Recall that it
is called by the client to provide initial simulation data. (In the collaboration
diagram in Figure 17.2 initializeSimulation() was called receive-
Input() , the name invented early in our OOAD phase. Its name was changed
late in Chapter 17 to be more descriptive of its function after our analysis of
Search WWH ::




Custom Search