Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New development version.
[jaceP2P.git] / src / jaceP2P / JaceServer.java
index d7aaeea..69f0195 100644 (file)
@@ -28,16 +28,30 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                Register.Instance().setSpawnerStub(spawnerStub);
        }
 
+//     public JaceSpawnerInterface transformIntoSpawner(String[] params,
+//                     String appliName, Register reg, int nbTasks,
+//                     JaceSuperNodeInterface snodeStub, int rank, int heartTime, int tag,
+//                     int nbdc, int nbsdc, int nbDaemonPerSpawner, int nbDaemonPerThread)
+//                     throws RemoteException {
+//             System.out.println("Beginning the transformation ...");
+//             new JaceSpawner(params, appliName, reg, nbTasks,
+//                             snodeStub, rank, heartTime, tag, nbdc, nbsdc,
+//                             nbDaemonPerSpawner, nbDaemonPerThread);
+//             HeartBeatThread.Instance().kill();
+//             return Register.Instance().getSpawnerStub();
+//     }
+       
+       
        public JaceSpawnerInterface transformIntoSpawner(String[] params,
                        String appliName, Register reg, int nbTasks,
                        JaceSuperNodeInterface snodeStub, int rank, int heartTime, int tag,
-                       int nbdc, int nbsdc, int nbDaemonPerSpawner, int nbDaemonPerThread)
+                       int nbdc, int nbsdc, int nbDaemonPerSpawner, int nbDaemonPerThread,
+                       String idAlgo)
                        throws RemoteException {
-               System.out.println("beginning the transformation .........");
-//             @SuppressWarnings("unused")
-//             JaceSpawner spawner = new JaceSpawner(params, appliName, reg, nbTasks,
-//                             snodeStub, rank, heartTime, tag, nbdc, nbsdc,
-//                             nbDaemonPerSpawner, nbDaemonPerThread);
+               System.out.println("Beginning the transformation ...");
+               new JaceSpawner(params, appliName, reg, nbTasks,
+                               snodeStub, rank, heartTime, tag, nbdc, nbsdc,
+                               nbDaemonPerSpawner, nbDaemonPerThread, idAlgo);
                HeartBeatThread.Instance().kill();
                return Register.Instance().getSpawnerStub();
        }
@@ -59,7 +73,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                // 1 - replace the old Register by the new one
                System.out.println(" \n\n             NEW REGISTER            \n\n");
                // if(Register.Instance().getVersion()<=newReg.getVersion()){
-               System.out.println("replacing Register !!!!!!$$$$$$$$******");
+               System.out.println("Replacing Register ...");
                Register.Instance().replaceBy(newReg);
                Register.Instance().viewAll();
                // }
@@ -78,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());
@@ -86,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.out.println("error in updateregister :" + e);
+                       System.err.println("Error in updateregister :" + e);
+                       return 1 ;
                        // e.printStackTrace();
                }
        }
@@ -128,7 +158,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
        }
 
        public void suicide(String debugMsg) throws RemoteException {
-               System.out.println("suiciiiiiiiiiiiide : "/* + debugMsg */);
+//             System.out.println("suiciiiiiiiiiiiide : "/* + debugMsg */);
                new ReinitDaemon().start();
        }
 
@@ -260,7 +290,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
                                ScanThread.Instance().notify();
                        }
                } catch (Exception e) {
-                       System.out.println("error in setScanning: " + e);
+                       System.err.println("Error in setScanning: " + e);
                }
                // System.out.println("before notify!!!!!!!!!");
                // try{ScanThread.Instance().notify();}
@@ -281,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 ) ;
+       }
 }