/** Remote method invocation (RMI) library.
This package contains two major classes, Skeleton
and
Stub
, which can be used to implement remote method
invocation (RMI). In RMI, a client possesses a stub object.
The stub object purports to implement a certain functionality. In fact, the
functionality is implemented remotely by a server. The stub object merely
marshals the arguments given to its methods and transmits them over a
network to the server. It then waits for the server to provide the result,
which is returned to the client. RMI hides the network communication from
the client. Network requests and responses appear to the client as regular
method calls on the stub object.
The skeleton is an object on the server that is responsible for maintaining network connections and unmarshaling arguments. It is the server's counterpart to the client's stub.
The Skeleton
class includes a multithreaded server which
communicates with stubs over TCP connections. The Stub
class
provides methods for creating stubs. Each stub object is given the network
address of the skeleton with which it is to communicate when it is created.
To use the library, first define a remote interface: an interface
in which all public methods are marked as throwing
RMIException
. Skeletons can be created using the
Skeleton
constructors, and stubs with one of the
create
methods in Stub
. For example, with the
following definitions:
public interface TestInterface { public void testMethod() throws RMIException; } public class TestClass implements TestInterface { ... }An RMI skeleton and stub can be created as follows:
TestClass object = new TestClass(); Skeleton<TestInterface> skeleton = new Skeleton<TestInterface>(TestInterface.class, object); skeleton.start(); TestInterface stub = Stub.create(TestInterface.class, skeleton);
The methods declared in the remote interface may throw their own exceptions. In case an exception is thrown remotely, it is transmitted back to the client.
In the typical case, the server will create both the skeleton and the
corresponding stub, as above. The stub will then be transmitted to any
clients that wish to use the services provided by the server. Stubs may also
be created directly by the client - this is provided primarily to bootstrap
RMI. If all stubs were created by the server, then it would be necessary to
use a means other than the RMI library to transmit an initial stub to the
client. To avoid this, the RMI library allows the client to create an
initial stub by directly providing a network address to a version of
create
.
*/
package rmi;