Clients et serveurs RMI

Le client

La classe java.rmi.Naming permet de gerer les objets a distance par le biais des URLs avec un protocole particulier qui est rmi

Detail de cette classe :
package java.rmi;  

public final class Naming  

 

    public static final int REGISTRY_PORT = 1099;// port par defaut 
    public static Remote lookup(String url)  
      throws NotBoundException, java.net.MalformedURLException, UnknownHostException, RemoteException; 

      // retourne l'objet reference par l'url.

    public static void bind(String url, Remote obj)  
      throws AlreadyBoundException, java.net.MalformedURLException, UnknownHostException, RemoteException;  

      // lie l'url a l'objet designe

    public static void rebind(String url, Remote obj)  
      throws RemoteException, java.net.MalformedURLException, UnknownHostException; 

      // meme action que bind meme si l'objet a deja ete attachee.

    public static void unbind(String url)  
      throws RemoteException, NotBoundException, java.net.MalformedURLException, UnknownHostException; 

      // detache l'url

    public static String[] list(String url)  
      throws RemoteException, java.net.MalformedURLException, UnknownHostException;  

      // liste des objets

}

Le serveur d'objets

Trois classes differentes sont disponibles pour ecrire le serveur. java.rmi.server.RemoteObject qui est une classe abstract, java.rmi.server.RemoteServer qui est la classe generale des objets distants et enfin la sous-classe java.rmi.server.RemoteServer qui crees des objets ayant les caracteristiques suivantes : Voici le details des classes :
package java.rmi.server;  

public abstract class RemoteObject implements java.rmi.Remote, java.io.Serializable 

{ 

    public int hashCode();  

    public boolean equals(Object obj); public String toString(); 

} 

package java.rmi.server;  

public abstract class RemoteServer extends RemoteObject 

{ 

    public static String getClientHost() throws ServerNotActiveException; 

    public static void setLog(java.io.OutputStream out); 

    public static java.io.PrintStream getLog();

} 

package java.rmi.server;  

public class UnicastRemoteObject extends RemoteServer  

{ 

    protected UnicastRemoteObject() throws java.rmi.RemoteException; 

    public Object clone() throws java.lang.CloneNotSupportedException; 

    public static RemoteStub exportObject(java.rmi.Remote obj) throws java.rmi.RemoteException; 

}

Ph. RIS 1997