bind , rebind , and unbind lookup and list

public static Remote lookupString name These methods naturally divide into two sets: those called by the launch code and those called by clients. The launch-code methods, bind , unbind , and rebind , deal with the mechanics of inserting and removing servers from a registry. The client methods, list and lookup , deal with querying a registry to find a server.

14.2.1 bind , rebind , and unbind

These three methods deal with binding or unbinding a server into the registry. Each of them takes a string argument called name . In addition, bind and rebind take an instance of a class that implements the Remote interface. The first thing that any of them do is parse name to find out where the registry is running. name is a combination of the location of the RMI registry and the logical name of the server. That is, it is a URL with the following format: registryHost:portlogical_name Both host and port are optional. host defaults to the machine that makes the call, and port defaults to 1099. After parsing name , these methods form a socket connection to the actual registry. The registry is an RMI server running on the named host machine and listening on the indicated port. In the case of bind and rebind , they serialize the remote object e.g., serialize the stub that implements the Remote interface and pass it, along with logical_name , to the registry. The registry then proceeds to do one of two things: Reject the request If a bind was requested, and another object has already been bound to logical_name , the request will be rejected. Bind the object Otherwise, logical_name will be associated to the deserialized object that was received. Theres an interesting point here. What the registry receives is not the object itself, but the output of RMIs customized version of the serialization mechanism. That is, the registry deserializes a stub that knows how to communicate with the original server. In the case of unbind , the URL is parsed, and the registry is told to forget about whatever object was bound to logical_name .

14.2.2 lookup and list

lookup and list are similar to each other. Each begins by parsing their argument. In the case of lookup , name is a URL with the same format as the URL passed to bind , rebind , and unbind . In the case of list , the argument should be shorter, specifying only the machine and port for the RMI registry, but not a specific server. After parsing the URL, each opens a socket connection to the indicated registry and makes a method invocation. In the case of lookup , logical_name is passed; in the case of list , there are no arguments to send. lookup either throws an exception or returns a single stub to the calling application. This stub is a serialized copy of the stub bound into the registry under logical_name . And, hence, the client can use this stub to directly call methods on the server, without using the registry ever again. list returns an array of strings. These strings are the complete URLs, not just the logical names, of all the servers bound into the registry.

14.3 The RMI Registry Is an RMI Server