Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New development version.
[jaceP2P.git] / src / jaceP2P / JaceSuperNodeServer.java
1 package jaceP2P;
2
3 import java.rmi.RemoteException;
4 import java.rmi.server.UnicastRemoteObject;
5 import java.util.ArrayList;
6 import java.util.Vector;
7
8 import and.Mapping.Algo;
9 import and.Mapping.DefaultMapping;
10 import and.Mapping.FT_AIAC_QM;
11 import and.Mapping.FT_FEC;
12 import and.Mapping.GNode;
13 import and.Mapping.GTask;
14 import and.Mapping.Graph;
15 import and.Mapping.Grid;
16 import and.Mapping.Maheve;
17 import and.Mapping.Simple;
18
19
20 public class JaceSuperNodeServer extends UnicastRemoteObject implements
21                 JaceSuperNodeInterface {
22         private static final long serialVersionUID = 1L;
23
24         // Attributes
25         private int beat;
26         private ArrayList<GNode> gnodes = null;
27         private ArrayList<Algo> algos = null ;
28         private boolean inDemand = false, operating = false, authorized = false ;
29         
30         // Constructors
31
32         public JaceSuperNodeServer(int timeBeat) throws RemoteException {
33                 super() ;
34                 beat = timeBeat ;
35                 gnodes = new ArrayList<GNode>() ;
36                 algos = new ArrayList<Algo>() ;
37         }
38
39         public int getSuperNodeBeat() throws RemoteException {
40                 return beat;
41         }
42
43         public Vector<?> sendStub(String IP, int port, JaceSuperNodeInterface stub)
44                         throws RemoteException {
45                 SuperNodeListe.Instance().addStubOf(IP, port, stub);
46                 System.out.println("Added new superNode (" + IP
47                                 + ") to list and return List");
48                 return SuperNodeListe.Instance().getListe();
49         }
50
51         public void updateCountNode(String IP, int nb) throws RemoteException {
52                 SuperNodeListe.Instance().modifCountNode(IP, nb);
53                 // System.out.println( "SuperNode " + IP + " has registered " + nb +
54                 // " Daemons" ) ;
55                 SuperNodeListe.Instance().viewAll();
56         }
57
58         public void sendSurplus(Vector<?> nodes, ArrayList<GNode> _gnodes) throws RemoteException {
59                 System.out.println("Recieved " + nodes.size() + " nodes");
60
61                 for (int i = 0; i < nodes.size(); i++) {
62                         Register.Instance().getListe().add((Node) nodes.elementAt(i));
63
64                         System.out.println("Adding "
65                                         + ((Node) nodes.elementAt(i)).getName());
66
67                         try {
68                                 ((Node) nodes.elementAt(i)).getStub().updateHeart(
69                                                 LocalHost.Instance().getSuperNodeStub());
70                                 int index = SuperNodeListe.Instance().existSuperNode(
71                                                 LocalHost.Instance().getIP());
72                                 ((SuperNodeData) SuperNodeListe.Instance().getListe()
73                                                 .get(index))
74                                                 .setNbOfNodes(Register.Instance().getSize());
75                                 new ForwardCount().start();
76                         } catch (Exception e) {
77                                 System.err.println("Error changing Server in SendSurplus : "
78                                                 + e);
79                         }
80                 }
81                 
82                 /** Updating gnodes **/
83                 if( _gnodes != null )
84                 {
85                         gnodes = _gnodes ;
86                 }
87         }
88
89         public void setToken() throws RemoteException {
90                 System.out.println("I got Token");
91
92                 TokenThread.Instance().setToken();
93
94                 try {
95                         HeartBeatSNode.Instance().getServer().beating(true);
96
97                         System.out.println("Put token to true");
98                 } catch (Exception e) {
99                         System.err
100                                         .println("Unable to heartBeat the next SuperNode with the new Token : "
101                                                         + e);
102                 }
103         }
104
105         public void updateHeart(JaceSuperNodeInterface stub) throws RemoteException {
106                 System.out.println("I change to ping a superNode");
107
108                 HeartBeatSNode.Instance().setServer(stub);
109         }
110
111         public synchronized void removeSuperNode(SuperNodeData d)
112                         throws RemoteException {
113                 SuperNodeListe.Instance().removeSuperNode(d);
114         }
115
116         /****************************************************/
117         /****************************************************/
118
119         // Register a Daemon in the Register.Instance() of the SuperNode
120         public synchronized void workerRegistering(JaceInterface workerStub,
121                         String workerIP, String workerName, int port, GNode g)
122                         throws RemoteException {
123                 System.out.println("CONNECTION of " + workerName);
124
125                 // Create the node
126                 Node noeud = new Node(workerStub);
127                 noeud.setName(workerName);
128                 noeud.setIP(g.getIP());
129                 noeud.setAliveFlag(true);
130                 noeud.setAliveTime();
131                 noeud.setPort(port);
132                 noeud.setAppliName(null);
133                 noeud.setNbOfBeats(0);
134                 
135                 String sid = workerIP.replace( ".", "" ) + port ;
136                 Long id = Long.parseLong( sid ) ;
137                 noeud.setId( id ) ;
138
139                 g.setNode( noeud ) ;
140                 g.setId( id ) ;
141                 g.setMapped( false ) ;
142                 
143                 workingOnGnodes() ;
144                 
145                 gnodes.add( g ) ;
146                 updateGrids( g ) ;
147                 
148
149                 // Insert the node in the Register.Instance() of the Super Node
150                 Register.Instance().addNode(noeud);
151
152                 // Register.Instance().viewAll() ;
153                 // SuperNodeListe.Instance().viewAll() ;
154
155                 // Inform the other superNode and tell them the nb of Daemon I have
156                 // registered
157                 int index = SuperNodeListe.Instance().existSuperNode(
158                                 LocalHost.Instance().getIP());
159
160                 ((SuperNodeData) SuperNodeListe.Instance().getListe().get(index))
161                                 .setNbOfNodes(Register.Instance().getSize());
162                 SuperNodeListe.Instance().forwardCountNode();
163                 
164                 authorized = true ;
165                 SuperNodeListe.Instance().addGNode( g ) ;
166                 authorized = false ;
167                 
168                 operating = false ;
169         }
170
171         
172         /**
173          * Update all mapping algorithms with a new node.
174          * @param _g The new node
175          * 
176          * @author S&eacute;bastien Miqu&eacute;e
177          */
178         private synchronized void updateGrids( GNode _g )
179         {
180                 if( _g != null )
181                 {
182                         for( int i = 0 ; i < algos.size() ; i++ )
183                         {
184                                 algos.get( i ).getGrid().addGNode( _g ) ;
185                         }
186                 }
187                 
188         }
189
190         /****************************************************/
191         /****************************************************/
192
193         // HeartBeat that detects if a Daemon is dead or alive
194         public void beating(JaceInterface stub) throws RemoteException {
195                 Node noeud = Register.Instance().getNodeOfStub(stub);
196
197                 if (noeud != null) {
198                         noeud.setAliveFlag(true);
199                         noeud.setAliveTime();
200                         noeud.incrementNbOfBeats();
201                         // -- sm modif
202                         // System.out.println( noeud.getName() + " is pinging me" ) ;
203                 } else {
204                         // System.out.println( noeud.getName() +
205                         // ".................. is not in my list" ) ;
206                 }
207         }
208
209         // HeartBeat that detects if a Super Node is dead or alive
210         public void beating(boolean token) throws RemoteException {
211                 ScanThreadSuperNode.Instance().setAliveTime();
212                 ScanThreadSuperNode.Instance().setToken(token);
213                 // -- sm modif
214                 // System.out.println( "Super Node is pinging me" ) ;
215         }
216
217
218         /*********************************/
219         /** Mapping !! Sébastien Miquée **/
220         /*********************************/
221
222         /**
223          * Search and return to the requester spawner a register containing
224          * computation nodes plus some extra nodes if needed. This method requires
225          * as parameters the mapping algorithm choice and its parameters, and the
226          * amount of requested nodes and the task to be used, in order to 
227          * construct the tasks graph.
228          * @param spawnerIP IP of the requester
229          * @param nbTasks Amount of tasks
230          * @param t Tasks to be executed
231          * @param nbNoeuds Total amount of requested nodes
232          * @param algo Identifier of the mapping algorithm
233          * @param paramAlgo Parameter of the mapping algorithm 
234          * 
235          * @author S&eacute;bastien Miqu&eacute;e        
236          */
237         @Override
238         public synchronized Register getRegisterSpawner(String spawnerIP, int nbTasks, Task t,
239                         int nbNoeuds, int algo, double paramAlgo) throws RemoteException {
240
241                 // Have we the correct application ?
242                 if( t == null ) {
243                         System.err.println( "Problem of class transmission!" ) ;
244                         return null ;
245                 }
246                 
247                 if( t.getDependencies( 0 ) == null )
248                 {
249                         System.err.println( "No redifinition of getDependencies() function!" ) ;
250                         return null ;
251                 }
252                 
253
254                 /** Creation of an empty new Register **/
255                 Register reg = new Register() ;
256
257                 workingOnGnodes() ;
258                 
259                 /** Initialization of Grid architecture (G5K for now) **/
260                 Grid grid = new Grid() ;
261
262                 for( int i = 0 ; i < gnodes.size() ; i++ )
263                 {
264                         grid.addGNode( gnodes.get( i ) ) ;
265                 }
266                 
267                 
268                 /** Informing about the grid heterogeneity **/
269                 System.out.println( "\nHeterogeneity of the grid : " + grid.getHeterogenityDegre() + "\n" ) ;
270                 
271
272                 /** Creation of tasks GTask **/
273                 ArrayList<GTask> ts = new ArrayList<GTask>();
274                 for( int i = 0; i < nbTasks; i++ ) {
275                         ts.add( new GTask( i ) ) ;
276                 }
277
278                 /** Research of dependencies **/
279                 for( int i = 0; i < nbTasks; i++ ) {
280                         int dep[] = null ;
281                         dep = t.getDependencies( i ) ;
282
283                         /** Adding dependencies to tasks **/
284                         for( int j = 0; j < dep.length; j++ ) {
285                                 if( dep[j] != -1 ) {
286                                         ts.get( i ).addDependance( ts.get( dep[ j ] ) ) ;
287                                 } else {
288                                         break ;
289                                 }
290                         }
291                 }
292                 
293                 /** Creation of the application interaction graph **/
294                 Graph graph = new Graph();
295
296                 for( int i = 0 ; i < ts.size() ; i++) 
297                 {
298                         graph.addGTask(ts.get(i));
299                 }
300
301                 /** TODO Loading algorithm class with parameters in a configuration file **/
302                 /** Selection of the mapping algorithm **/
303                 Algo al = null ;
304
305                 switch( algo ) {
306                 case 0:
307                         al = new Simple(graph, grid);
308                         break;
309                 case 1:
310                         al = new FT_AIAC_QM(graph, grid, paramAlgo);
311                         break;
312                 case 2:
313                         al = new FT_FEC(graph, grid, paramAlgo);
314                         break;
315                 case 3:
316                         al = new Maheve( graph, grid ) ;
317                         break ;
318                 default:
319                         al = new DefaultMapping( graph, grid, gnodes ) ;
320                 }
321
322                 if (al != null) 
323                 {
324                         /** Launching the Mapping **/
325                         al.map();
326
327
328                         /** Creating the register **/
329                         ArrayList<GNode> ag = al.getMapping().getMappedGNodes();
330                         
331                         System.out.println("NB returned nodes : "+ag.size());
332
333                         
334                         /** Setting the algorithm's identifier **/
335                         al.setIdS( spawnerIP ) ;
336                         
337                         /** Adding the algorithm in the list **/
338                         algos.add( al ) ;
339                         
340                         int idAlgo = searchAlgo( spawnerIP ) ;
341                         
342                         /** Mapping distribution over other SuperNodes */
343                         SuperNodeListe.Instance().setMapping( al ) ;
344                         
345                         
346                         
347                         authorized = true ;
348                         
349                         for( int i = 0; i < ag.size(); i++ ) {
350                                 reg.addNode((Node) ag.get(i).getNode());
351                                 
352                                 ag.get(i).setMapped( true ) ;
353                                 setMapped( ag.get(i), 1 ) ;
354                                 Register.Instance().removeNode((Node) ag.get(i).getNode());
355                         }
356                         
357                         
358                         /** Searching extra nodes if any **/
359                         if( nbNoeuds > nbTasks )
360                         {
361                                 int nb = nbNoeuds - nbTasks ;
362                                 GNode sup = null ;
363                                 
364                                 for( int i = 0 ; i < nb ; i ++ )
365                                 {
366                                         sup = algos.get(idAlgo).getOtherGNode( gnodes ) ;
367                                         algos.get(idAlgo).getMapping().addOtherNode( sup ) ;
368                                         reg.addNodeBeg( (Node) sup.getNode() ) ;
369                                         setMapped( sup, 1 ) ;
370                                         Register.Instance().removeNode((Node) sup.getNode());
371                                 }
372                         }
373                         
374                         authorized = false ;
375
376                         if (ag.size() != 0) {
377                                 SuperNodeListe.Instance().forwardCountNode();
378                         }
379
380                 } 
381                 
382                 operating = false ;
383                 
384                 /** Returning result **/
385                 return reg ;
386         }
387
388         
389         public synchronized void setMapped( GNode _g, int _mode ) throws RemoteException 
390         {
391                 if( _g != null )
392                 {
393                         _g.setMapped( true ) ;
394                         
395                         for( int i = 0 ; i < gnodes.size() ; i++ )
396                         {
397                                 if( _g.getId() == gnodes.get( i ).getId() )
398                                 {
399                                         gnodes.remove( i ) ;
400                                         break ;
401                                 }
402                         }
403                         
404                         for( int i = 0 ; i < algos.size() ; i++ )
405                         {
406                                 algos.get( i ).getGrid().setMappedStatus( _g, true ) ;
407                         }
408                         
409                         if( _mode == 1 )
410                         {
411                                 authorized = true ;
412                         
413                                 SuperNodeListe.Instance().setMappedGNode( _g, 0 ) ;
414                         
415                                 authorized = false ;
416                         }
417                 } else {
418                         System.err.println( "GNode is null is setMapped!" ) ;
419                 }
420         }
421
422         /**
423          * Suppress a node from the gnodes list if this node is free, or remove
424          * it from the Mapping class of the mapping algorithm if this node is
425          * a computation node. After having done the local suppression of the node
426          * it propagates the suppression to other SuperNodes.
427          * @param _n The fallen node
428          * @param _mode Choice of the list (0: gnodes, 1: mapping, 2:just mapped)
429          * 
430          * @author S&eacute;bastien Miqu&eacute;e        
431          */
432         @Override
433         public synchronized GNode delGNodeFromList( Node _n, int _mode, String _spawnerIp ) throws RemoteException
434         {
435                 GNode removedGNode = null ;
436                 
437                 if( _n != null )
438                 {       
439                         boolean free = false ;
440                         
441                         if( ! operating )
442                         {
443                                 workingOnGnodes() ;
444                                 free = true ;
445                         }
446
447                         if( _mode == 0 )
448                         {
449                                 GNode dead = null ;
450                                 
451                                 for( int i = 0 ; i < gnodes.size() ; i++ )
452                                 {
453                                         if( _n.getId() == ((Node) gnodes.get(i).getNode()).getId() )
454                                         {
455                                                 dead = gnodes.remove( i ) ;
456                                                 break ;
457                                         }
458                                 }
459                                 
460                                 if( dead != null )
461                                 {
462                                         for( int i = 0 ; i < algos.size() ; i++ )
463                                         {
464                                                 algos.get( i ).getGrid().removeGNode( dead ) ;
465                                                 Register.Instance().removeNodeOfName( dead.getName() ) ;
466                                                 SuperNodeListe.Instance().removeGNode( dead, _mode, _spawnerIp ) ;
467                                         }
468                                 } else {
469                                         System.err.println( "The dead node signaled does not exist!" ) ;
470                                 }
471                         }
472                         
473                         if( free )
474                         {
475                                 operating = false ;
476                         }
477                 
478                 }
479                 
480                 return removedGNode ;
481         }
482         
483         
484         /**
485          * Search the position of the mapping algorithm in the list.
486          * @param _id Identifier of the algorithm
487          * @return The position in the list
488          */
489         private int searchAlgo( String _id ) 
490         {
491                 int id = -1 ;
492                 
493                 for( int i = 0 ; i < algos.size() ; i++ )
494                 {
495                         if( algos.get( i ).getIdS().equals( _id ) )
496                         {
497                                 id = i ; 
498                                 break ;
499                         }
500                 }
501                 
502                 return id ;
503         }
504
505         /**
506          * Determine if this SuperNode can operate on the gnodes list.
507          * It asks other SuperNodes to know if their are working on this list
508          * and set the authorization, or not.
509          * 
510          * @author S&eacute;bastien Miqu&eacute;e        
511          */
512         private synchronized void workingOnGnodes()
513         {
514                 boolean tmp = true ;    
515                 
516                 inDemand = false ; 
517                 operating = false ;
518             
519                 while( ! operating )
520                 {
521                         inDemand = true ;
522                         tmp = true ;
523                         
524                         tmp = tmp && SuperNodeListe.Instance().workingOnGnodes() ;
525
526                         operating = tmp ;
527                         
528                         if( ! tmp )
529                         {
530                                 inDemand = false ;
531                                 
532                                 try {
533                                         Thread.sleep( 10 ) ;
534                                 } catch (InterruptedException e) {
535                                         e.printStackTrace();
536                                 }
537                         }
538                 }
539                 
540                 inDemand = false ;
541         }
542         
543         /**
544          * Search and return a new node when one failed or when JaceP2P needs another
545          * one. For the first case, the given failed node should not be null, and
546          * null in the other case.
547          * @param _spawnerIP IP of the requester
548          * @param _rank The task number number of the dead node
549          * 
550          * @author S&eacute;bastien Miqu&eacute;e
551          */
552         @Override
553         public synchronized Node getNewNode( String _spawnerIP, int _rank ) throws RemoteException
554         {
555                 int idNode = -1 ;
556                 int idAlgo = searchAlgo( _spawnerIP ) ;
557                 
558                 if( idAlgo == -1 )
559                 {
560                         System.err.println( "No algorithm found for this Spawner!" ) ;
561                         return null ;
562                 }
563                 
564                 /** We have to replace a Spawner **/
565                 if( _rank == -2 )
566                 {
567                         idNode = -2 ;
568                 } else {
569                 /** We have to replace a computing node **/
570                         idNode = algos.get( idAlgo ).getMapping().getIdOfAssociation( _rank ) ;
571                 }
572                 
573                 if( idNode == -1 )
574                 {
575                         System.err.println( "No tasks corresponds to rank "+_rank+"!" ) ;
576                         return null ;
577                 }
578                 
579                 GNode dead = null ;
580                 
581                 if( idNode >= 0 ) 
582                 {
583                         dead = algos.get( idAlgo ).getMapping().getAssociation( idNode ).getGNode() ;
584                 }
585                 
586                 if( dead == null && idNode >= 0 )
587                 {
588                         System.err.println( "The GNode corresponding to the task "+_rank+" is null!" ) ;
589                         System.err.println( "Trying to find a new node for this task (not optimal)..." ) ;
590                 }
591                 
592                 return getNewNode( _spawnerIP, dead ) ;
593         }
594
595         /**
596          * Search and return a new node when one failed or when JaceP2P needs another
597          * one. For the first case, the given failed node should not be null, and
598          * null in the other case.
599          * @param _spawnerIP IP of the requester
600          * @param _deadNode The failed node
601          * 
602          * @author S&eacute;bastien Miqu&eacute;e
603          */
604         @Override
605         public synchronized Node getNewNode( String _spawnerIP, GNode _deadNode ) throws RemoteException
606         {
607                 Node node = null ;
608                 GNode remp = null ;
609
610                 int idAlgo = searchAlgo( _spawnerIP ) ;
611                 
612                 if( idAlgo == -1 )
613                 {
614                         System.err.println( "No algorithm found for this Spawner!" ) ;
615                         return null ;
616                 }
617                 
618                 
619                 /** Can we use gnodes ?**/
620                 workingOnGnodes() ;
621                 
622                 if( _deadNode != null )         
623                 {
624                         authorized = true ;
625                         
626                         removeMappedGNode( _deadNode, 1 ) ;
627                         
628                         authorized = false ;
629
630                         remp = algos.get( idAlgo ).replaceNode( _deadNode, gnodes ) ;
631                 
632                         if( remp != null )
633                         {
634                                 System.out.println( "Replacing node found." ) ;
635                                 
636                                 authorized = true ;
637                                 
638                                 remp.setMapped( true ) ;
639                                 
640                                 setMapped( remp, 1 ) ;
641                                 Register.Instance().removeNodeOfName( remp.getName() ) ;
642                                 
643                                 
644                                 /** Updating all mapping **/
645                                 updateMappedNode( _deadNode, remp, _spawnerIP ) ;
646                                 propagateReplaceNode( _deadNode, remp, _spawnerIP ) ;
647                                 
648                                 authorized = false ;
649                                 
650                                 SuperNodeListe.Instance().forwardCountNode();
651                         } else {
652                                 System.err.println( "Replacing node not found !!" ) ;
653                         }
654                 } else {
655                         remp = algos.get( idAlgo ).getOtherGNode( gnodes ) ;
656                         
657                         if( remp != null )
658                         {
659                                 System.out.println( "Other new node found." ) ;
660
661                                 remp.setMapped( true ) ;
662                                 
663                                 authorized = true ;
664                                 
665                                 setMapped( remp, 1 ) ;
666                                 Register.Instance().removeNodeOfName( remp.getName() ) ;
667                                 
668                                 authorized = false ;
669                                 
670                                 SuperNodeListe.Instance().forwardCountNode();
671                         } else {
672                                 System.err.println( "Other new node not found !!" ) ;
673                         }
674                 }
675                 
676                 if( remp != null )
677                 {
678                         node = (Node) remp.getNode() ;
679                 } else {
680                         System.err.println( "SuperNode: No new node found!" ) ;
681                 }
682                 
683                 
684                 /** Free the gnodes use **/
685                 operating = false ;
686                 
687                 return node ;
688         }
689         
690         
691         public synchronized void removeMappedGNode( GNode _g, int _mode ) throws RemoteException
692         {
693                 if( _g != null )
694                 {
695                         for( int i = 0 ; i < algos.size() ; i++ )
696                         {
697                                 algos.get( i ).getGrid().removeGNode( _g ) ;
698                         }
699                         
700                         if( _mode == 1 )
701                         {
702                                 SuperNodeListe.Instance().removeGNode( _g, 0 ) ;
703                         }
704                 } else {
705                         System.err.println( "GNode to be deleted is null!" ) ;
706                 }
707         }
708         
709         /**
710          * Replace a failed GNode in the mapping by another one.
711          * This method is called by the SuperNodeList, to broadcast the modification.
712          * @param _dead The failed node
713          * @param _remp The replacing node
714          * 
715          * @author S&eacute;bastien Miqu&eacute;e
716          */
717         @Override
718         public synchronized void updateMappedNode( GNode _dead, GNode _remp, String _spawnerIP ) 
719         {
720                 if( _remp != null )
721                 {
722                         int pos = 0 ;
723                         
724                         int idAlgo = searchAlgo( _spawnerIP ) ;
725                         
726                         if( idAlgo == -1 )
727                         {
728                                 System.err.println( "No algorithm found for this Spawner!" ) ;
729                                 return ;
730                         }
731                 
732                         pos = algos.get( idAlgo ).getMapping().getIdOfAssociation( _dead ) ;
733                 
734                         if( pos != -1 )
735                         {
736                                 /** Changing the node in the mapping **/
737                                 if( algos.get( idAlgo ).getMapping().getMapping().get( pos ).setGNode( _remp ) )
738                                 {
739                                         System.out.println( "Succesfully replacing the fallen node in the mapping." ) ;
740                                 } else {
741                                         System.err.println( "Failed in replacing the fallen node in the mapping!" ) ;
742                                 }
743                         } else {
744                                 System.err.println( "The dead node was not found in the mapping!" ) ;
745                         }
746                         
747                 } else {
748                         System.err.println( "The new GNode is null!" ) ;
749                 }       
750         }
751
752         
753         /**
754          * Inform all SuperNodes of the replacement of a failed computing node.
755          * @param _dead The failed node
756          * @param _remp The replacing node
757          * 
758          * @author S&eacute;bastien Miqu&eacute;e        
759          */
760         private synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP ) throws RemoteException
761         {
762                 if( _remp != null )
763                 {       
764                         SuperNodeListe.Instance().propagateReplaceNode( _dead, _remp, _spawnerIP ) ;
765                 } else {
766                         System.err.println( "The replacement node is null!" ) ;
767                 }
768         }
769
770         /**********************************************************/
771         /**********************************************************/
772
773         
774         @Override
775         /**
776          * Add a new node in the list.
777          * @param _g The new node
778          *
779          * @author S&eacute;bastien Miqu&eacute;e        
780          */
781         public void addGNode( GNode _g ) throws RemoteException 
782         {
783                 if( _g != null )
784                 {
785                         boolean free = false ;
786                         
787                         if( ! operating )
788                         {
789                                 workingOnGnodes() ;
790                                 free = true ;
791                         }       
792                         
793                         gnodes.add( _g ) ;
794                         
795                         updateGrids( _g ) ;
796                         
797                         if( free )
798                                 operating = false ;
799                 }
800         }
801         
802
803         /**
804          * Set the local mapping with another done on an other SuperNode.
805          * @param _al The new mapping
806          * 
807          * @author S&eacute;bastien Miqu&eacute;e
808          */
809         @Override
810         public synchronized void setMapping( Algo _al ) throws RemoteException 
811         {
812                 if( searchAlgo( _al.getIdS() ) == -1 )
813                 {
814                         algos.add( _al ) ;
815                 } else {
816                         System.err.println( "I already have this mapping algorithm!" ) ;
817                 }
818         }
819
820         
821         @Override
822         /**
823          * Allow or deny the use of operations on the gnodes list, in order to
824          * do a mapping operation.
825          * @return The authorization or not to block gnodes
826          * 
827          * @author S&eacute;bastien Miqu&eacute;e
828          */
829         public boolean blockForMapping() throws RemoteException
830         {
831                 while( inDemand )
832                 {
833                         try {
834                                 Thread.sleep( 10 ) ;
835                         } catch (InterruptedException e) {
836                                 e.printStackTrace();
837                         }
838                 }
839                 
840                 if( operating && ! authorized )
841                 {
842                         return false ;
843                 } else {
844                         return true ;
845                 }
846         }
847
848         /**
849          * Return the array containing the current not mapped nodes available.
850          * @return The array of available nodes
851          * 
852          * @author S&eacute;bastien Miqu&eacute;e 
853          */
854         @Override
855         public ArrayList<GNode> getGNodes() throws RemoteException 
856         {
857                 return gnodes ;
858         }
859         
860         
861         /**
862          * Remove a mapping algorithm of the algorithms list.
863          * @param _id The algorithm identifier
864          * @param _mode Indicate if the information should be transmitted
865          * 
866          * @author S&eacute;bastien Miqu&eacute;e
867          */
868         public void removeAlgo( String _id, int _mode ) throws RemoteException
869         {
870                 int pos ;
871                 
872                 pos = searchAlgo( _id ) ;
873                 
874                 if( pos != -1 )
875                 {
876                         algos.remove( pos ) ;
877                         
878                         if( _mode == 0 )
879                         {
880                                 SuperNodeListe.Instance().removeAlgo( _id ) ;
881                         }
882                 } else {
883                         System.err.println( "The mapping algorithm requested for deletion does not exist!" ) ;
884                 }
885         }
886         
887         
888         // ** Tests ** //
889         public Algo getAlgo( String _spID ) throws RemoteException
890         {
891                 int pos ;
892                 Algo ret = null ;
893                 
894                 pos = searchAlgo( _spID ) ;
895                 
896                 if( pos != -1 )
897                 {
898                         ret = algos.get( pos ) ;
899                 }
900                 
901                 return ret ;
902         }
903         
904         
905 }
906
907 /** ! **/