super() ;
}
-
+
+ public void setSaveTime( int _saveTime )
+ {
+ save_interleave = _saveTime * 60 * 1000 ;
+ }
+
@Override
public Integer register( ServicesClient _stub )
clients.get( i ).getStub().emergencyStop() ;
clients.get( i ).getStub().stop() ;
} catch (RemoteException e) {
- e.printStackTrace();
+ System.err.println( "Unable to send stop signal to " + clients.get( i ).getName() ) ;
+ e.printStackTrace() ;
}
}
} catch( RemoteException e ) {
System.err.println( "Unable to indicate to client to retrieve last save!" ) ;
e.printStackTrace() ;
+ yield() ;
}
if( res == 0 )
} catch( RemoteException e ) {
System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
e.printStackTrace() ;
+ yield() ;
}
if( ok_new && ok_old )
@Override
public void run()
{
- boolean change ;
+ boolean change, dead ;
while( run )
{
{
ConnectedClient cl = it.next() ;
cl.incTimeout() ;
+ dead = false ;
- if( cl.getTimeout() > max_timeout )
+ if( cl.getTimeout() > max_timeout || cl.getFail() )
{
- System.out.println( "Disconnection of " + cl.getName() ) ;
- if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
+ dead = true ;
+ if( ! cl.getFail() )
{
- System.out.println( "A VM was running on it!!" ) ;
- System.out.println( "I will redeploy a save and restart all VM ..." ) ;
+ try {
+ cl.getStub().echo() ;
+ cl.resetTimeout() ;
+ dead = false ;
+ } catch( RemoteException e ) {
+ dead = true ;
+ }
+ }
+
+ if( dead )
+ {
+ System.out.println( "Disconnection of " + cl.getName() ) ;
+ if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
+ {
+ System.out.println( "A VM was running on it!!" ) ;
+ System.out.println( "I will redeploy a save and restart all VM ..." ) ;
-// for( int i = 0 ; i < computingClients.size() ; i++ )
-// {
-// if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
+// for( int i = 0 ; i < computingClients.size() ; i++ )
// {
-// computingClients.remove( i ) ;
-// break ;
+// if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
+// {
+// computingClients.remove( i ) ;
+// break ;
+// }
// }
-// }
- synchronized( counter ){
- counter.inc() ;}
+ synchronized( counter )
+ {
+ counter.inc() ;
+ }
-
- new Server.FaultManager( cl ).start() ;
- nb_disconnections_computing++ ;
- } else {
- System.out.println( "There was no VM running on it." ) ;
- System.out.println( "Maybe it will come back later :)" ) ;
- }
+ new Server.FaultManager( cl ).start() ;
+ nb_disconnections_computing++ ;
+ } else {
+ System.out.println( "There was no VM running on it." ) ;
+ System.out.println( "Maybe it will come back later :)" ) ;
+ }
- synchronized( clients )
- {
- it.remove() ;
+ synchronized( clients )
+ {
+ it.remove() ;
+ }
+ nb_disconnections++ ;
+ change = true ;
}
- nb_disconnections++ ;
- change = true ;
}
}
} catch( RemoteException e ) {
System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ;
e.printStackTrace() ;
+ yield() ;
}
}
}
counter.wait() ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
+ yield() ;
}
}
}
for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
{
- final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
-
applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
- new Thread( new Runnable() {
-
- @Override
- public void run()
- {
- try {
- sc.restartVMAfterCrash() ;
- } catch( RemoteException e ) {
- e.printStackTrace() ;
- }
- }
- } ).start() ;
+ new RestartVM( applications.get( ind ).getComputingClients().get( i ).getClient() ).start() ;
+
+// final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
+
+// new Thread( new Runnable() {
+//
+// @Override
+// public void run()
+// {
+// try {
+// if( sc.restartVMAfterCrash() != 0 )
+// {
+// System.err.println( "Problem while restarting VM on " +sc.getName() + "!" ) ;
+// }
+// } catch( RemoteException e ) {
+// try {
+// System.err.println( "Problem while restarting VM on " + sc.getName() + "!" ) ;
+// } catch( RemoteException e1 ) {
+// System.err.println( "Problem while restarting a VM!" ) ;
+// e1.printStackTrace() ;
+// }
+// e.printStackTrace() ;
+// yield() ;
+// }
+// }
+// } ).start() ;
}
}
Thread.sleep( 2000 ) ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
+ yield() ;
}
}
}
try {
computingClients.get( i ).getClient().getStub().saveOk() ;
} catch (RemoteException e) {
- e.printStackTrace();
+ System.err.println( "Unable to invoke the saveOk method on " + computingClients.get( i ).getClient().getName() ) ;
+ e.printStackTrace() ;
}
computingClients.get( i ).setSaveStatus( false ) ;
}
if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
{
computingClients.get( i ).setLastSave( _saveName ) ;
- System.out.println( "Save name successfully changed on " + _ip ) ;
+ System.out.println( "Save name successfully changed on " + computingClients.get( i ).getClient().getName() ) ;
return 0 ;
}
}
+
+ System.err.println( "Unable to found computing client with IP " + _ip + "!" ) ;
+ return 1 ;
}
+ System.err.println( "Unable to change save name. IP or save name empty ! (IP: " + _ip + " ; save name: " + _saveName +")" ) ;
+
return 1 ;
}
+
@Override
public ArrayList<ServicesClient> startApplication( int _nb )
{
try {
startingClients.wait() ;
- } catch (InterruptedException e) {
- e.printStackTrace();
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
}
}
}
final int indice = i ;
- new Thread( new Runnable(){
-
+ new Thread( new Runnable()
+ {
@Override
public void run()
{
try {
res = clients.get( indice ).getStub().startVM( 0 ) ;
} catch( RemoteException e ) {
- e.printStackTrace();
+ e.printStackTrace() ;
}
if( res == 0 )
{
app.setComputingClients( tmp ) ;
app.setRunning( true ) ;
-// app.setStartTime( System.currentTimeMillis() ) ;
+ app.setStartTime( System.currentTimeMillis() ) ;
int index, index2 ;
/* Choosing save neighbors */
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 )
+// if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
{
// Has it already finished?
for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
}
}
- // Is every body ok?
+ // Is everybody ok?
boolean ok = false ;
for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
{
public void goApplication()
{
synchronized( applications ) {
- if( running && applications.get( ind ).getStartTime() != 0 )
- {
- applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
- applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
- }}
+ 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() ) ;
+ }
+ }
}
{
synchronized( applications )
{
- if( running )
- {
- Iterator<ComputingClient> it = computingClients.iterator() ;
-
- while( it.hasNext() )
+ if( running )
{
- ComputingClient cl = it.next() ;
+ applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
+ applications.get( ind ).setRunning( false ) ;
+ applications.get( ind ).clear() ;
+
+ Iterator<ComputingClient> it = computingClients.iterator() ;
+
+ while( it.hasNext() )
+ {
+ ComputingClient cl = it.next() ;
- try {
- cl.getClient().getStub().emergencyStop() ;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ try {
+ cl.getClient().getStub().emergencyStop() ;
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
- cl.getClient().setStatus( "connected" ) ;
- cl.getClient().setComputingClient( null ) ;
- it.remove() ;
- cl = null ;
- }
+ cl.getClient().setStatus( "connected" ) ;
+ cl.getClient().setComputingClient( null ) ;
+ it.remove() ;
+ cl = null ;
+ }
- applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
- applications.get( ind ).setRunning( false ) ;
- applications.get( ind ).clear() ;
-// applications.remove( ind ) ;
- running = false ;
+ applications.get( ind ).clear() ;
+
+ running = false ;
- System.out.println( "Application " + applications.get( ind ).getName() + " ends in " +
+ System.out.println( "Application " + applications.get( ind ).getName() + " ends in " +
applications.get( ind ).getExecutionTime() + " seconds." ) ;
- }}
+ }
+ }
}
protected int getNb() { return nb ; }
}
+
+ private class RestartVM extends Thread
+ {
+ private ConnectedClient cc ;
+
+ protected RestartVM( ConnectedClient _cc )
+ {
+ cc = _cc ;
+ }
+
+ public void run()
+ {
+ boolean error = false ;
+ if( cc != null )
+ {
+ try {
+ if( cc.getStub().restartVMAfterCrash() != 0 )
+ {
+ System.err.println( "Problem while restarting VM on " + cc.getName() + "!" ) ;
+ error = true ;
+ }
+ } catch( RemoteException e ) {
+ e.printStackTrace() ;
+ error = true ;
+ yield() ;
+ }
+ } else {
+ System.err.println( "The client to restart is null!" ) ;
+ }
+
+ if( error )
+ {
+ cc.setFail( true ) ;
+
+ try {
+ System.out.print( "Trying to stop the client ... " ) ;
+ cc.getStub().stop() ;
+ System.out.println( "successful client stop." );
+ } catch( RemoteException e ) {
+ System.out.println( "unsuccessful client stop!" ) ;
+ e.printStackTrace() ;
+ }
+ }
+ }
+ }
+
}
/** La programmation est un art, respectons ceux qui la pratiquent !! **/