Java Reference
In-Depth Information
Note Java programs have permissions that are governed by policy files. The Java 2 security model
requires that programs and the RMI registry have permission to create sockets. After all, RMI is based
on sockets. The client also needs to specify a policy file on start-up. Here is how we would start the
RMI registry to load a policy file other than the default: rmiregistry -J-Djava.security.
policy=ourSecurityFile.policy .
Port 80 is used as the default port unless one is specified in the server property http.
proxyHost . However, HTTP tunneling comes with a number of costs. Performance is sacrificed
and security can be compromised. Tunneling can be disabled by setting the server property
java.rmi.server.disableHttp to true.
Summary
This chapter covered a great deal of information. First, we reviewed serialization.
Any object that can potentially be sent across a network must be serialized prior to its trip
across the wire. Both sockets (which will be discussed in the next chapter) and RMI require
serialization. In RMI, both the return values and the method parameters must be serializable
for the application to work.
Finally, we explored RMI in depth and implemented an RMI solution for Denny's DVDs.
Considering the amount of effort that went into building the socket implementation, we were
able to appreciate the amount of work RMI does under the hood. We did not have to worry
about writing a multithreaded server, since RMI handles that aspect for us. We also did not
have to worry about creating command and result objects in order to implement an applica-
tion protocol.
However, RMI did require us to define a remote interface and make sure that all of our
method parameters were serializable. Additionally, we had to concern ourselves with register-
ing our remote object with the RMI naming service and starting the RMI registry so that our
object is accessible to a remote client. We hope you have learned enough about serialization,
sockets, and RMI so that you can design and implement a complete networking solution for
the SCJD exam. Using this project networking package as a guide, along with the chapter, you
should be adequately prepared.
FA Q Is RMI thread-safe?
A No. The J2SE 1.4 RMI specification makes no guarantee regarding the number of
threads that will have access to your remote object. For this reason, your design has
to take into account issues of thread safety. See Chapter 4 for details on locking and
thread safety. The approach we used in this chapter was to create an RMI factory
ensuring a distinct instance of the DvdDatabase wrapper class and using that as our
unique identifier for record locking.
Search WWH ::




Custom Search