Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of interlock implementation.
[jaceP2P.git] / src / jaceP2P / JaceSuperNodeServer.java
index 8809d17..c85a7c5 100644 (file)
@@ -27,7 +27,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
        private ArrayList<GNode> gnodes = null;
        private Algo al = null ;
        private int count = 0 ;
-       private boolean inDemand = false, operating = false ;
+       private boolean inDemand = false, operating = false, authorized = false ;
 //     private boolean daemonListChange ;
        
        // Constructors
@@ -216,6 +216,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                /** Initialization of Grid architecture (G5K for now) **/
                Grid grid = Utils.createGridG5k(gnodes);
                grid.initClusters();
+               
 
                /** Creation of tasks GTask **/
                ArrayList<GTask> ts = new ArrayList<GTask>();
@@ -237,6 +238,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                                }
                        }
                }
+               
 
                Graph graph = new Graph();
 
@@ -279,17 +281,23 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        /** Launching the Mapping **/
                        al.map();
 
+
                        /** Transforming mapping in register **/
                        Mapping mp = al.getMapping();
-
+                       
+                       
                        /** Creating the register **/
                        ArrayList<GNode> ag = mp.getMappedGNodes();
 
+                       authorized = true ;
+                       
                        for (int i = 0; i < ag.size(); i++) {
                                reg.addNode((Node) ag.get(i).getNode());
                                gnodes.remove(ag.get(i));
                                Register.Instance().removeNode((Node) ag.get(i).getNode());
                        }
+                       
+                       authorized = false ;
 
                        if (ag.size() != 0) {
                                SuperNodeListe.Instance().forwardCountNode();
@@ -321,8 +329,14 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                GNode removedGNode = null ;
                
                if( _n != null )
-               {               
-                       workingOnGnodes() ;
+               {       
+                       boolean free = false ;
+                       
+                       if( ! operating )
+                       {
+                               workingOnGnodes() ;
+                               free = true ;
+                       }
                        
                        for( int i = 0 ; i < gnodes.size() ; i++ )
                        {
@@ -337,7 +351,10 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                
                        SuperNodeListe.Instance().removeGNode( removedGNode ) ;
                        
-                       operating = false ;
+                       if( free )
+                       {
+                               operating = false ;
+                       }
                
                }
                
@@ -355,6 +372,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                while( ! operating )
                {
                        inDemand = true ;
+                       tmp = true ;
                        
                        tmp = tmp && SuperNodeListe.Instance().workingOnGnodes() ;
 
@@ -394,7 +412,13 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        {
                                System.out.println( "Replacing node found." ) ;
                                node = (Node) remp.getNode() ;
+                               
+                               authorized = true ;
+                               
                                delGNodeFromList( node ) ;
+                               
+                               authorized = false ;
+                               
                                SuperNodeListe.Instance().forwardCountNode();
                        } else {
                                System.err.println( "Replacing node not found !!" ) ;
@@ -406,7 +430,13 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        {
                                System.out.println( "Other new node found." ) ;
                                node = (Node) remp.getNode() ;
+                               
+                               authorized = true ;
+                               
                                delGNodeFromList( node ) ;
+                               
+                               authorized = false ;
+                               
                                SuperNodeListe.Instance().forwardCountNode();
                        } else {
                                System.err.println( "Other new node not found !!" ) ;
@@ -465,6 +495,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                al = _al ;              
        }
 
+       
        @Override
        /**
         * Allow or deny the use of operations on the gnodes list, in order to
@@ -472,7 +503,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
         * @author miquee
         * @return The authorization or not to block gnodes
         */
-       public boolean blockForMapping() 
+       public boolean blockForMapping() throws RemoteException
        {
                while( inDemand )
                {
@@ -483,7 +514,7 @@ public class JaceSuperNodeServer extends UnicastRemoteObject implements
                        }
                }
                
-               if( operating )
+               if( operating && ! authorized )
                {
                        return false ;
                } else {