Java Reference
In-Depth Information
and setForecast . The Location interface is remotable, indicated by its extension of the
java.rmi.Remote interface. Its concrete implementation, LocationImpl , is based on the
RMI OP implementation of a java.rmi.UnicastRemoteObject , which can be shared across a
distributed computing environment.
Note Because NetBeans doesn't directly support the development of RMI applications, the examples that
follow require you to have the JDK installed, which should have been installed when you installed NetBeans.
You may need to be sure that the bin directory of the installed JDK is in your path to access commands
such as javac and rmic .
Writing the Java Interfaces for the Service
As I noted previously, the key to RMI is defining the interfaces to the remote service.
Listing 11-1 shows the Location interface.
Listing 11-1. The Location Interface
public interface Location
extends java.rmi.Remote {
public String getLocation()
throws java.rmi.RemoteException;
public void setLocation(String l)
throws java.rmi.RemoteException;
public String getForecast()
throws java.rmi.RemoteException;
public void setForecast(String f)
throws java.rmi.RemoteException;
}
This interface is straightforward, although you can see that each method can throw
java.rmi.RemoteException . This is because implementations of the interface can be prox-
ies, remote from the actual implementation. In that case, the implementation of the
interface must have a way to signal an exceptional situation, such as a loss of network
connectivity.
 
Search WWH ::




Custom Search