Java Reference
In-Depth Information
class implements the server interface, the Java code for the Server class begins
like this:
public class Server implements ServerInterface {...}
To illustrate this relationship in UML, there is one box for the ServerInter-
face class and another box for the Server . The Java implements relationship
(called realization in UML terminology) is shown as a dashed line with a hollow
arrowhead. As with inheritance, the arrowhead points to the parent.
The client obtains a reference to an object that implements ServerInter-
face . The only methods on the Server known to the client are those defined
in ServerInterface ,asimplified version of which is shown in the class dia-
gram in Figure 16.7. Here we see an attribute named MAX - SIZE in the central
section of the ServerInterface box. MAX - SIZE is an int ,asindicated, and
the
sign is UML notation signifying public access (see Chapter 5). Following
standard Java coding conventions, MAX - SIZE is all uppercase, indicating that
it is a constant. The idea here is that MAX - SIZE will be used to define the size
of the data arrays passed between client and server. An actual working example
would probably use dynamic array allocation instead of fixed array sizes, but the
usage here serves as a good example of the use of UML attributes.
We also see the three publicly exposed methods, initialize() ,
receiveInput() , and retrieveData() . The initialize() method
receives a size parameter which specifies the size of the data arrays (up to a
pre-compiled maximum of MAX - SIZE in this example) and returns a boolean
indicating success or failure of the initialization operation. The client provides
a float array of input data to the server in the receiveInput() method,
which returns void .Weassume that the calculation begins (i.e. the “start” mes-
sage, sequence 3 in Figure 16.6) when the server receives and processes the
receiveInput() call. As the server is running the simulation, the client must
periodically call the retrieveData() method, obtaining a float array of
results in return. There can be a special sentinel value in one of the array ele-
ments when the simulation is complete. For the control data sent from the client to
the server, we could define a receiveControlData() method on the server
that would receive an array of control data of some kind. However, it is usually
more convenient simply to add a parameter to the retrieveData() method
containing the control data as shown. That is, the current set of control data
could be sent to the server during each retrieveData() operation rather than
creating a new method just to receive the control data. If no new control data is
available when the client calls retrieveData() , then null or the previous
control set could be sent, a convention that must be agreed to by both client and
server.
The technique for obtaining the server's data illustrated here is called “polling,”
in which the client periodically polls the server for new results. An alternative
+
Search WWH ::




Custom Search