Java Reference
In-Depth Information
a minor complication when any item in the parameter list or the return value is
itself a remote object. In that case, the parameter or return value must be referred
to using its corresponding remote interface rather than the implementation
class.
The java.rmi.Remote interface declares no methods; it is simply a marker,
or tagging, interface like java.io.Serializable .
A code snippet that gives an example of a remote interface is:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RMIExampleInterface extends Remote {
public void method1 (String s) throws RemoteException;
public int add (int a, int b) throws RemoteException;
}
The exception java.rmi.RemoteException ,orone of its several sub-
classes, is thrown back to the calling method whenever a remote method invo-
cation fails for some reason. Some reasons for remote method invocation failure
include:
server is down (or unreachable, which can mean the network is down)
failure during marshalling or unmarshalling of parameters or return value
protocol errors
RemoteException is a checked exception - i.e. the caller must handle it. That
requirement is one difference in remote method calls compared to local calls -
all remote calls must appear within a try-catch block to respond to the possibility
of a RemoteException .
Yo umay also want to declare some application-specific exceptions as
well for handling exception conditions within the server code - such as
input parameters outside the expected range. Such application-specific excep-
tions should not extend java.rmi.RemoteException ,which is intended
for communications-related failures outside the control of the developer.
Application-specific exceptions should be created just like normal non-remote
exceptions - by extending java.lang.Exception .
18.3.3.2 The remote implementation class
Now let's consider the server-side implementation of the remote interface defined
above. The implementation class must, of course, implement the remote inter-
face. An additional requirement is that it must extend java.rmi.server.
RemoteObject .Inorder to be remotely callable, the implementation class
must make a runtime notification to the RMI system that the implementa-
tion is available to accept incoming requests. This runtime notification pro-
cess is known as exporting .Inmost cases, including all cases of interest here,
 
Search WWH ::




Custom Search