Java Reference
In-Depth Information
ServerFactory object is factory and the instance name of the Server object is
server .Inthe first message (i.e. sequence number 1), the client already holds a ref-
erence to factory and calls its getInstance() method. The return is an object
of type Server , though that is not explicitly shown in the diagram. The name of
the returned value is server ,which is explicitly shown. Since the diagrams may
be confusing at first we emphasize that the sequence numbered messages are just
method calls in Java. In other words, what sequence number 1 really means in
Java code executed on the client is something like
Server server = factory.getInstance (ID);
In order to obtain the Server object to return, the ServerFactory creates
anew Server instance in sequence number 1.1, forwarding the ID parame-
ter received from the client. The notation { new } means that a new Server
instance is created during this step. The name of the Server object created
is server ,asindicated in the diagram. This name is the same as that returned in
sequence 1 because it is the same object. The factory then returns this server to the
client.
Once the client has a reference to its own private Server object, all further
interaction is between the client and that particular Server instance. All of
this interaction is indicated by the operate() method which takes various
unspecified arguments and returns unspecified results. In practice, there will
be numerous methods on Server that the client invokes to obtain numerous
different results. The details are highly dependent on the nature of the actual
services provided by the server and are not important here.
We have so far glossed over how the client got a reference to the ServerFac-
tory to begin with. Recall that in a distributed application, the ServerFactory
must be constantly running on a server machine somewhere on the Internet, wait-
ing on clients to connect to it to obtain their private Server objects. But how does
a client object obtain the original reference to the ServerFactory ? The answer
is through a naming service, which is a well-known service that must be running
somewhere accessible to the client. The naming service functions somewhat like
afactory, but instead of creating new instances of the objects requested, it returns
a reference to an existing object - in this case, to the one single instance of the
ServerFactory that already exists. Since there is only one ServerFactory
object, it is referred to as a singleton , another very common design pattern.
In order to begin this bootstrap process, the client must know how to contact
the naming service and must know the proper protocol to request a reference
to the ServerFactory .Inthe Common Object Request Broker Architecture
(CORBA, the subject of Chapter 19) the naming service is known as CosNaming .
There is a certain, well-known protocol for contacting the CosNaming service
and requesting an object reference. In Java Remote Method Invocation (RMI, the
subject of Chapter 18), there is an rmiregistry running on the server machine
from which clients obtain server references. In both of these, clients request a
Search WWH ::




Custom Search