From 7a473b4f506b5264586f090f34b21fe11531bb70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Miqu=C3=A9e?= Date: Mon, 8 Aug 2011 23:28:04 +0200 Subject: [PATCH] Correction and modification of save mechanisms. --- src/and/hpcvm/Client.java | 44 ++++++++++++++++--------------- src/and/hpcvm/HpcVm.java | 12 +++++++++ src/and/hpcvm/Server.java | 7 ++++- src/and/hpcvm/ServicesClient.java | 2 +- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index e3233eb..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 ) ; } } } @@ -1509,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 { @@ -1552,7 +1554,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override public void stop() { - stopVM() ; + stopVM( 0 ) ; pingServer.stopPing() ; diff --git a/src/and/hpcvm/HpcVm.java b/src/and/hpcvm/HpcVm.java index 98994b7..7551966 100644 --- a/src/and/hpcvm/HpcVm.java +++ b/src/and/hpcvm/HpcVm.java @@ -6,6 +6,7 @@ public class HpcVm private static String server_ip ; private static int server_port ; private static int dialog_port ; + private static int save_time ; // private static int mode ; // 0: server, 1: client private static Client client ; private static Server server ; @@ -19,6 +20,7 @@ public class HpcVm server_ip = "127.0.0.1" ; server_port = 2666 ; dialog_port = 7788 ; + save_time = -1 ; // mode = -1 ; @@ -60,11 +62,21 @@ public class HpcVm server_port = Integer.parseInt( argv[1] ) ; } + if( argv.length == 3 ) + { + server_port = Integer.parseInt( argv[1] ) ; + save_time = Integer.parseInt( argv[2] ) ; + } + try { // mode = 0 ; server = new Server() ; server.init( server_port ) ; + if( save_time != -1 ) + { + server.setSaveTime( save_time ) ; + } } catch( Exception e ) { System.err.println( "Error while launching Server: " + e ) ; } diff --git a/src/and/hpcvm/Server.java b/src/and/hpcvm/Server.java index 390d580..90a8653 100644 --- a/src/and/hpcvm/Server.java +++ b/src/and/hpcvm/Server.java @@ -94,7 +94,12 @@ public class Server extends UnicastRemoteObject implements ServicesServer super() ; } - + + public void setSaveTime( int _saveTime ) + { + save_interleave = _saveTime * 60 * 1000 ; + } + @Override public Integer register( ServicesClient _stub ) diff --git a/src/and/hpcvm/ServicesClient.java b/src/and/hpcvm/ServicesClient.java index 438af96..09ad97e 100644 --- a/src/and/hpcvm/ServicesClient.java +++ b/src/and/hpcvm/ServicesClient.java @@ -12,7 +12,7 @@ public interface ServicesClient extends Remote public int startVM( int _mode ) throws RemoteException ; - public int stopVM() throws RemoteException ; + public int stopVM( int _mode ) throws RemoteException ; public int suspendVM( int _mode ) throws RemoteException ; -- 2.20.1