Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New development version.
[jaceP2P.git] / src / jaceP2P / JaceServer.java
index b92c31e..69f0195 100644 (file)
@@ -92,7 +92,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                return 0;
        }
 
-       public void updateRegister(Node oldNode, Node node) throws RemoteException {
+       public int updateRegister( Node oldNode, Node node, int rank ) throws RemoteException {
 
                // if(tag==1)
                // HeartBeatThread.Instance().setServer((Object)node.getStub());
@@ -100,28 +100,44 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                Calendar cal = new GregorianCalendar();
                System.out.println("at time=" + cal.get(Calendar.MINUTE) + ":"
                                + cal.get(Calendar.SECOND));
-               System.out.println("Modify  REGISTER");
+               System.out.println("Modify REGISTER");
                try {
-                       // System.out.println("blablablablabalablablabalbalab");
-                       System.out.println("oldName=" + oldNode.getName());
-                       boolean b = Register.Instance().removeNodeOfName(oldNode.getName());
-                       if (b)
-                               System.out.println("removed old Node!!!!!");
-                       else
-                               System.out.println("didn't find old Node!!!!");
-
-                       Register.Instance().addNode(node);
-                       Register.Instance().viewAll();
+                       boolean b = false ;
+                       if( oldNode != null )
+                       {
+                               System.out.println("Old node name=" + oldNode.getName());
+                               b = Register.Instance().removeNodeOfName(oldNode.getName());
+                       }
+                       if( b )
+                       {
+                               System.out.println("Old node removed !");
+                       } else {
+                               System.out.println("Did not find the old Node !");
+                       }
+
+                       if( node != null )
+                       {
+                               Register.Instance().addNode(node);
+                       } else {
+                               System.err.println( "The new node is NULL !" ) ;
+                               return 1 ;
+                       }
+//                     Register.Instance().viewAll();
                        TaskId myTaskId = null;
+//                     myTaskId = Register.Instance().getListeOfTasks()
+//                                     .getTaskIdOfHostStub(oldNode.getStub());
                        myTaskId = Register.Instance().getListeOfTasks()
-                                       .getTaskIdOfHostStub(oldNode.getStub());
+                       .getTaskIdOfRank( rank ) ;
                        myTaskId.setHostIP(node.getIP());
                        myTaskId.setHostName(node.getName());
                        // Register.Instance().setVersion(version);
                        myTaskId.setHostStub(node.getStub());
+                       
+                       return 0 ;
 
                } catch (Exception e) {
                        System.err.println("Error in updateregister :" + e);
+                       return 1 ;
                        // e.printStackTrace();
                }
        }
@@ -295,18 +311,32 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                }
 
                public void run() {
-                       BackupsManager.Instance().initialize(req);
+                       BackupsManager.Instance().initialize( req ) ;
 
                }
        }
 
        class ReinitDaemon extends Thread {
 
-               public ReinitDaemon() {
-               }
+               public ReinitDaemon() {}
 
                public void run() {
-                       JaceDaemon.Instance().reinitDaemon();
+                       JaceDaemon.Instance().reinitDaemon() ;
                }
        }
+
+       @Override
+       public void suicide2( String mes ) throws RemoteException 
+       {
+               System.out.println( "Killed because: " + mes ) ;
+               
+               try{ 
+               UnicastRemoteObject.unexportObject( this, true ) ; 
+           } 
+           catch( Exception e ) {
+               System.err.println( "Unable to unexport myself: " + e ) ;
+           } 
+                                 
+               System.exit( 0 ) ;
+       }
 }