Listing 13.2
LazyServerImpl.java
import java.rmi.*;
import java.rmi.activation.*;
public class LazyServerImpl extends Activatable
implements LazyInterface {
//this constructor is called by the
//method ActivationInstantiator.newInstance during
//activation process, to construct the object.
public LazyServerImpl(ActivationID id, MarshalledObject data)
throws RemoteException {
//Register the object with the activation system and
//then export it.
super(id, 0);
}
//Remote method
public String sayHello() throws RemoteException {
return "Hello World!";
}
}
Explanation
of Code
The implementation class declares which remote interface(s) it is implementing.
Here is the LazyServerImpl class declaration:
public class LazyServerImpl extends Activatable
implements LazyInterface {
The Activatable class provides support
for remote objects that require persistent access over time and that
can be activated by the system on demand.
The constructor registers the object with the activation system.
public LazyServerImpl(ActivationID id, MarshalledObject data)
throws RemoteException {
super(id, 0);
}
Our next task is to provide implementation for each remote method.
In this example, the remote interface contains only one remote method
sayHello(). Here is the implementation
for the sayHello() method, which returns
the string "Hello World!" to the client:
public String sayHello() throws RemoteException {
return "Hello World!";
}
|