cours0708/A61/FASD/MyNoeud.java

45 lines
994 B
Java
Raw Normal View History

import java.rmi.Naming;
import java.rmi.RemoteException;
public class MyNoeud {
public MyNoeud(String nom, String pere, String port) {
Noeud pere_temp;
NoeudImpl n;
try{
if(pere != null && !pere.equals("null")) {
pere_temp = (Noeud)Naming.lookup("rmi://localhost:" + port + "/" + pere);
n = new NoeudImpl(nom,pere_temp.getName());
} else {
pere_temp = null;
n = new NoeudImpl(nom,null);
}
try{
Naming.rebind("rmi://127.0.0.1:" + port + "/" + nom, n);
}catch (RemoteException e) {
System.out.println(e.getMessage());
System.exit(1);
}
System.out.println("rmi://localhost:" + port + "/" + nom);
if(pere_temp != null)
pere_temp.addFils(nom);
}catch(Exception e) {
e.printStackTrace();
}
}
public static void main (String[] args) throws RemoteException {
if(args.length == 3){
new MyNoeud(args[0], args[1], args[2]);
} else {
System.out.println(" please use : java MyNoeud name father port");
}
}
}