You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/03/11 04:04:42 UTC

git commit: support forced shutdown etc.

Repository: airavata
Updated Branches:
  refs/heads/master e5901e8e8 -> 29e122151


support forced shutdown etc.


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/29e12215
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/29e12215
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/29e12215

Branch: refs/heads/master
Commit: 29e122151df1f416fdbec56e01a8312edf69dd2e
Parents: e5901e8
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Mon Mar 10 23:04:07 2014 -0400
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Mon Mar 10 23:04:07 2014 -0400

----------------------------------------------------------------------
 .../org/apache/airavata/server/ServerMain.java  | 24 ++++++++++++++------
 1 file changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/29e12215/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
index 9e1b1f8..41d2f16 100644
--- a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
+++ b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
@@ -47,6 +47,7 @@ public class ServerMain {
 	private static int serverIndex=-1;
 	private static final String serverStartedFileNamePrefix = "airavata-server-start";
 	private static boolean forcedStop=false; 
+	private static boolean systemShutDown=false;
     static{
 		servers = new ArrayList<IServer>();
     }
@@ -81,6 +82,7 @@ public class ServerMain {
 		serversLoaded=true;
 		Runtime.getRuntime().addShutdownHook(new Thread() {
 			public void run() {
+				setSystemShutDown(true);
 				stopAllServers();
 			}
 		});
@@ -156,7 +158,7 @@ public class ServerMain {
 	
 	private static boolean hasStopRequested(){
 		forcedStop=new File(getServerStopForceFileName()).exists() || new File(stopFileNamePrefixForced).exists();
-		return  forcedStop || new File(getServerStopFileName()).exists() || new File(stopFileNamePrefix).exists(); 
+		return  isSystemShutDown() || forcedStop || new File(getServerStopFileName()).exists() || new File(stopFileNamePrefix).exists(); 
 	}
 
 	private static String getServerStopFileName() {
@@ -236,11 +238,11 @@ public class ServerMain {
 	}
 	private static final int SERVER_STATUS_CHANGE_WAIT_INTERVAL=100;
 
-	public static void waitForServerToStart(IServer server,Integer maxWait) throws Exception {
+	private static void waitForServerToStart(IServer server,Integer maxWait) throws Exception {
 		int count=0;
-		if (server.getStatus()==ServerStatus.STARTING) {
-			logger.info("Waiting for " + server.getName() + " to start...");
-		}
+//		if (server.getStatus()==ServerStatus.STARTING) {
+//			logger.info("Waiting for " + server.getName() + " to start...");
+//		}
 		while(server.getStatus()==ServerStatus.STARTING && (maxWait==null || count<maxWait)){
 			Thread.sleep(SERVER_STATUS_CHANGE_WAIT_INTERVAL);
 			count+=SERVER_STATUS_CHANGE_WAIT_INTERVAL;
@@ -250,13 +252,13 @@ public class ServerMain {
 		}
 	}
 
-	public static void waitForServerToStop(IServer server,Integer maxWait) throws Exception {
+	private static void waitForServerToStop(IServer server,Integer maxWait) throws Exception {
 		int count=0;
 		if (server.getStatus()==ServerStatus.STOPING) {
 			logger.info("Waiting for " + server.getName() + " to stop...");
 		}
 		//we are doing hasStopRequested() check because while we are stuck in the loop to stop there could be a forceStop request 
-		while(server.getStatus()==ServerStatus.STOPING && (maxWait==null || count<maxWait) && hasStopRequested() && !forcedStop){
+		while(server.getStatus()==ServerStatus.STOPING && (maxWait==null || count<maxWait) && hasStopRequested() && (maxWait!=null || !forcedStop)){
 			Thread.sleep(SERVER_STATUS_CHANGE_WAIT_INTERVAL);
 			count+=SERVER_STATUS_CHANGE_WAIT_INTERVAL;
 		}
@@ -264,4 +266,12 @@ public class ServerMain {
 			throw new Exception("Error stopping the "+server.getName()+"!!!");
 		}
 	}
+
+	private static boolean isSystemShutDown() {
+		return systemShutDown;
+	}
+
+	private static void setSystemShutDown(boolean systemShutDown) {
+		ServerMain.systemShutDown = systemShutDown;
+	}
 }
\ No newline at end of file