Java Reference
In-Depth Information
the gateway in the startSimulation() call. The gateway then sends these
initialization parameters to the server's receiveInput() method.
After initializing the simulation, the gateway tells the PollerThread to
begin polling and then calls the server's start() method which starts the sim-
ulation actually running. PollerThread repeatedly polls the server by calling
retrieveData() . Whenever new data is received, PollerThread calls the
notifyObservers() method in the DataManager to cause the two observers
to update their output displays.
To reduce clutter in the diagram, we've omitted how the control data from
InputPane is communicated to PollerThread in order to pass it to the
server during the retrieveData() call. One method is for this flow to mimic
that of sequence 4's start simulation messages, but bypassing the receive-
Input() initialization call. Alternatively, a particularly elegant solution can
be had by making InputPane into an Observable and PollerThread an
Observer of InputPane . Then, when new control data is entered by the user
into InputPane , the PollerThread observer is notified of the changes, ready
to pass the new control set to the server during the next poll.
Through the process of creating this client collaboration diagram, we've
learned that the server needs another method that we forgot, or at least glossed
over, in Chapter 16. That missing method is the start() method that the client
uses to tell the server to begin running the simulation. In Chapter 16, we assumed
that the simulation would start at the end of the receiveInput() method, once
the calculation was initialized. However, we need a chance to begin polling after
initializing the simulation but before actually starting the simulation. Alterna-
tively, if we started the simulation and then started polling, we might miss the
first few data points. The astute reader can think of several other solutions to
this timing problem, including some more elegant ideas, but the most obvious
technique is to separate simulation initialization and simulation start into the two
receiveInput() and start() methods. We might also wish to change the
name of the receiveInput() method, first invented back in Chapter 16 while
designing the server with only a little thought about the client, to something more
descriptive like initializeSimulation() .
17.5 Improved client class diagram
By examining the collaboration diagram, we can now add some of the missing
pieces to the initial class diagram. This time we show some of the operations
identified while creating the collaboration diagram. We won't show the instantiate
methods since they're really object instantiations rather than methods anyway.
This more complete class diagram appears in Figure 17.3.
The only new UML notation used here is the italicized notifyObservers()
method in DataManager . Italics are used to indicate that a method is inherited
from a superclass. We've also switched to the initializeSimulation()
Search WWH ::




Custom Search