Java Reference
In-Depth Information
5.8.1.4
An interface is an “empty vessel.” Before any interface can be used, you must
have an actual class that implements the interface. In an RMI application, the
implementing class is the server (Example 5.11).
The class is named SessionImpl to emphasize its relationship with the
Session interface. There is no requirement to match up such names. Likewise,
the RMI name given, //penfold/Session , uses the interface name, but it
could use any name. It is a good idea to develop a naming convention for RMI
interfaces and their implementations. It is critical to develop naming conven-
tions for RMI registry names, particularly in production environments. With-
out a naming convention, it is difficult to avoid confusion and even chaos.
What happens when multiple business units develop RMI code destined for a
single production server, and they have all made an RMI interface named
Session , or Payment ? 18 Bad things happen.
There is no “one size fits all” naming convention that we can offer. Possi-
bilities include using package names in RMI registry names, using some element
of the business area as a component of the name (such as AccountingSession ,
ShippingSession , ExecutiveSession ). All that matters is that an unambigu-
ous standard be created and followed.
Let's spend some time talking about what this code does.
First, notice that the class extends UnicastRemoteObject . This is not
necessary, but using that as a base class saves a lot of server setup. There are
times when you would want to do such setup manually, but for our purpose
here it saves a lot of effort. The class also implements our remote interface.
The first method is a constructor that calls the superclass constructor. At
first glance, this is pointless. Any Java class gets a default constructor that just
calls the superclass constructor, so why is this here? It is here because the super-
class constructor throws RemoteException . If we didn't define a constructor
like the one here specifying that it throws RemoteException , the compiler
would complain that there is an unhandled exception. So we define a construc-
tor identical to a default constructor except that it specifies that it can throw
the exception.
Writing the Server Class
18. One solution is to use a more advanced naming system, such as LDAP. See
Section 21.3.2.3.
Search WWH ::




Custom Search