+
+ public void treatRequestSave( String _ip )
+ {
+ if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
+ {
+ if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
+ {
+ // Mark it as a requester
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ applications.get( ind ).getComputingClients().get( i ).setSaveRequest( true ) ;
+
+ break ;
+ }
+ }
+
+ semaSave.release() ;
+
+ // Is every body ok?
+ boolean ok = false ;
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ if( i == 0 )
+ {
+ ok = applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
+ } else {
+ ok = ok & applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
+ }
+
+ if( ! ok )
+ {
+ break ;
+ }
+ }
+
+ if( ok )
+ {
+// try {
+// Thread.sleep( 5000 ) ;
+// } catch( InterruptedException e1 ) {
+// e1.printStackTrace() ;
+// }
+
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ try {
+ applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
+ applications.get( ind ).getComputingClients().get( i ).setSaveRequest( false ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to send the save request response to " +
+ applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+ e.printStackTrace() ;
+ }
+ }
+
+ applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
+ }
+
+ } else {
+ semaSave.release() ;
+
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ try {
+ applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to send the save request response to " +
+ applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+ e.printStackTrace() ;
+ }
+ break ;
+ }
+ }
+ }
+ } else {
+ semaSave.release() ;
+ System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
+ }
+ }
+
+
+ @Override
+ public void restartOk( String _ip )
+ {
+ if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
+ {
+ System.out.println( "Client " + _ip + " has finished to restart ("+applications.get( ind ).getComputingClients().size()+") ... " ) ;
+// if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
+ {
+ // Has it already finished?
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ applications.get( ind ).getComputingClients().get( i ).setRestartOk( true ) ;
+
+ break ;
+ }
+ }
+
+ // Is everybody ok?
+ boolean ok = false ;
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ if( i == 0 )
+ {
+ ok = applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
+ } else {
+ ok = ok & applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
+ }
+
+ if( ! ok )
+ {
+ break ;
+ }
+ }
+
+ if( ok )
+ {
+ applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
+
+ for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
+ {
+ applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
+ }
+ }
+
+ }
+ }
+ }
+
+
+ @Override
+ public void goApplication()
+ {
+ synchronized( applications ) {
+ if( running && ! applications.get( ind ).getStartMark() )
+ {
+ System.out.println( "Application is starting." ) ;
+ applications.get( ind ).setStartMark() ;
+ applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
+ applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
+ }
+ }
+ }
+