X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/c2a0de69e20fda415c1ca6d90b04d2a4cf253acc..7a473b4f506b5264586f090f34b21fe11531bb70:/src/and/hpcvm/Client.java diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 06bb4e7..3153cb9 100644 --- a/src/and/hpcvm/Client.java +++ b/src/and/hpcvm/Client.java @@ -81,7 +81,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( Exception e ) {} } - stopVM() ; + stopVM( 1 ) ; } @@ -241,7 +241,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -250,7 +250,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to check VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } System.out.println( "Retrying (" + retry + ") ... " ) ; @@ -261,12 +261,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } catch( InterruptedException e ) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -283,7 +283,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { @@ -315,7 +315,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e1 ) { e1.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -346,7 +346,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -355,7 +355,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to send information to VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -367,12 +367,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient 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 ; } } @@ -396,7 +396,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e1 ) { e1.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -428,7 +428,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -437,7 +437,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to send information to VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -449,12 +449,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient 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 ; } } @@ -482,7 +482,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override - public int stopVM() + public int stopVM( int _mode ) { if( machine != null && machine.getStatus().equalsIgnoreCase( "stopped" ) ) { @@ -505,6 +505,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient int retry = 0 ; machine.setStatus( "undefined" ) ; + if( _mode == 0 ) try { LocalHost.Instance().getServerStub().changeStatus( LocalHost.Instance().getIP(), "undefined" ) ; @@ -560,6 +561,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } machine.setStatus( "stopped" ) ; + if( _mode == 0 ) try { LocalHost.Instance().getServerStub().changeStatus( LocalHost.Instance().getIP(), "stopped" ) ; @@ -761,7 +763,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient e.printStackTrace() ; } - if( stopVM() == 0 ) + if( stopVM( 1 ) == 0 ) { if( machine.deployLastSave() == 0 ) { @@ -819,7 +821,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient return 0 ; } } else { - stopVM() ; + stopVM( 1 ) ; } } } @@ -1245,7 +1247,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient while( (line = br.readLine()) != null ) { System.err.println( line ) ; - if( line.contains( "egmentation" ) ) + if( line.contains( "egmentation" ) || _p.exitValue() == 139 ) { ret = true ; } @@ -1258,6 +1260,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient return ret ; } + + @Override + public int echo() + { + return 0 ; + } + @Override public int start() @@ -1328,12 +1337,14 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( RemoteException e1 ) { System.err.println( "Unable to ping the server!" ) ; e1.printStackTrace() ; + yield() ; } try { sleep( 2000 ) ; } catch( InterruptedException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1361,6 +1372,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient serverSocket.close() ; } catch( IOException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1377,8 +1389,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { System.err.println( "Unable to launch the SocketServer on port " + dialog_port + "!" ) ; e.printStackTrace() ; - - go = false ; + System.exit( 1 ) ; } while( go ) @@ -1391,6 +1402,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { System.err.println( "Problem with the accept function!" ) ; e.printStackTrace() ; + yield() ; } } } @@ -1412,7 +1424,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient reader = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ) ; } catch( IOException e ) { System.err.println( "Unable to open a dialog socket with the VM!" ) ; - e.printStackTrace(); + e.printStackTrace() ; + yield() ; } try { @@ -1475,7 +1488,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient saveRequest.setStatus( false ) ; /* Requesting the VM save */ - saveVM() ; + if( saveVM() == 1 ) + { + System.err.println( "Problem while saving. Exiting ..." ) ; + pingServer.stopPing() ; + emergencyStop() ; + System.exit( 1 ) ; + } } else { sendSaveOkVM() ; } @@ -1492,7 +1511,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient reader.close() ; reader = null ; socket.close() ; socket = null ; - stopVM() ; + stopVM( 0 ) ; machine.setStatus( "connected" ) ; try { @@ -1515,6 +1534,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient /* Close streams */ reader.close() ; reader = null ; socket.close() ; socket = null ; + System.out.println( "Application is starting." ) ; try { LocalHost.Instance().getServerStub().goApplication() ; @@ -1526,6 +1546,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1533,7 +1554,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override public void stop() { - stopVM() ; + stopVM( 0 ) ; pingServer.stopPing() ;