You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/08/31 02:22:04 UTC
svn commit: r438724 - in
/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix:
Main.java jbi/container/JBIContainer.java jbi/nmr/flow/jca/JCAFlow.java
Author: gnodet
Date: Wed Aug 30 17:22:04 2006
New Revision: 438724
URL: http://svn.apache.org/viewvc?rev=438724&view=rev
Log:
Add a shutdown hook.
Add logs on the JBIContainer lifecycle
Reduce log on JCA flow
Modified:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/Main.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/Main.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/Main.java?rev=438724&r1=438723&r2=438724&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/Main.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/Main.java Wed Aug 30 17:22:04 2006
@@ -43,7 +43,7 @@
if (p != null) {
version = ": " + p.getImplementationVersion();
}
- System.out.println("Apache ServiceMix ESB" + version);
+ System.out.println("Starting Apache ServiceMix ESB" + version);
System.out.println();
ApplicationContext context = null;
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java?rev=438724&r1=438723&r2=438724&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java Wed Aug 30 17:22:04 2006
@@ -117,6 +117,8 @@
protected boolean notifyStatistics = false;
protected EventListenerList listeners = new EventListenerList();
protected EventListener[] configuredListeners;
+ protected boolean useShutdownHook = true;
+ protected transient Thread shutdownHook;
/**
* Default Constructor
@@ -187,16 +189,16 @@
* @return the subscriptionFlowName
*/
public String getSubscriptionFlowName() {
- return getDefaultBroker().getSubscriptionFlowName();
- }
+ return getDefaultBroker().getSubscriptionFlowName();
+ }
/**
* Set the subscription flow name
* @param subscriptionFlowName
*/
- public void setSubscriptionFlowName(String subscriptionFlowName) {
+ public void setSubscriptionFlowName(String subscriptionFlowName) {
getDefaultBroker().setSubscriptionFlowName(subscriptionFlowName);
- }
+ }
/**
* Set the broker message flow
@@ -237,6 +239,19 @@
return getDefaultBroker().getFlows();
}
+ public boolean isUseShutdownHook() {
+ return useShutdownHook;
+ }
+
+ /**
+ * Sets whether or not we should use a shutdown handler to close down the
+ * broker cleanly if the JVM is terminated. It is recommended you leave this
+ * enabled.
+ */
+ public void setUseShutdownHook(boolean useShutdownHook) {
+ this.useShutdownHook = useShutdownHook;
+ }
+
/**
* Get the ManagementContext
*
@@ -497,6 +512,11 @@
*/
public void init() throws JBIException {
if (containerInitialized.compareAndSet(false, true)) {
+ log.info("ServiceMix " +
+ EnvironmentContext.getVersion() +
+ " JBI Container (" + getName() + ") is starting");
+ log.info("For help or more informations please see: http://incubator.apache.org/servicemix/");
+ addShutdownHook();
if (this.workManager == null) {
this.workManager = createWorkManager();
this.isWorkManagerCreated = true;
@@ -541,9 +561,6 @@
addListener(listener);
}
}
-
- log.info("ServiceMix JBI Container (http://servicemix.org/) name: " + getName() + " running version: "
- + EnvironmentContext.getVersion());
}
}
@@ -565,6 +582,7 @@
autoDeployService.start();
adminCommandsService.start();
super.start();
+ log.info("ServiceMix JBI Container (" + getName() + ") started");
}
}
@@ -576,6 +594,7 @@
public void stop() throws JBIException {
checkInitialized();
if (started.compareAndSet(true, false)) {
+ log.info("ServiceMix JBI Container (" + getName() + ") stopping");
adminCommandsService.stop();
autoDeployService.stop();
deploymentService.stop();
@@ -596,6 +615,7 @@
*/
public void shutDown() throws JBIException {
if (containerInitialized.compareAndSet(true, false)) {
+ removeShutdownHook();
adminCommandsService.shutDown();
autoDeployService.shutDown();
deploymentService.shutDown();
@@ -615,10 +635,45 @@
throw new JBIException("Could not stop workManager", e);
}
}
+ log.info("ServiceMix JBI Container (" + getName() + ") stopped");
}
}
+ protected void addShutdownHook() {
+ if (useShutdownHook) {
+ shutdownHook = new Thread("ServiceMix ShutdownHook") {
+ public void run() {
+ containerShutdown();
+ }
+ };
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ }
+
+ protected void removeShutdownHook() {
+ if (shutdownHook != null) {
+ try {
+ Runtime.getRuntime().removeShutdownHook(shutdownHook);
+ }
+ catch (Exception e) {
+ log.debug("Caught exception, must be shutting down: " + e);
+ }
+ }
+ }
+
+ /**
+ * Causes a clean shutdown of the container when the VM is being shut down
+ */
+ protected void containerShutdown() {
+ try {
+ stop();
+ shutDown();
+ }
+ catch (Exception e) {
+ System.err.println("Failed to shut down: " + e);
+ }
+ }
/**
* @return theMBean server assocated with the JBI
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java?rev=438724&r1=438723&r2=438724&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/jca/JCAFlow.java Wed Aug 30 17:22:04 2006
@@ -502,12 +502,12 @@
}
public void onRemoteEndpointRegistered(EndpointEvent event) {
- log.info(broker.getContainer().getName() + ": adding remote endpoint: " + event.getEndpoint());
+ log.debug(broker.getContainer().getName() + ": adding remote endpoint: " + event.getEndpoint());
broker.getContainer().getRegistry().registerRemoteEndpoint(event.getEndpoint());
}
public void onRemoteEndpointUnregistered(EndpointEvent event) {
- log.info(broker.getContainer().getName() + ": removing remote endpoint: " + event.getEndpoint());
+ log.debug(broker.getContainer().getName() + ": removing remote endpoint: " + event.getEndpoint());
broker.getContainer().getRegistry().unregisterRemoteEndpoint(event.getEndpoint());
}
@@ -710,4 +710,4 @@
}
}
-}
\ No newline at end of file
+}