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/03/09 17:09:16 UTC
svn commit: r384539 - in /incubator/servicemix/trunk:
servicemix-common/src/main/java/org/apache/servicemix/common/
servicemix-common/src/main/java/org/apache/servicemix/common/xbean/
servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ s...
Author: gnodet
Date: Thu Mar 9 08:09:13 2006
New Revision: 384539
URL: http://svn.apache.org/viewcvs?rev=384539&view=rev
Log:
Fix SA/SU lifecycle in container and components
Modified:
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/DeploymentService.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java
incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNDeployer.java
Modified: incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java (original)
+++ incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java Thu Mar 9 08:09:13 2006
@@ -15,20 +15,22 @@
*/
package org.apache.servicemix.common;
-import javax.jbi.JBIException;
-import javax.jbi.management.LifeCycleMBean;
-
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
public class ServiceUnit {
protected BaseComponent component;
protected String name;
protected String rootPath;
- protected String status = LifeCycleMBean.STOPPED;
+ protected String status = LifeCycleMBean.SHUTDOWN;
protected Map endpoints = new HashMap();
public ServiceUnit() {
@@ -36,19 +38,42 @@
public void start() throws Exception {
// Activate endpoints
- for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
- Endpoint endpoint = (Endpoint) iter.next();
- endpoint.activate();
+ List activated = new ArrayList();
+ try {
+ for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
+ Endpoint endpoint = (Endpoint) iter.next();
+ endpoint.activate();
+ activated.add(endpoint);
+ }
+ this.status = LifeCycleMBean.STARTED;
+ } catch (Exception e) {
+ // Deactivate activated endpoints
+ for (Iterator iter = activated.iterator(); iter.hasNext();) {
+ try {
+ Endpoint endpoint = (Endpoint) iter.next();
+ endpoint.deactivate();
+ } catch (Exception e2) {
+ // do nothing
+ }
+ }
+ throw e;
}
- this.status = LifeCycleMBean.STARTED;
}
public void stop() throws Exception {
this.status = LifeCycleMBean.STOPPED;
- // Activate endpoints
+ // Deactivate endpoints
+ Exception exception = null;
for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
Endpoint endpoint = (Endpoint) iter.next();
- endpoint.deactivate();
+ try {
+ endpoint.deactivate();
+ } catch (Exception e) {
+ exception = e;
+ }
+ }
+ if (exception != null) {
+ throw exception;
}
}
Modified: incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java (original)
+++ incubator/servicemix/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/XBeanServiceUnit.java Thu Mar 9 08:09:13 2006
@@ -54,10 +54,10 @@
* @see org.apache.servicemix.common.ServiceUnit#shutDown()
*/
public void shutDown() throws JBIException {
+ super.shutDown();
if (kernel != null) {
kernel.destroy();
}
- super.shutDown();
}
public ClassLoader getConfigurationClassLoader() throws ServiceNotFoundException {
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java Thu Mar 9 08:09:13 2006
@@ -207,6 +207,7 @@
try {
doStart();
persistRunningState();
+ getContainer().getRegistry().checkPendingAssemblies();
} catch (JBIException e) {
log.error("Could not start component", e);
throw e;
@@ -544,7 +545,7 @@
if (sa.isStarted()) {
try {
sa.stop(false, false);
- // TODO: add sa to a list of pending sa
+ registry.addPendingAssembly(sa);
} catch (Exception e) {
log.error("Error stopping service assembly " + sas[i]);
}
@@ -553,15 +554,14 @@
}
protected void shutDownServiceAssemblies() throws DeploymentException {
- JBIContainer container = getContainer();
- Registry registry = container.getRegistry();
+ Registry registry = getContainer().getRegistry();
String[] sas = registry.getDeployedServiceAssembliesForComponent(getName());
for (int i = 0; i < sas.length; i++) {
ServiceAssemblyLifeCycle sa = registry.getServiceAssembly(sas[i]);
if (sa.isStopped()) {
try {
sa.shutDown(false);
- // TODO: add sa to a list of pending sa
+ registry.addPendingAssembly(sa);
} catch (Exception e) {
log.error("Error shutting down service assembly " + sas[i]);
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/DeploymentService.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/DeploymentService.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/DeploymentService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/DeploymentService.java Thu Mar 9 08:09:13 2006
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import javax.jbi.JBIException;
@@ -224,6 +225,12 @@
throw ManagementSupport.failure("undeploy", "SA must be shut down: " + saName);
}
try {
+ // Make sure the all service units in the assembly are shutdown.
+ // SUs can have different states (if a previous shutdown failed).
+ try {
+ sa.shutDown();
+ } catch (Exception e) {
+ }
String result = null;
if (sa != null) {
String assemblyName = sa.getName();
@@ -513,12 +520,16 @@
try {
ComponentMBeanImpl lcc = container.getComponent(componentName);
ServiceUnitManager sum = lcc.getServiceUnitManager();
- String resultMsg = sum.deploy(suName, targetDir.getAbsolutePath());
- success = getComponentTaskResult(resultMsg, componentName, componentResults, true);
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(lcc.getComponent().getClass().getClassLoader());
+ String resultMsg = sum.deploy(suName, targetDir.getAbsolutePath());
+ success = getComponentTaskResult(resultMsg, componentName, componentResults, true);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
// TODO: need to register the SU somewhere to keep track of its state
} catch (Exception e) {
- // Delete SU deployment dir
- FileUtil.deleteFile(targetDir);
getComponentTaskResult(e.getMessage(), componentName, componentResults, false);
}
if (success) {
@@ -529,10 +540,25 @@
}
}
}
- // Total failure
- if (nbSuccess == 0 && nbFailures > 0) {
+ // Note: the jbi spec says that if at least one deployment succeeds,
+ // this should be a SUCCESS. However, ServiceMix handles SA in an
+ // atomic way: for a given operation on an SA, all operations on SU
+ // should succeed. This is clearly a minor violation of the spec.
+ //
+ // Failure
+ if (nbFailures > 0) {
+ // Undeploy SUs
+ for (Iterator iter = suKeys.iterator(); iter.hasNext();) {
+ try {
+ String suName = (String) iter.next();
+ ServiceUnitLifeCycle su = registry.getServiceUnit(suName);
+ undeployServiceUnit(su);
+ } catch (Exception e) {
+ log.warn("Error undeploying SU", e);
+ }
+ }
// Delete SA deployment directory
- FileUtil.deleteFile(tmpDir);
+ FileUtil.deleteFile(saDirectory);
throw ManagementSupport.failure("deploy", componentResults);
}
// Success
@@ -619,7 +645,13 @@
if (component != null) {
ServiceUnitManager sum = component.getServiceUnitManager();
if (sum != null) {
- sum.undeploy(name, targetDir.getAbsolutePath());
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(component.getComponent().getClass().getClassLoader());
+ sum.undeploy(name, targetDir.getAbsolutePath());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
FileUtil.deleteFile(targetDir);
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java Thu Mar 9 08:09:13 2006
@@ -28,6 +28,8 @@
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.management.JMException;
import javax.management.ObjectName;
+import javax.resource.spi.work.Work;
+import javax.resource.spi.work.WorkException;
import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
@@ -46,6 +48,7 @@
import org.w3c.dom.DocumentFragment;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
/**
* Registry - state infomation including running state, SA's deployed etc.
@@ -60,6 +63,7 @@
private SubscriptionRegistry subscriptionRegistry;
private ServiceAssemblyRegistry serviceAssemblyRegistry;
private Map serviceUnits;
+ private List pendingAssemblies;
/**
* Constructor
@@ -70,6 +74,7 @@
this.subscriptionRegistry = new SubscriptionRegistry(this);
this.serviceAssemblyRegistry = new ServiceAssemblyRegistry(this);
this.serviceUnits = new ConcurrentHashMap();
+ this.pendingAssemblies = new CopyOnWriteArrayList();
}
/**
@@ -456,7 +461,6 @@
* @param sa
* @return true if not already registered
* @throws DeploymentException
- * @deprecated
*/
public ServiceAssemblyLifeCycle registerServiceAssembly(ServiceAssembly sa) throws DeploymentException{
return serviceAssemblyRegistry.register(sa);
@@ -618,6 +622,49 @@
public void unregisterRemoteEndpoint(ServiceEndpoint endpoint) {
endpointRegistry.unregisterRemoteEndpoint((InternalEndpoint) endpoint);
+ }
+
+ public void checkPendingAssemblies() {
+ try {
+ getContainer().getWorkManager().scheduleWork(new Work() {
+ public void release() {
+ }
+ public void run() {
+ startPendingAssemblies();
+ }
+ });
+ } catch (WorkException e) {
+ log.error("Could not schedule work", e);
+ }
+ }
+
+ public void addPendingAssembly(ServiceAssemblyLifeCycle sa) {
+ if (!pendingAssemblies.contains(sa)) {
+ pendingAssemblies.add(sa);
+ }
+ }
+
+ protected synchronized void startPendingAssemblies() {
+ for (Iterator iter = pendingAssemblies.iterator(); iter.hasNext();) {
+ ServiceAssemblyLifeCycle sa = (ServiceAssemblyLifeCycle) iter.next();
+ ServiceUnitLifeCycle[] sus = sa.getDeployedSUs();
+ boolean ok = true;
+ for (int i = 0; i < sus.length; i++) {
+ ComponentMBeanImpl c = getComponent(sus[i].getComponentName());
+ if (c == null || !c.isStarted()) {
+ ok = false;
+ break;
+ }
+ }
+ if (ok) {
+ try {
+ sa.restore();
+ pendingAssemblies.remove(sa);
+ } catch (Exception e) {
+ log.error("Error trying to restore service assembly state", e);
+ }
+ }
+ }
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyLifeCycle.java Thu Mar 9 08:09:13 2006
@@ -105,7 +105,7 @@
return start(true);
}
- public String start(boolean writeState) throws Exception {
+ public synchronized String start(boolean writeState) throws Exception {
log.info("Starting service assembly: " + getName());
// Start connections
try {
@@ -134,7 +134,6 @@
}
}
if (componentFailures.size() == 0) {
- log.info("Started Service Assembly: " + getName());
currentState = STARTED;
if (writeState) {
writeRunningState();
@@ -156,7 +155,7 @@
return stop(true, false);
}
- public String stop(boolean writeState, boolean forceInit) throws Exception {
+ public synchronized String stop(boolean writeState, boolean forceInit) throws Exception {
log.info("Stopping service assembly: " + getName());
// Stop connections
stopConnections();
@@ -181,7 +180,6 @@
}
}
if (componentFailures.size() == 0) {
- log.info("Stopped Service Assembly: " + getName());
currentState = STOPPED;
if (writeState) {
writeRunningState();
@@ -203,7 +201,7 @@
return shutDown(true);
}
- public String shutDown(boolean writeState) throws Exception {
+ public synchronized String shutDown(boolean writeState) throws Exception {
log.info("Shutting down service assembly: " + getName());
List componentFailures = new ArrayList();
for (int i = 0; i < sus.length; i++) {
@@ -225,7 +223,6 @@
}
}
if (componentFailures.size() == 0) {
- log.info("Shutdown Service Assembly: " + getName());
currentState = SHUTDOWN;
if (writeState) {
writeRunningState();
@@ -323,7 +320,7 @@
* Restore this service assembly to its state at shutdown.
* @throws Exception
*/
- void restore() throws Exception {
+ synchronized void restore() throws Exception {
String state = getRunningStateFromStore();
if (STARTED.equals(state)) {
start(false);
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceAssemblyRegistry.java Thu Mar 9 08:09:13 2006
@@ -77,15 +77,16 @@
* @param sa
* @return true if successful
* @throws DeploymentException
- * @deprecated
*/
public ServiceAssemblyLifeCycle register(ServiceAssembly sa) throws DeploymentException {
List sus = new ArrayList();
- for (int i = 0; i < sa.getServiceUnits().length; i++) {
- String suKey = registry.registerServiceUnit(
- sa.getServiceUnits()[i],
- sa.getIdentification().getName());
- sus.add(suKey);
+ if (sa.getServiceUnits() != null) {
+ for (int i = 0; i < sa.getServiceUnits().length; i++) {
+ String suKey = registry.registerServiceUnit(
+ sa.getServiceUnits()[i],
+ sa.getIdentification().getName());
+ sus.add(suKey);
+ }
}
return register(sa, (String[]) sus.toArray(new String[sus.size()]));
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ServiceUnitLifeCycle.java Thu Mar 9 08:09:13 2006
@@ -74,7 +74,13 @@
checkComponentStarted("init");
ServiceUnitManager sum = getServiceUnitManager();
File path = getServiceUnitRootPath();
- sum.init(getName(), path.getAbsolutePath());
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getComponentClassLoader());
+ sum.init(getName(), path.getAbsolutePath());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
currentState = STOPPED;
}
@@ -86,7 +92,13 @@
log.info("Starting service unit: " + getName());
checkComponentStarted("start");
ServiceUnitManager sum = getServiceUnitManager();
- sum.start(getName());
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getComponentClassLoader());
+ sum.start(getName());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
currentState = STARTED;
}
@@ -98,7 +110,13 @@
log.info("Stopping service unit: " + getName());
checkComponentStarted("stop");
ServiceUnitManager sum = getServiceUnitManager();
- sum.stop(getName());
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getComponentClassLoader());
+ sum.stop(getName());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
currentState = STOPPED;
}
@@ -111,7 +129,13 @@
log.info("Shutting down service unit: " + getName());
checkComponentStartedOrStopped("shutDown");
ServiceUnitManager sum = getServiceUnitManager();
- sum.shutDown(getName());
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getComponentClassLoader());
+ sum.shutDown(getName());
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
currentState = SHUTDOWN;
}
@@ -205,6 +229,12 @@
protected ServiceUnitManager getServiceUnitManager() {
ComponentMBeanImpl lcc = registry.getComponent(getComponentName());
return lcc.getServiceUnitManager();
+ }
+
+ protected ClassLoader getComponentClassLoader() {
+ ComponentMBeanImpl lcc = registry.getComponent(getComponentName());
+ // TODO: should retrieve the real component class loader
+ return lcc.getComponent().getClass().getClassLoader();
}
public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/ManagementContext.java Thu Mar 9 08:09:13 2006
@@ -533,7 +533,7 @@
}
public static ObjectName getContainerObjectName(String domainName, String containerName) {
- String tmp = domainName + ":" + "type=Container,name=" + containerName;
+ String tmp = domainName + ":container=" + containerName + ",type=Container";
ObjectName result = null;
try {
result = new ObjectName(tmp);
Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNDeployer.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNDeployer.java?rev=384539&r1=384538&r2=384539&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNDeployer.java (original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNDeployer.java Thu Mar 9 08:09:13 2006
@@ -17,7 +17,9 @@
import java.io.File;
import java.io.FilenameFilter;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import javax.jbi.management.DeploymentException;
import javax.jbi.management.LifeCycleMBean;
@@ -186,19 +188,34 @@
public static class WSNServiceUnit extends ServiceUnit {
public void start() throws Exception {
- for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
- Endpoint endpoint = (Endpoint) iter.next();
- if (endpoint instanceof WSNPullPointEndpoint) {
- endpoint.activate();
+ List<Endpoint> activated = new ArrayList<Endpoint>();
+ try {
+ for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
+ Endpoint endpoint = (Endpoint) iter.next();
+ if (endpoint instanceof WSNPullPointEndpoint) {
+ endpoint.activate();
+ activated.add(endpoint);
+ }
}
- }
- for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
- Endpoint endpoint = (Endpoint) iter.next();
- if (endpoint instanceof WSNSubscriptionEndpoint) {
- endpoint.activate();
+ for (Iterator iter = getEndpoints().iterator(); iter.hasNext();) {
+ Endpoint endpoint = (Endpoint) iter.next();
+ if (endpoint instanceof WSNSubscriptionEndpoint) {
+ endpoint.activate();
+ activated.add(endpoint);
+ }
+ }
+ this.status = LifeCycleMBean.STARTED;
+ } catch (Exception e) {
+ // Deactivate activated endpoints
+ for (Endpoint endpoint : activated) {
+ try {
+ endpoint.deactivate();
+ } catch (Exception e2) {
+ // do nothing
+ }
}
+ throw e;
}
- this.status = LifeCycleMBean.STARTED;
}
}