Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of some bugs and performance enhancement.
[jaceP2P.git] / src / jaceP2P / JaceServer.java
index d63f6ee..bf6e27d 100644 (file)
@@ -2,9 +2,10 @@ package jaceP2P;
 
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
-import java.util.Vector;
+
 
 public class JaceServer extends UnicastRemoteObject implements JaceInterface {
 
@@ -28,15 +29,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 ...");
                new JaceSpawner(params, appliName, reg, nbTasks,
                                snodeStub, rank, heartTime, tag, nbdc, nbsdc,
-                               nbDaemonPerSpawner, nbDaemonPerThread);
+                               nbDaemonPerSpawner, nbDaemonPerThread, idAlgo);
                HeartBeatThread.Instance().kill();
                return Register.Instance().getSpawnerStub();
        }
@@ -77,7 +93,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());
@@ -85,37 +101,53 @@ 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();
                }
        }
 
-       public Vector<?> getIterationOfBackup(int remoteRank, int tag)
+       public ArrayList<Integer> getIterationOfBackup(int remoteRank, int tag)
                        throws RemoteException {
                Backup b = BackupsManager.Instance().getBackupTaskOfRank(remoteRank,
                                tag);
-               Vector<?> result = b.getIterationStep();
+               ArrayList<Integer> result = b.getIterationStep();
                return result;
        }
 
@@ -200,7 +232,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
        }
 
        public void savOrFinOrRest(int tag, int step, boolean verd,
-                       Vector<?> recievedValue) throws RemoteException {
+                       ArrayList<Object> recievedValue) throws RemoteException {
                JaceSession.Instance().getTaskObject().savOrFinOrRest(tag, step, verd,
                                recievedValue);
        }
@@ -216,7 +248,7 @@ public class JaceServer extends UnicastRemoteObject implements JaceInterface {
        }
 
        public synchronized void response(int neighId, int tag, int response,
-                       Vector<?> recievedValue) throws RemoteException {
+                       ArrayList<Object> recievedValue) throws RemoteException {
                JaceSession.Instance().getTaskObject().response(neighId, tag, response,
                                recievedValue);
        }
@@ -280,18 +312,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 ) ;
+       }
 }