You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by an...@apache.org on 2010/12/19 20:22:22 UTC

svn commit: r1050938 - in /karaf/branches/karaf-2.1.x: main/src/main/java/org/apache/karaf/main/Main.java main/src/main/java/org/apache/karaf/main/ShutdownCallback.java shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java

Author: anierbeck
Date: Sun Dec 19 19:22:22 2010
New Revision: 1050938

URL: http://svn.apache.org/viewvc?rev=1050938&view=rev
Log:
[KARAF-327] - The Main stop method now calls a call-back to signal the Wrapper that the JVM is still alive, giving the framework time for a graceful shutdown. 

Added:
    karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java   (with props)
Modified:
    karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java
    karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java

Modified: karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java?rev=1050938&r1=1050937&r2=1050938&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java (original)
+++ karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java Sun Dec 19 19:22:22 2010
@@ -249,14 +249,29 @@ public class Main {
     }
 
     public void destroy(boolean await) throws Exception {
+		destroy(await, 0, null);
+	}
+
+	public void destroy(boolean await, int timeout, ShutdownCallback callback) throws Exception {
         if (framework == null) {
             return;
         }
         try {
             if (await) {
                 while (true) {
-                    FrameworkEvent event = framework.waitForStop(0);
-                    if (event.getType() != FrameworkEvent.STOPPED_UPDATE) {
+                	FrameworkEvent event;
+	                if (callback != null) {
+	                	callback.waitingForShutdown();
+	                	framework.stop();
+	                	do {
+	                		callback.waitingForShutdown();
+	                		event = framework.waitForStop(timeout);
+	                	} while(event.getType() == FrameworkEvent.WAIT_TIMEDOUT);
+	                	break;
+                	} else {
+                		event = framework.waitForStop(0);
+                	}
+                	if (event.getType() != FrameworkEvent.STOPPED_UPDATE) {
                         break;
                     }
                 }

Added: karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java?rev=1050938&view=auto
==============================================================================
--- karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java (added)
+++ karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java Sun Dec 19 19:22:22 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.karaf.main;
+
+
+/**
+ * <p>
+ * This interface is a callback interface for the stoping process. 
+ * It's main purpose is to give the ServiceWrapper a way of waiting 
+ * for the Framework to gracefully stop the Server. 
+ * <p>
+ */
+public interface ShutdownCallback {
+
+	/**
+	 * The callback method invoked to inform anyone listening that the 
+	 * Main class is still waiting for the completion of the shutdown. 
+	 */
+	void waitingForShutdown();
+	
+}

Propchange: karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/ShutdownCallback.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java?rev=1050938&r1=1050937&r2=1050938&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java (original)
+++ karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java Sun Dec 19 19:22:22 2010
@@ -16,15 +16,18 @@
  */
 package org.apache.karaf.shell.wrapper;
 
+import org.apache.karaf.main.ShutdownCallback;
 import org.tanukisoftware.wrapper.WrapperListener;
 import org.tanukisoftware.wrapper.WrapperManager;
 
 /**
  * Java Service Wrapper Main class
  */
-public class Main implements WrapperListener {
+public class Main implements WrapperListener, ShutdownCallback {
 
-    private org.apache.karaf.main.Main main;
+    private static final int TIMEOUT = 1000; //wainting timeout for a second should be enough
+	private static final int TIMEOUT_OFFSET = 500; // the offset for the wrapper, to leave us some time to breath
+	private org.apache.karaf.main.Main main;
 
     /*---------------------------------------------------------------
      * Constructors
@@ -85,7 +88,7 @@ public class Main implements WrapperList
     {
         try
         {
-            main.destroy(false);
+            main.destroy(true, TIMEOUT, this);
         }
         catch (Throwable ex)
         {
@@ -96,6 +99,14 @@ public class Main implements WrapperList
 
         return exitCode;
     }
+    
+    /**
+     * Call-back method is called by the @{link org.apache.karaf.main.Main} for Signaling 
+     * that the stopping process is in progress and the wrapper doesn't kill the JVM.  
+     */
+    public void waitingForShutdown() {
+    	WrapperManager.signalStopping(TIMEOUT + TIMEOUT_OFFSET);
+    }
 
     /**
      * Called whenever the native Wrapper code traps a system control signal