|
Java[tm] Platform RMI FAQsby Eshwar Rao(June 2002) We want to hear from you! Please send us your FEEDBACK.
1. What does RMI stand for and for what type of applications is RMI suitable? RMI stands for Remote Method Invocation. RMI is tightly coupled with the Java[tm] programming language and is suited for applications in which both the client and server are Java programming language objects. However non-Java technology applications may be integrated
with existing RMI systems using other Java technologies like RMI over IIOP,
plain sockets or Java Messaging Service[tm] ("JMS").
2. What are the changes in RMI since its inclusion in the Java[tm] Development Kit (JDK[tm]) 1.1? Changes in JDK 1.2:
Changes in JDK 1.3:
Changes in JDK 1.4: Certain static methods of java.rmi.server.RMIClassLoader
now delegate their behavior to an instance of a new service provider interface,
java.rmi.server.RMIClassLoaderSpi.
This service provider object can be configured to augment RMI's dynamic
class loading behavior for a given application. By default, the service
provider implements the standard behavior of all of the static methods
in RMIClassLoader.
3. What is the basic working principle of RMI and what is the structure of an RMI application ? RMI allows interaction between different objects in different Java[tm] Virtual Machines (JVM[tm]). The JVMs can be located on the same machine or on different machines. RMI enables objects in one JVM to call methods on objects in other JVM. The basic composition of an RMI application
is an Interface which models the behaviour of the system, an Implementation
class which models the implementation of this behaviour, and a client which
accesses the services of the implementation class through the interface.
The location of the implementation class is transparent to the client.
The communication process between the client and the implementation class
are also abstracted from the client. For a tutorial on RMI see:
http://java.sun.com/docs/books/tutorial/rmi/
4. Can I integrate non-Java technology applications with RMI? Though RMI is primarily for Java programming language Objects located on different Virtual Machines to communicate, other non-Java technology applications may be integrated into existing RMI applications through the use of either RMI/IIOP, plain Sockets or JMS. XML (SOAP) can also be used for integration purposes. RMI over IIOP provides the Interoperability with objects written in different languages. For further reading see: RMI/IIOP: http://java.sun.com/j2se/1.4/docs/guide/rmi-iiop/interop.html Socket Programming: http://java.sun.com/docs/books/tutorial/networking/sockets/ http://www.ecst.csuchico.edu/~beej/guide/net/html/ JMS: http://java.sun.com/products/jms/tutorial/ http://www.codemesh.com/en/index.html XML: http://java.sun.com/xml/tutorial_intro.html SOAP:
http://www.xml.org/xml/resources_focus_soap.shtml.
5. How are parameters passed in RMI? Parameters are arguments passed to a method
or values that are returned from it. They can be either non-Remote or Remote.
Non-Remote Objects which also include the Primitive Data types are passed
by value. This indicates that when a called method returns an object, an
object of that type is created in the Virtual Machine of the caller. For
Remote Objects, a reference to the Remote
Object is passed.
6. Can I start the
RMI Registry from within the server?
Yes, the RMI Registry can be started from
within the RMI server. See the following code snippet for an explanation:
//LocateRegistry
is used to load the bootstrap registry
//Binds the
name to the specified remote object
7. What Design Patterns
are used within the RMI architecture?
The design pattern easily identifiable
is the Proxy pattern. The object returned by the server is a proxy object
that implements the same interface as the Remote Object. All methods executed
by the client on the Remote interface are routed to the server through
this object. For futher reading on Design Patterns in the Java programming language, see:
http://www.hillside.net/patterns.
8. Can we perform
client side logging in RMI?
Yes, starting with the Java[tm] 2 Platform, Standard Edition (J2SE[tm] version 1.4,
Remote calls and exceptions on the client side can be logged by setting the system
property to sun.rmi.client.logCalls=true
before starting the client. For further information see:
http://java.sun.com/j2se/1.4/docs/guide/rmi/logging.html
9. Where can I find
a
list of RMI specific properties ?
For RMI specific properties see:
Generally the client makes calls into the
server but somtimes the server has to make calls back into the client.
This is achieved by the client exporting itself through the
UnicastRemoteObject.exportObject()
method. Once this is done the client can register itself with the server
through a unique identifier. The server can then send any messages back
to clients selectively through this registered client object.
http://developer.java.sun.com/developer/onlineTraining/rmi/exercises/RMICallback/index.html
11. Why are skeleton
classes not required in Java 2 programming language?
Stubs and skeletons are generated using
the rmic
tool. The stub class is the proxy for the server object on the client side.
The skeleton on the other hand, is responsible for dispatching the call
to the actual remote server object. The stub protocol introduced in JDK
1.2 eliminates the requirement for skeleton classes. Generic code now performs
all the duties of the skeleton class.
12. What is the
difference between bind and rebind?
bind("server-lookup-name", remote-obj): If there's already an object bound to
that name within the RMI
Registry, the application will throw an AlreadyBoundException.
If there is no match, the object will be bound to the name within the Registry.
rebind("server-lookup-name", remote-obj): If there's already an object bound to
that name within the RMI Registry,
the application will replace any existing binding for the name within the RMI
Registry. If there was no match, the object will be bound to the name within
the registry as usual.
13. What is Distributed
Garbage Collection and how does it work?
RMI implements a Reference Counting Algorithm
for memory management. The basic method used is to keep track of the clients
holding a reference to the Remote Object. Whenever a client gets a reference
to the object, the reference count for that object is increased by one. Similarly,
when a client drops the reference, the reference
count is decreased
by one. When the reference count for an object becomes 0, that is, there are no
clients which hold a reference to that object, then it is marked for Garbage
Collection. For a tutorial on Distributed Garbage Collection, visit
JRMP stands for "Java Remote Method Protocol".
It is a proprietary wire level protocol designed by Sun Microsystems for
RMI. JRMP is similar to IIOP with the added feature that it can also pass
object references.
15. Where can I
find the specifications for RMI over IIOP?
RMI over IIOP is based on two specifications
of the Object Management Group:
Advantages of RMI/IIOP:
17. I have
an RMI application running over JRMP. What code changes do I have to
make for it to work over IIOP?
On the server side:
18. Can I use callbacks
through firewalls?
No, callbacks cannot be used through firewalls.
To effect a callback the server should be able to make a socket connection
back to the client (roles of server and client are reversed in a callback)
and this may not be possible through firewalls.
19. Where can I
find information and sample applications of RMI with Secure Socket Layer (SSL)?
For information and sample applications see:
http://java.sun.com/j2se/1.3/docs/guide/rmi/SSLInfo.html
20. How many instances
of the server are there in an RMI application?
There is only one instance of the server
class. Multiple client requests are handled by spawning threads to service
client requests. In the server implementation, the developer is responsible
for taking care of synchronization.
21. Where can I
find sample code and API documentation for Activation?
For sample code on Activation see:
http://java.sun.com/products/jdk/1.2/docs/guide/rmi/activation.html
The API documentation
is packaged along with the J2SE Javadoc[tm] software. The API documentation can
be found at:
http://java.sun.com/j2se/1.3/docs/api/java/rmi/activation/package-summary.html
22. How can I selectively
serialize the contents of an object?
You can selectively serialize the contents
of an object by using the Java programming language keyword transient. This prevents
the attribute from being serialized. Therefore, if we mark a field of an
object as transient, and write that object to disk, when we de-serialize
the object the transient field contains only the default value for that
particular field, and not the actual value that the field had before its state
was serialized.
23. Can I programatically
stop an RMI application?
Yes, several approaches can be taken for
this. The general idea is to start a thread from within the main server
thread. This thread would wait for a particular flag to be set; it
would be set on the call for a shutdown of the server. Once the flag is
set, the main RMI server thread can be terminated by calling the System.exit(int).
24. Why is rmic
invoked on the implementation class and not the remote interface?
Simple RMI applications consist of one
Interface and one implementation class.
When rmic is used with the implementation
class, it generates the stub and skeleton classes for the client and server
sides respectively. However in some cases the class providing the implementation
may actually implement more than one interface.
This is the reason rmic
is run against the implementation class rather than the interface.
DOC ID #1216
| |||||||||||||||||||||||||||||||||||||||