Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b776409f57fa7bf63df4c8fdcc86dc475138bbdf
[hpcvm.git] / src / and / hpcvm / Server.java
1 package and.hpcvm ;
2
3 import java.rmi.Naming;
4 import java.rmi.RemoteException;
5 import java.rmi.registry.LocateRegistry;
6 import java.rmi.registry.Registry;
7 import java.rmi.server.UnicastRemoteObject;
8 import java.util.ArrayList;
9 import java.util.Iterator;
10
11
12 public class Server extends UnicastRemoteObject implements ServicesServer
13 {
14         private class DiscCount
15         {
16                 private int nb ;
17                 
18                 DiscCount() { nb = 0 ; }
19                 
20                 protected void inc() { nb++ ; }
21                 
22                 protected void dec() { 
23                         if( nb > 0 )
24                         {
25                                 nb-- ;
26                         }
27                 }
28                 
29                 protected int getNb() { return nb ; }
30         }
31         
32         
33         private class ConnectedClient
34         {
35                 private ServicesClient stub ;
36                 private int timeout ;
37                 private Status state ;
38                 private String ip ;
39                 private String name ;
40                 private ComputingClient cl ;
41                 
42                 ConnectedClient( ServicesClient _stub )
43                 {
44                         stub = _stub ;
45                         timeout = 0 ;
46                         state = new Status() ;
47                         state.setStatus( "connected" ) ;
48                         try {
49                                 ip = stub.getIPHost() ;
50                                 name = stub.getName() ;
51                         } catch (RemoteException e) {
52                                 e.printStackTrace();
53                         }
54                         cl = null ;
55                 }
56                 
57                 protected ServicesClient getStub() { return stub ; }
58                 
59                 protected void setStub( ServicesClient _stub ) { stub = _stub ; }
60                 
61                 protected int getTimeout() { return timeout ; }
62                 
63                 protected void incTimeout() { timeout++ ; }
64                 
65                 protected void resetTimeout() { timeout = 0 ; }
66                 
67                 protected String getStatus() { return state.getStatus() ; }
68                 
69                 protected void setStatus( String _state ) { state.setStatus( _state ) ; }
70                 
71                 protected String getIP() { return ip ; }
72                 
73                 protected String getName() { return name ; } ;
74                 
75                 protected void setComputingClient( ComputingClient _cl ) { cl = _cl ; }
76                 
77                 protected ComputingClient getComputingClient() { return cl ; } 
78         }
79         
80         
81         private class ComputingClient
82         {
83                 private ConnectedClient client ;
84                 private boolean save_status ;
85                 private ArrayList<ServicesClient> save_neighbor ;
86                 private String lastSaveName ;
87                 
88                 ComputingClient( ConnectedClient cl )
89                 {
90                         client = cl ;
91                         save_status = false ;
92                         save_neighbor = new ArrayList<ServicesClient>() ;
93                         lastSaveName = "none" ;
94                 }
95                 
96                 protected ConnectedClient getClient() { return client ; }
97                 
98                 protected boolean getSaveStatus(){ return save_status ; }
99                 
100                 protected void setSaveStatus( boolean _status ) { save_status = _status ; }
101                 
102                 protected void setSaveNeighbor( ServicesClient _sn ) 
103                 { 
104                         if( _sn != null )
105                         {
106                                 save_neighbor.set( 0, _sn ) ; 
107                                 
108                                 System.out.println( "My save neighbor is " + _sn ) ;
109                         
110                                 try {
111                                         client.getStub().setSavingNeighbor( _sn ) ;
112                                 } catch( RemoteException e ) {
113                                         System.err.println( "Error while setting save neighbor on " + 
114                                                         client.getName() + "(" + client.getIP() + ")!" ) ;
115                                         e.printStackTrace() ;
116                                 }
117                         }
118                 }
119                 
120                 protected ServicesClient getSaveNeighbor() 
121                 {
122                         if( save_neighbor.isEmpty() )
123                         {
124                                 return null ;
125                         } else {
126                                 return save_neighbor.get( 0 ) ;
127                         }
128                 }
129
130                 public void setLastSave( String _saveName ) 
131                 {
132                         lastSaveName = _saveName ;                      
133                 }
134                 
135                 public String getLastSave() { return lastSaveName ; }
136                 
137         }
138         
139         
140         private class IPAssociation
141         {
142                 private String vmIP ;
143                 private String hostIP ;
144                 
145                 IPAssociation()
146                 {
147                         vmIP = null ;
148                         hostIP = null ;
149                 }
150                 
151                 protected void setVmIP( String _vmIP )
152                 {
153                         vmIP = _vmIP ;
154                 }
155                 
156                 protected void setHostIP( String _hostIP )
157                 {
158                         hostIP = _hostIP ;
159                 }
160                 
161                 protected String getVmIP()
162                 {
163                         return vmIP ;
164                 }
165                 
166                 protected String getHostIP()
167                 {
168                         return hostIP ;
169                 }
170         }
171         
172         
173         
174         private static final long serialVersionUID = 1L ;
175         private int port ;
176         private ArrayList<ConnectedClient> clients ;
177         private ArrayList<ComputingClient> computingClients ;
178         private int max_timeout ;
179         private ConnectedMonitor monitor ;
180         private DiscCount counter ;
181         private ArrayList<IPAssociation> vmIPs ;
182         
183         
184         protected Server() throws RemoteException 
185         {
186                 super() ;
187         }
188
189
190
191         @Override
192         public Integer register( ServicesClient _stub ) 
193         {
194                 if( _stub != null )
195                 {
196                         String ip = "" ;
197                         try {
198                                 ip = _stub.getIPHost() ;
199                         } catch (RemoteException e) {
200                                 e.printStackTrace() ;
201                                 return 1 ;
202                         }
203                         
204                         boolean exists = false ;
205                         int i ;
206                         
207                         for( i = 0 ; i < clients.size() ; i++ )
208                         {
209                                 if( ip.equals( clients.get( i ).getIP() ) )
210                                 {
211                                         exists = true ;
212                                         System.out.println( "Client already connected!" ) ;
213                                         break ;
214                                 }
215                         }
216                         
217                         if( exists )
218                         {
219                                 System.out.println( "The client stub will be replaced." ) ;
220                                 clients.get( i ).setStub( _stub ) ;
221                                 System.out.println( "(reconnection of " + clients.get( i ).getName() + ")" ) ;
222                                 return 2 ;
223                         } else {
224                                 System.out.println( "New connection!" ) ;
225                                 clients.add( new ConnectedClient( _stub ) ) ;
226                                 System.out.println( "(connection of " + clients.get( clients.size() - 1 ).getName() + ")" ) ;
227                                 generateVmIP( ip ) ;
228                                 
229                                 if( clients.size() == 0 )
230                                 {
231                                         System.out.println( "There is no client connected." ) ;
232                                 } else if( clients.size() == 1 ) {
233                                         System.out.println( "There is one client connected." ) ;
234                                 } else {
235                                         System.out.println( "There are " + clients.size() + " clients connected." ) ;
236                                 }
237
238                                 return 0 ;
239                         }
240                 }
241                 
242                 return 1 ;
243         }
244
245         
246         private void generateVmIP( String _ip ) 
247         {
248                 if( _ip != null && ! _ip.equals( "" ) ) 
249                 {       
250                         for( int i = 0 ; i < vmIPs.size() ; i++ )
251                         {
252                                 if( vmIPs.get( i ).getHostIP() == null )
253                                 {
254                                         vmIPs.get( i ).setHostIP( _ip ) ;
255                                         
256                                         break ;
257                                 }
258                         }
259                 }
260         }
261         
262
263         @Override
264         public void ping( String _ip ) 
265         {
266                 if( _ip != null )
267                 {
268                         for( int i = 0 ; i < clients.size() ; i++ )
269                         {
270                                 if( _ip.equals( clients.get( i ).getIP() ) ) 
271                                 {
272                                         clients.get( i ).resetTimeout() ;
273                                         break ;
274                                 }
275                         }
276                 }               
277         }
278
279         
280         @Override
281         public void changeStatus( String _ip, String _status ) 
282         {
283                 if( _ip != null && _status != null )
284                 {
285                         for( int i = 0 ; i < clients.size() ; i++ )
286                         {
287                                 if( _ip.equals( clients.get( i ).getIP() ) ) 
288                                 {
289                                         clients.get( i ).setStatus( _status ) ;
290                                         System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
291                                         break ;
292                                 }
293                         }
294                 }
295         }
296         
297
298         public void init( int _port ) 
299         {       
300                 port = _port ;
301                 max_timeout = 4 ;
302                 
303                 clients = new ArrayList<Server.ConnectedClient>() ;
304                 computingClients = new ArrayList<Server.ComputingClient>() ;
305                 monitor = null ;
306                 
307                 exportObject() ;
308
309                 vmIPs = new ArrayList<IPAssociation>() ;
310                 // TODO initialisation of VM IPs
311                 for( int i = 2 ; i < 101 ; i++ )
312                 {
313                         vmIPs.add( new IPAssociation() ) ;
314                         vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
315                 }
316                 
317                 clients = new ArrayList<Server.ConnectedClient>() ;
318                 
319                 counter = new DiscCount() ;
320                 
321                 monitor = new ConnectedMonitor() ;
322                 monitor.start() ;
323         }
324         
325         
326         public void stop()
327         {
328                 if( monitor != null ) { monitor.stopMonitor() ; }
329                 
330                 for( int i = 0 ; i < clients.size() ; i++ )
331                 {
332                         try {
333                                 clients.get( i ).getStub().stop() ;
334                         } catch (RemoteException e) {
335                                 e.printStackTrace();
336                         }
337                 }
338                 
339                 // unexportObject ?
340                 
341                 System.exit( 0 ) ;
342         }
343
344         
345         private void exportObject() 
346         {
347                 ServicesServer ref = null ;
348                 Registry reg = null ;
349                 
350                 try 
351                 {       
352                         while( true )
353                         {
354                                 reg = LocateRegistry.getRegistry( port ) ;
355
356                                 String tab[] = reg.list() ;
357                         
358                                 System.out.println( "There is an existing RMI Registry on port " +
359                                                 port + " with " + tab.length + " entries!" ) ;
360                                 for( int i = 0 ; i < tab.length ; i++ )
361                                 {
362                                         try {
363                                                 if( UnicastRemoteObject.unexportObject( Naming.lookup(tab[i]), true ) )
364                                                 {
365                                                         System.out.println( "Register successfuly deleted!" ) ;
366                                                 } else {
367                                                         System.err.println( "Register undeleted !!!" ) ;
368                                                 }
369                                         } catch( Exception e ) {
370                                                 e.printStackTrace() ;
371                                         }
372                                 } 
373                         }
374                 } catch( RemoteException e ) {
375                 }       
376                                 
377                 try {
378                         if ( System.getSecurityManager() == null ) 
379                         {
380                     System.setSecurityManager( new SecurityManager() ) ;
381                 }
382                         
383                         LocateRegistry.createRegistry( port ) ;
384                         LocateRegistry.getRegistry( port ).rebind( "Server", this ) ;
385                         ref = (ServicesServer) Naming.lookup( "rmi://"
386                                         + LocalHost.Instance().getIP() + ":" + port
387                                         + "/Server" ) ;
388                 } catch ( Exception e ) {
389                         System.err.println( "Error in Server.exportObject() when creating local services:" + e ) ;
390                         System.err.println( "Exit from Server.exportObject" ) ;
391                         System.exit( 1 ) ;
392                 }
393
394                 LocalHost.Instance().setServerStub( ref ) ;
395                 
396                 System.out.println( "Server launched on IP " + LocalHost.Instance().getIP() + 
397                                 " on port " + port + "." ) ;
398         }
399         
400         /** Fault manager thread **/
401         private class FaultManager extends Thread
402         {
403                 ConnectedClient cl ;
404                 
405                 FaultManager( ConnectedClient _cl )
406                 {
407                         cl = _cl ;
408                 }
409                 
410                 @Override
411                 public void run() 
412                 {
413                         if( cl != null && cl.getStatus().equalsIgnoreCase( "running" ) ||
414                                         cl.getStatus().equalsIgnoreCase( "saving" ) )
415                         {
416                                 ComputingClient cc = cl.getComputingClient() ;
417                                 ServicesClient dead = cc.getClient().getStub() ;
418                                 String ipDead = cc.getClient().getIP() ;
419                                                                 
420                                 boolean ok = false ;
421                                 
422                                 for( int i = 0 ; i < clients.size() ; i++ )
423                                 {
424                                         if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) ) 
425                                         {
426 //                                              int res = 1 ;
427 //                                              try {
428 //                                                      res = clients.get( i ).getStub().startVM() ;
429 //                                              } catch( RemoteException e ) {
430 //                                                      e.printStackTrace();
431 //                                              }
432 //                                              
433 //                                              if( res == 0 )
434 //                                              {
435                                                         //clients.get(i).setStatus( "running" ) ;
436                                                 
437                                                 int pos = computingClients.indexOf( cc )  ;
438                                                 if( pos == -1 )
439                                                 {
440                                                         System.err.println( "Dead client not found in the computing clients list!" ) ;
441                                                 } else {
442                                                         System.out.println( "Trying to replace " + cc.getClient().getName() + " with " +
443                                                                         clients.get(i).getName() + " ... " ) ;
444                                                         
445                                                         String save_name = computingClients.get( pos ).getLastSave() ;
446                                                         
447                                                         ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
448                                                         clients.get( i ).setComputingClient( ccl ) ;
449                                                         ServicesClient sn = computingClients.get( pos ).getSaveNeighbor() ;
450                                                         ccl.setSaveNeighbor( sn ) ;
451                                                         computingClients.set( pos, ccl ) ;
452
453                                                                 
454                                                         int res = 1 ;
455                                                         try {
456                                                                 res = computingClients.get( pos ).getClient().getStub().
457                                                                       retrieveSave( save_name ) ;
458                                                         } catch( RemoteException e ) {
459                                                                 System.err.println( "Unable to indicate to client to retrieve last save!" ) ;
460                                                                 e.printStackTrace() ;
461                                                         }
462                                                                 
463                                                         if( res == 0 )
464                                                         {
465                                                                 ok = true ;
466                                                                         
467                                                                         // replace dead client in vmIPs
468                                                                 for( int j = 0 ; j < vmIPs.size() ; j++ )
469                                                                 {
470                                                                         if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
471                                                                         {
472                                                                                 String vmIP = vmIPs.get( j ).getVmIP() ;
473                                                                                 vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
474                                                                                         
475                                                                                 try {
476                                                                                         computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
477                                                                                 } catch( RemoteException e ) {
478                                                                                         System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
479                                                                                         e.printStackTrace() ;
480                                                                                 }
481                                                                                 break ;
482                                                                         }
483                                                                 }
484                                                                         
485                                                                 System.out.println( "Successful redeployment of the VM." ) ;
486                                                         } else {
487                                                                 System.err.println( "Unable to deploy the save on the new computing client!" ) ;
488                                                         }
489                                                 }
490 //                                              } else {
491 //                                                      System.err.println( "Problem while launching the VM on " 
492 //                                                                      + clients.get(i).getName() + "!" ) ;
493 //                                              }
494                                                         
495                                                 if( ok )
496                                                 {
497                                                         for( int k = 0 ; k < computingClients.size() ; k++ )
498                                                         {
499                                                                 try {
500                                                                         computingClients.get( i ).getClient().getStub().
501                                                                                 replaceSavingNeighbor( dead, clients.get( i ).getStub() ) ;
502                                                                 } catch( RemoteException e ) {
503                                                                         System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
504                                                                                         " of the replacement of a save neighbor!" ) ;
505                                                                         e.printStackTrace() ;
506                                                                 }
507                                                         }
508                                                         
509                                                         
510                                                         System.out.println( "Dead client successfully replaced." ) ;
511                                                         // restart vms
512                                                         break ;
513                                                 } else {
514                                                         System.err.println( "Dead client not replaced!!" ) ;
515                                                 }
516                                         }
517                                 }
518                         }
519                         
520                         try {
521                                 synchronized( counter ) {
522                                         counter.dec() ;
523                                         counter.notifyAll() ;}
524                         } catch( Exception e ) {}
525                 }
526         }
527         
528         
529         /** Monitoring thread **/
530         private class ConnectedMonitor extends Thread
531         {
532                 boolean run ;
533                 
534                 ConnectedMonitor()
535                 {
536                         run = true ;
537                 }
538                 
539                 protected void stopMonitor() { run = false ; }
540                 
541                 @Override
542                 public void run() 
543                 {
544                         boolean change ;
545                         
546                         while( run )
547                         {
548                                 change = false ;
549                                 Iterator<ConnectedClient> it = clients.iterator() ;
550                                 int nb_disconnections = 0 ;
551                                 int nb_disconnections_computing = 0 ;
552                                 
553                                 while( it.hasNext() )
554                                 {
555                                         ConnectedClient cl = it.next() ;
556                                         cl.incTimeout() ;
557                                         
558                                         if( cl.getTimeout() > max_timeout )
559                                         {
560                                                 System.out.println( "Disconnection of " + cl.getName() ) ;
561                                                 if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
562                                                 {
563                                                         System.out.println( "A VM was running on it!!" ) ;
564                                                         System.out.println( "I will redeploy a save and restart all VM ..." ) ;
565                                 
566 //                                                      for( int i = 0 ; i < computingClients.size() ; i++ )
567 //                                                      {
568 //                                                              if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
569 //                                                              {
570 //                                                                      computingClients.remove( i ) ;
571 //                                                                      break ;
572 //                                                              }
573 //                                                      }
574                                                         synchronized( counter ){
575                                                                 counter.inc() ;}
576                                                                 
577                                                         
578                                                         new Server.FaultManager( cl ).start() ;
579                                                         nb_disconnections_computing++ ;
580                                                 } else {
581                                                         System.out.println( "There was no VM running on it." ) ;
582                                                         System.out.println( "Maybe it will come back later :)" ) ;
583                                                 }
584                                                 
585                                                 it.remove() ;
586                                                 nb_disconnections++ ;
587                                                 change = true ;
588                                         }
589                                 }
590                                 
591                                 if( change )
592                                 {
593                                         if( clients.size() == 0 )
594                                         {
595                                                 System.out.println( "There is no client connected." ) ;
596                                         } else if( clients.size() == 1 ) {
597                                                 System.out.println( "There is one client connected." ) ;
598                                         } else {
599                                                 System.out.println( "There are " + clients.size() + " clients connected." ) ;
600                                         }
601                                 }
602                                 
603                                 
604                                 if( nb_disconnections_computing > 0 )
605                                 {
606                                         System.out.println( "Sending emergency stop signal to all computing nodes ... " ) ;
607                                         
608                                         for( int i = 0 ; i < clients.size() ; i++ )
609                                         {
610                                                 if( clients.get( i ).getStatus().equalsIgnoreCase( "running" ) 
611                                                         || clients.get( i ).getStatus().equalsIgnoreCase( "saving" ) )
612                                                 {
613                                                         try {
614                                                                 clients.get( i ).getStub().emergencyStop() ;
615                                                         } catch( RemoteException e ) {
616                                                                 System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ;
617                                                                 e.printStackTrace() ;
618                                                         }
619                                                 }
620                                         }
621                                         
622                                         System.out.println( "I will redeploy save and restart VMs ... " ) ;
623                                         
624                                         synchronized( counter ) 
625                                         {
626                                                 if( counter.getNb() > 0 )
627                                                 {
628                                                         System.out.println( "... waiting all redeployments done ..." ) ;
629                                                 }
630                                         
631                                                 while( counter.getNb() != 0 )
632                                                 {
633                                                         try {
634                                                                 System.out.println( "### WAITING counter ###" ) ;
635                                                                 counter.wait() ;  // !!!!! synchro
636                                                         } catch( InterruptedException e ) {
637                                                                 e.printStackTrace() ;
638                                                         }
639                                                 }
640                                         }
641                                         
642                                         for( int  i = 0 ; i < computingClients.size() ; i++ )
643                                         {
644                                                 final ServicesClient sc = computingClients.get( i ).getClient().getStub() ;
645                                                 
646                                                 new Thread( new Runnable() {
647                                                         
648                                                         @Override
649                                                         public void run() 
650                                                         {
651                                                                 try {
652                                                                         sc.restartVMAfterCrash() ;
653                                                                 } catch( RemoteException e ) {
654                                                                         e.printStackTrace() ;
655                                                                 }
656                                                         }
657                                                 } ).start() ;
658                                         }
659                                 }
660                                 
661                                 try 
662                                 {
663                                         Thread.sleep( 2000 ) ;
664                                 } catch( InterruptedException e ) {
665                                         e.printStackTrace() ;
666                                 }
667                         }
668                 }
669         }
670
671         @Override
672         public Integer saveOk( String _ip, String _saveName ) 
673         {
674                 int i ;
675                 for( i = 0 ; i < computingClients.size() ; i ++ )
676                 {
677                         if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) ) 
678                         {
679                                 computingClients.get( i ).setLastSave( _saveName ) ;
680                                 computingClients.get( i ).setSaveStatus( true ) ;
681                                 break ;
682                         }
683                 }
684                 
685                 
686                 boolean all_ok = true ;
687                 i = 0 ;
688                 
689                 while( all_ok && i < computingClients.size() )
690                 {
691                         all_ok = all_ok & computingClients.get( i ).getSaveStatus() ;
692                         i++ ;
693                 }
694                 
695                 if( all_ok )
696                 {
697                         for( i = 0 ; i < computingClients.size() ; i++ )
698                         {
699                                 try {
700                                         computingClients.get( i ).getClient().getStub().saveOk() ;
701                                 } catch (RemoteException e) {
702                                         e.printStackTrace();
703                                 }
704                                 computingClients.get( i ).setSaveStatus( false ) ;
705                         }
706                 }
707                 
708                 return 0 ;
709         }
710
711
712
713         @Override
714         public ArrayList<ServicesClient> startApplication( int _nb ) 
715         {
716                 int nb = clients.size() - computingClients.size() ;
717                 
718                 if( nb > _nb )
719                 {
720                         ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
721                         ArrayList<ComputingClient> tmp = new ArrayList<Server.ComputingClient>() ;
722                         
723                         int i = 0 ;
724                         
725                         while( i < clients.size() && ac.size() < _nb )
726                         {
727                                 if( clients.get(i).getStatus().equalsIgnoreCase( "connected" ) ) 
728                                 {
729                                         int res = 1 ;
730                                         try {
731                                                 res = clients.get( i ).getStub().startVM( 0 ) ;
732                                         } catch( RemoteException e ) {
733                                                 e.printStackTrace();
734                                         }
735                                         
736                                         if( res == 0 )
737                                         {
738                                                 ac.add( clients.get( i ).getStub() ) ;
739                                                 clients.get( i ).setStatus( "running" ) ;
740                                                 ComputingClient cl = new ComputingClient( clients.get( i ) ) ;
741                                                 clients.get( i ).setComputingClient( cl ) ;
742                                                 computingClients.add( cl ) ;
743                                                 tmp.add( cl ) ;
744                                         } else {
745                                                 System.err.println( "Problem while launching the VM on " 
746                                                                 + clients.get(i).getName() + "!" ) ;
747                                         }
748                                 }
749                                 
750                                 i++ ;
751                         }
752                         
753                         if( ac.size() == _nb )
754                         {
755                                 int index, index2 ;
756                                 /* Choosing save neighbors */
757                                 for( i = 0 ; i < tmp.size() ; i++ )
758                                 {
759                                         if( i == tmp.size() - 1 )
760                                         {
761                                                 index = computingClients.indexOf( tmp.get( i ) ) ;
762                                                 index2 = computingClients.indexOf( tmp.get( 0 ) ) ;
763                                                 
764                                                 if( index == -1 || index2 == -1 )
765                                                 {
766                                                         System.err.println( "Problem in ComputingClients list!" ) ;
767                                                 } else {
768                                                         computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
769                                                 }
770                                         } else {
771                                                 index = computingClients.indexOf( tmp.get( i ) ) ;
772                                                 index2 = computingClients.indexOf( tmp.get( i + 1 ) ) ;
773                                                 
774                                                 if( index == -1 || index2 == -1 )
775                                                 {
776                                                         System.err.println( "Problem in ComputingClients list!" ) ;
777                                                 } else {
778                                                         computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
779                                                 }
780                                         }
781                                 }
782                         }
783                         
784                         /* Cleaning */
785                         tmp.clear() ;
786                         tmp = null ;
787                         
788                         return ac ;
789                 }
790                 
791                 return null ;
792         }
793
794
795
796         @Override
797         public void endApplication() 
798         {
799                 Iterator<ComputingClient> it = computingClients.iterator() ;
800                 
801                 while( it.hasNext() )
802                 {
803                         ComputingClient cl = it.next() ;
804
805                         try {
806                                 cl.getClient().getStub().stopVM() ;
807                         } catch (RemoteException e) {
808                                 e.printStackTrace();
809                         }
810                         
811                         cl.getClient().setStatus( "connected" ) ;
812                         cl.getClient().setComputingClient( null ) ;
813                         it.remove() ;
814                         cl = null ;
815                 }
816                 
817         }
818
819
820
821         @Override
822         public String getAssociatedIP( String _ip ) throws RemoteException 
823         {
824                 String ret = null ;
825                 
826                 for( int i = 0 ; i < vmIPs.size() ; i++ )
827                 {
828                         if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( _ip ) )
829                         {
830                                 ret = vmIPs.get( i ).getVmIP() ;
831                                 break ;
832                         }
833                 }
834                 
835                 return ret ;
836         }
837         
838 }
839
840 /** La programmation est un art, respectons ceux qui la pratiquent !! **/
841