adding a safeguard shutdown bundle that would leave SIP Communicator 15 seconds to die and, if this doesn't happen, kill it itself

cusax-fix
Emil Ivov 19 years ago
parent e66065f01d
commit c6fbd8b8bf

@ -1063,4 +1063,14 @@ javax.swing.event, javax.swing.border"/>
prefix="net/java/sip/communicator/slick/version"/>
</jar>
</target>
<!-- BUNDLE-SHUTDOWN -->
<target name="bundle-shutdown">
<!-- Creates a bundle for the shutdown plugin.-->
<jar compress="false" destfile="${bundles.dest}/shutdown.jar"
manifest="src/net/java/sip/communicator/slick/shutdown/shutdown.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/impl/shutdown"
prefix="net/java/sip/communicator/impl/shutdown"/>
</jar>
</target>
</project>

@ -78,6 +78,7 @@ felix.auto.start.4= \
reference:file:sc-bundles/sipaccregwizz.jar \
reference:file:sc-bundles/jabberaccregwizz.jar \
reference:file:sc-bundles/msnaccregwizz.jar
reference:file:sc-bundles/shutdown.jar
# Uncomment the following lines if you want to run the architect viewer
# bundle.

@ -0,0 +1,81 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.shutdown;
import org.osgi.framework.*;
import net.java.sip.communicator.util.*;
/**
* In order to shut down SIP Communicator we kill the Felix system bundle.
* However, this sometimes doesn't work for reason of running non-daemon
* threads (such as the javasound event dispatcher). This results in having
* instances of SIP Communicator running in the background.
*
* We use this shutdown timout bundle in order to fix this problem. When our
* stop method is called, we assume that a shutdown is executed and start a 15
* seconds daemon thread. If the application is still running once these 15
* seconds expire, we System.exit() the application.
*
* @author Emil Ivov
*/
public class ShutdownTimeout
implements BundleActivator
{
private static final Logger logger
= Logger.getLogger(ShutdownTimeout.class);
/**
* The number of miliseconds that we wait before we force a shutdown.
*/
public static final long SHUTDOWN_TIMEOUT = 15000;//ms
/**
* The code that we exit with if the application is not down in 15 seconds.
*/
public static final int SYSTEM_EXIT_CODE = 500;
/**
* Dummy impl of the bundle activator start method.
*
* @param context unused
*/
public void start(BundleContext context)
throws Exception
{}
/**
* Called when this bundle is stopped so the Framework can perform the
* bundle-specific activities necessary to stop the bundle.
*
* @param context The execution context of the bundle being stopped.
* @throws Exception If this method throws an exception, the bundle is
* still marked as stopped, and the Framework will remove the bundle's
* listeners, unregister all services registered by the bundle, and
* release all services used by the bundle.
*/
public void stop(BundleContext context)
throws Exception
{
Thread shutdownTimeoutThread = new Thread()
{
public void run()
{
synchronized(this)
{
try{
wait(SHUTDOWN_TIMEOUT);
logger.error("Failed to gently shutdown. Forcing exit.");
System.exit(500);
}catch (InterruptedException ex){}
}
}
};
shutdownTimeoutThread.setDaemon(true);
shutdownTimeoutThread.start();
}
}

@ -0,0 +1,9 @@
Bundle-Activator: net.java.sip.communicator.impl.shutdown.ShutdownTimeout
Bundle-Name: ShutdownBundle
Bundle-Description: A bundle that makes sure that when closed SIP Communicator will exit in 15 seconds at most.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.configuration,
net.java.sip.communicator.service.configuration.event,
net.java.sip.communicator.util
Loading…
Cancel
Save