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 2007/03/26 17:13:33 UTC
svn commit: r522539 - in
/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common:
AsyncBaseLifeCycle.java DefaultComponent.java Registry.java
Author: gnodet
Date: Mon Mar 26 08:13:32 2007
New Revision: 522539
URL: http://svn.apache.org/viewvc?view=rev&rev=522539
Log:
SM-896: Add a currentState on the component and ensure endpoints are correctly added / started at runtime
Modified:
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java
incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java
Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java?view=diff&rev=522539&r1=522538&r2=522539
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java (original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java Mon Mar 26 08:13:32 2007
@@ -22,6 +22,7 @@
import javax.jbi.JBIException;
import javax.jbi.component.ComponentContext;
import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.management.LifeCycleMBean;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
@@ -54,6 +55,8 @@
*/
public class AsyncBaseLifeCycle implements ComponentLifeCycle {
+ public static final String INITIALIZED = "Initialized";
+
protected transient Log logger;
protected ServiceMixComponent component;
@@ -81,6 +84,8 @@
protected Map processors;
protected ThreadLocal correlationId;
+
+ protected String currentState = LifeCycleMBean.UNKNOWN;
public AsyncBaseLifeCycle() {
this.running = new AtomicBoolean(false);
@@ -120,6 +125,46 @@
return null;
}
+ public String getCurrentState() {
+ return currentState;
+ }
+
+ protected void setCurrentState(String currentState) {
+ this.currentState = currentState;
+ }
+
+ public boolean isStarted(){
+ return currentState != null && currentState.equals(LifeCycleMBean.STARTED);
+ }
+
+ /**
+ * @return true if the object is stopped
+ */
+ public boolean isStopped(){
+ return currentState != null && currentState.equals(LifeCycleMBean.STOPPED);
+ }
+
+ /**
+ * @return true if the object is shutDown
+ */
+ public boolean isShutDown(){
+ return currentState != null && currentState.equals(LifeCycleMBean.SHUTDOWN);
+ }
+
+ /**
+ * @return true if the object is shutDown
+ */
+ public boolean isInitialized(){
+ return currentState != null && currentState.equals(INITIALIZED);
+ }
+
+ /**
+ * @return true if the object is shutDown
+ */
+ public boolean isUnknown(){
+ return currentState == null || currentState.equals(LifeCycleMBean.UNKNOWN);
+ }
+
/*
* (non-Javadoc)
*
@@ -140,6 +185,7 @@
// return null
}
doInit();
+ setCurrentState(INITIALIZED);
if (logger.isDebugEnabled()) {
logger.debug("Component initialized");
}
@@ -194,6 +240,7 @@
logger.debug("Shutting down component");
}
doShutDown();
+ setCurrentState(LifeCycleMBean.SHUTDOWN);
this.context = null;
if (logger.isDebugEnabled()) {
logger.debug("Component shut down");
@@ -233,6 +280,7 @@
}
if (this.running.compareAndSet(false, true)) {
doStart();
+ setCurrentState(LifeCycleMBean.STARTED);
}
if (logger.isDebugEnabled()) {
logger.debug("Component started");
@@ -309,6 +357,7 @@
}
if (this.running.compareAndSet(true, false)) {
doStop();
+ setCurrentState(LifeCycleMBean.STOPPED);
}
if (logger.isDebugEnabled()) {
logger.debug("Component stopped");
Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java?view=diff&rev=522539&r1=522538&r2=522539
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java (original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/DefaultComponent.java Mon Mar 26 08:13:32 2007
@@ -242,6 +242,7 @@
public ServiceUnit getServiceUnit() {
if (serviceUnit == null) {
serviceUnit = new XBeanServiceUnit();
+ serviceUnit.setName("#default#");
serviceUnit.setComponent(this);
}
return serviceUnit;
@@ -295,14 +296,19 @@
/**
* Dynamically adds a new endpoint
*/
- protected void addEndpoint(Endpoint endpoint) throws DeploymentException {
+ protected void addEndpoint(Endpoint endpoint) throws Exception {
ServiceUnit su = getServiceUnit();
endpoint.setServiceUnit(su);
validateEndpoint(endpoint);
endpoint.validate();
su.addEndpoint(endpoint);
- if (registry.getServiceUnit(su.getName()) != null) {
+ if (registry.isRegistered(su)) {
registry.registerEndpoint(endpoint);
+ } else {
+ registry.registerServiceUnit(su);
+ if (isStarted()) {
+ su.start();
+ }
}
}
@@ -334,7 +340,7 @@
protected void doStart() throws Exception {
super.doStart();
if (serviceUnit != null) {
- if (registry.getServiceUnit(serviceUnit.getName()) == null) {
+ if (!registry.isRegistered(serviceUnit)) {
registry.registerServiceUnit(serviceUnit);
}
serviceUnit.start();
Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java?view=diff&rev=522539&r1=522538&r2=522539
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java (original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/Registry.java Mon Mar 26 08:13:32 2007
@@ -37,6 +37,14 @@
return (Endpoint) this.endpoints.get(key);
}
+ public boolean isRegistered(ServiceUnit su) {
+ return isServiceUnitRegistered(su.getName());
+ }
+
+ public boolean isServiceUnitRegistered(String name) {
+ return this.serviceUnits.containsKey(name);
+ }
+
public ServiceUnit getServiceUnit(String name) {
return (ServiceUnit) this.serviceUnits.get(name);
}