karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Achim Nierbeck <bcanh...@googlemail.com>
Subject Re: svn commit: r1055945 - /karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java
Date Thu, 06 Jan 2011 17:38:47 GMT
Hi,

are you sure we don't need the extra thread for the shutdown?
While testing with the camel example I used it did take a bit longer to
stop.
And it looks like the stop method doesn't return until the framework is
stopped.
Now if the shutdown takes to long the wrapper normaly just "kills" the
vm, doesn't it?

Achim


> Author: gnodet
> Date: Thu Jan  6 17:24:29 2011
> New Revision: 1055945
>
> URL: http://svn.apache.org/viewvc?rev=1055945&view=rev
> Log:
> [KARAF-327] - This should handle the stopping through the wrapper better.
>
> Modified:
>     karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/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=1055945&r1=1055944&r2=1055945&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 Thu
Jan  6 17:24:29 2011
> @@ -39,6 +39,7 @@ import java.util.regex.Pattern;
>  
>  import org.osgi.framework.Bundle;
>  import org.osgi.framework.BundleContext;
> +import org.osgi.framework.BundleException;
>  import org.osgi.framework.Constants;
>  import org.osgi.framework.FrameworkEvent;
>  import org.osgi.framework.ServiceReference;
> @@ -262,11 +263,25 @@ public class Main {
>                  	FrameworkEvent event;
>  	                if (callback != null) {
>  	                	callback.waitingForShutdown();
> -	                	framework.stop();
> -	                	do {
> +	                	event = framework.waitForStop(timeout);
> +	                	//do the stoping in an extra thread
> +	                	Runnable stopper = new Runnable() {
> +							
> +							public void run() {
> +								try {
> +									
> +									framework.stop();
> +								} catch (BundleException e) {
> +									System.err.println("Exception while stoping framework: " + e);
> +								}
> +							}
> +						};
> +	                	Thread t = new Thread(stopper);
> +	                	t.start();
> +	                	while (t.getState() != Thread.State.TERMINATED && event.getType()
== FrameworkEvent.WAIT_TIMEDOUT) {
>  	                		callback.waitingForShutdown();
>  	                		event = framework.waitForStop(timeout);
> -	                	} while(event.getType() == FrameworkEvent.WAIT_TIMEDOUT);
> +	                	} 
>  	                	break;
>                  	} else {
>                  		event = framework.waitForStop(0);
>
>


Mime
View raw message