} catch( Exception e ) {}
}
- stopVM() ;
+ stopVM( 1 ) ;
}
if( ! ret )
{
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} else {
retry++ ;
System.err.println( "Unable to check VM!" ) ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
System.out.println( "Retrying (" + retry + ") ... " ) ;
} catch( IOException e ) {
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} else {
} catch( IOException e1 ) {
e1.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
if( ! ret )
{
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} else {
retry++ ;
System.err.println( "Unable to send information to VM!" ) ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
System.err.println( "Error during execution of runScriptInGuest command: " ) ;
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} catch( InterruptedException e) {
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
}
} catch( IOException e1 ) {
e1.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
if( ! ret )
{
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} else {
retry++ ;
System.err.println( "Unable to send information to VM!" ) ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
System.err.println( "Error during execution of runScriptInGuest command: " ) ;
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
sema.release() ;
- stopVM() ;
+ stopVM( 1 ) ;
return 1 ;
}
}
@Override
- public int stopVM()
+ public int stopVM( int _mode )
{
if( machine != null && machine.getStatus().equalsIgnoreCase( "stopped" ) )
{
int retry = 0 ;
machine.setStatus( "undefined" ) ;
+ if( _mode == 0 )
try {
LocalHost.Instance().getServerStub().changeStatus(
LocalHost.Instance().getIP(), "undefined" ) ;
}
machine.setStatus( "stopped" ) ;
+ if( _mode == 0 )
try {
LocalHost.Instance().getServerStub().changeStatus(
LocalHost.Instance().getIP(), "stopped" ) ;
e.printStackTrace() ;
}
- if( stopVM() == 0 )
+ if( stopVM( 1 ) == 0 )
{
if( machine.deployLastSave() == 0 )
{
return 0 ;
}
} else {
- stopVM() ;
+ stopVM( 1 ) ;
}
}
}
if( ! lastSaveOk )
{
-// String arch1 = "", arch2 = "" ;
-// File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ) ;
-// if( file.exists() )
-// {
-// arch1 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ;
-// }
-//
-// file = null ;
-//
String arch = "" ;
File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
if( file.exists() )
e.printStackTrace() ;
error = true ;
}
-
-// /** Compression of the archive **/
-// if( ! error )
-// {
-// System.out.print( "Compression of the archive ... " ) ;
-// command = new String[]{ "/bin/gzip",
-// working_directory + "/" + machine.getName()
-// + "_new_" + machine.getComputationId() + ".tar" } ;
-//
-// if( emergencyStop )
-// {
-// return 1 ;
-// }
-//
-// try {
-// procSave = Runtime.getRuntime().exec( command ) ;
-// procSave.waitFor() ;
-//
-// if( procSave.exitValue() == 0 )
-// {
-// System.out.println( "Archive successfully compressed." ) ;
-// } else {
-// System.err.println( "Archive not compressed!" ) ;
-// printProcessError( procSave ) ;
-//
-// error = true ;
-// }
-// } catch( IOException e ) {
-// System.err.println( "Error during archive compression command: " ) ;
-// e.printStackTrace() ;
-// error = true ;
-// } catch( InterruptedException e ) {
-// e.printStackTrace() ;
-// error = true ;
-// }
-// }
long fin = System.currentTimeMillis() ;
while( (line = br.readLine()) != null )
{
System.err.println( line ) ;
- if( line.contains( "egmentation" ) )
+ if( line.contains( "egmentation" ) || _p.exitValue() == 139 )
{
ret = true ;
}
return ret ;
}
+
+ @Override
+ public int echo()
+ {
+ return 0 ;
+ }
+
@Override
public int start()
} catch( RemoteException e1 ) {
System.err.println( "Unable to ping the server!" ) ;
e1.printStackTrace() ;
+ yield() ;
}
try {
sleep( 2000 ) ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
+ yield() ;
}
}
}
if( serverSocket != null )
{
try {
- serverSocket.close() ;
-
-// for( int i = 0 ; i < dialogs.size() ; i++ )
-// {
-// dialogs.get( i ).stopDialogVM() ;
-// }
-
+ serverSocket.close() ;
} catch( IOException e ) {
e.printStackTrace() ;
+ yield() ;
}
}
}
} catch( IOException e ) {
System.err.println( "Unable to launch the SocketServer on port " + dialog_port + "!" ) ;
e.printStackTrace() ;
-
- go = false ;
+ System.exit( 1 ) ;
}
while( go )
socket = serverSocket.accept() ;
new DialogVM( socket ).start() ;
-// dialogs.add( new DialogVM( socket ) ) ;
-// dialogs.get( dialogs.size() - 1 ).start() ;
+
} catch( IOException e ) {
System.err.println( "Problem with the accept function!" ) ;
e.printStackTrace() ;
+ yield() ;
}
}
}
private class DialogVM extends Thread
{
- protected boolean go ;
private Socket socket ;
private BufferedReader reader ;
private String line ;
- DialogVM( Socket _socket ) { go = true ; socket = _socket ; }
-
- protected void stopDialogVM()
- {
- go = false ;
-
- try {
- reader.close() ; reader = null ;
- socket.close() ; socket = null ;
- } catch( IOException e ) {
- e.printStackTrace() ;
- }
- }
+ DialogVM( Socket _socket ) { socket = _socket ; }
@Override
public void run()
reader = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ) ;
} catch( IOException e ) {
System.err.println( "Unable to open a dialog socket with the VM!" ) ;
- e.printStackTrace();
- stopDialogVM() ;
+ e.printStackTrace() ;
+ yield() ;
}
-
-// while( go )
- {
- try {
- line = null ;
-
- if( reader != null )
+
+ try {
+ line = null ;
+
+ if( reader != null )
+ {
+ line = reader.readLine() ;
+ }
+
+ /** VM is starting -- retrieving informations **/
+ if( line != null && line.equalsIgnoreCase( "infos" ) )
+ {
+ /* Receiving name */
+ machine.setName( reader.readLine() ) ;
+
+ /* Receiving IP */
+ String ip = reader.readLine() ;
+ if( ! ip.equalsIgnoreCase( machine.getIp() ) )
{
- line = reader.readLine() ;
+ System.err.println( "VM IP not well configured!!" ) ;
}
-
- /** VM is starting -- retrieving informations **/
- if( go && line != null && line.equalsIgnoreCase( "infos" ) )
- {
- /* Receiving name */
- machine.setName( reader.readLine() ) ;
-
- /* Receiving IP */
- String ip = reader.readLine() ;
- if( ! ip.equalsIgnoreCase( machine.getIp() ) )
- {
- System.err.println( "VM IP not well configured!!" ) ;
- }
-
- /* Close streams */
- reader.close() ; reader = null ;
- socket.close() ; socket = null ;
-
- go = false ;
- }
-
+
+ /* Close streams */
+ reader.close() ; reader = null ;
+ socket.close() ; socket = null ;
+
+ } else if( line != null && line.equalsIgnoreCase( "save" ) ) {
/** It's time to do a save **/
- if( go && line != null && line.equalsIgnoreCase( "save" ) )
- {
+
+ try {
+ machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
+ } catch( Exception e ) {
+ System.err.println( "Problem while reading the computation id!" ) ;
+ e.printStackTrace() ;
+ }
+
+ synchronized( saveRequest )
+ {
try {
- machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
- } catch( Exception e ) {
- System.err.println( "Problem while reading the computation id!" ) ;
+ LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to request save to server!" ) ;
e.printStackTrace() ;
}
-
- synchronized( saveRequest )
- {
- try {
- LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ;
- } catch( RemoteException e ) {
- System.err.println( "Unable to request save to server!" ) ;
- e.printStackTrace() ;
- }
-
- try {
- saveRequest.wait() ;
- } catch( InterruptedException e ) {
- e.printStackTrace();
- }
- }
-
- if( saveRequest.getStatus() )
- {
- /* Close streams */
- reader.close() ; reader = null ;
- socket.close() ; socket = null ;
-
- go = false ;
-
- saveRequest.setStatus( false ) ;
-
- /* Requesting the VM save */
- saveVM() ;
- } else {
- sendSaveOkVM() ;
- }
- }
-
-
- /** Computation is done, we can shutdown the VM **/
- if( go && line != null && line.equalsIgnoreCase( "quit" ) )
- {
+
try {
- Thread.sleep( 5000 ) ;
+ saveRequest.wait() ;
} catch( InterruptedException e ) {
- e.printStackTrace() ;
+ e.printStackTrace();
}
-
+ }
+
+ if( saveRequest.getStatus() )
+ {
/* Close streams */
reader.close() ; reader = null ;
socket.close() ; socket = null ;
-
- go = false ;
-
- stopVM() ;
+
+ saveRequest.setStatus( false ) ;
+
+ /* Requesting the VM save */
+ if( saveVM() == 1 )
+ {
+ System.err.println( "Problem while saving. Exiting ..." ) ;
+ pingServer.stopPing() ;
+ emergencyStop() ;
+ System.exit( 1 ) ;
+ }
+ } else {
+ sendSaveOkVM() ;
+ }
+ } else if( line != null && line.equalsIgnoreCase( "quit" ) ) {
+ /** Computation is done, we can shutdown the VM **/
+
+ try {
+ Thread.sleep( 5000 ) ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ }
+
+ /* Close streams */
+ reader.close() ; reader = null ;
+ socket.close() ; socket = null ;
+
+ stopVM( 0 ) ;
+
+ machine.setStatus( "connected" ) ;
+ try {
+ LocalHost.Instance().getServerStub().changeStatus(
+ LocalHost.Instance().getIP(), "connected" ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to inform the server of the VM status!" ) ;
+ e.printStackTrace() ;
}
- } catch( IOException e ) {
- go = false ;
- e.printStackTrace() ;
+ try {
+ LocalHost.Instance().getServerStub().endApplication() ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to inform the server of the end of application!" ) ;
+ e.printStackTrace() ;
+ }
+ } else if( line != null && line.equalsIgnoreCase( "start" ) ) {
+ /** Computation is starting **/
+
+ /* Close streams */
+ reader.close() ; reader = null ;
+ socket.close() ; socket = null ;
+ System.out.println( "Application is starting." ) ;
+
+ try {
+ LocalHost.Instance().getServerStub().goApplication() ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to inform the server of the end of application!" ) ;
+ e.printStackTrace() ;
+ }
}
+
+ } catch( IOException e ) {
+ e.printStackTrace() ;
+ yield() ;
}
}
}
@Override
public void stop()
{
- stopVM() ;
+ stopVM( 0 ) ;
pingServer.stopPing() ;