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/10/16 03:09:29 UTC
svn commit: r584990 - in /incubator/servicemix/trunk:
common/servicemix-common/src/main/java/org/apache/servicemix/common/
core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/
deployables/serviceengines/servicemix-lwcontainer/ deploy...
Author: gnodet
Date: Mon Oct 15 18:09:27 2007
New Revision: 584990
URL: http://svn.apache.org/viewvc?rev=584990&view=rev
Log:
SM-1107: Deploy endpoints and listeners through the lwcontainer
Added:
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerExtra.java
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/servicemix.xml
Modified:
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/ServiceUnit.java
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringServiceUnitContainer.java
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/pom.xml
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java
incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/java/org/apache/servicemix/lwcontainer/LwContainerComponentTest.java
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?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- 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 Oct 15 18:09:27 2007
@@ -309,6 +309,11 @@
}
}
+ public void removeEndpoint(Endpoint endpoint) throws Exception {
+ ServiceUnit su = endpoint.getServiceUnit();
+ su.removeEndpoint(endpoint);
+ }
+
/**
* Provides a hook to validate the statically configured endpoint
Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java (original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceUnit.java Mon Oct 15 18:09:27 2007
@@ -98,7 +98,7 @@
public void setName(String name) {
this.name = name;
}
-
+
public String getRootPath() {
return rootPath;
}
@@ -135,6 +135,19 @@
if (this.status == LifeCycleMBean.STARTED) {
try {
endpoint.activate();
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ }
+ }
+ }
+
+ public void removeEndpoint(Endpoint endpoint) throws DeploymentException {
+ if (this.endpoints.remove(endpoint) != null) {
+ throw new DeploymentException("Endpoint not found in the SU for key: " + EndpointSupport.getKey(endpoint));
+ }
+ if (this.status == LifeCycleMBean.STARTED) {
+ try {
+ endpoint.deactivate();
} catch (Exception e) {
throw new DeploymentException(e);
}
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringServiceUnitContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringServiceUnitContainer.java?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringServiceUnitContainer.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/SpringServiceUnitContainer.java Mon Oct 15 18:09:27 2007
@@ -16,6 +16,11 @@
*/
package org.apache.servicemix.jbi.container;
+import java.util.EventListener;
+import java.util.Map;
+
+import org.apache.servicemix.jbi.management.BaseSystemService;
+
/**
* Used to hold a Server Unit configuration. The components
* are registered into the JBI container using the Service Unit
@@ -28,6 +33,10 @@
public class SpringServiceUnitContainer {
private ActivationSpec[] activationSpecs;
+ private Map components;
+ private Map endpoints;
+ private EventListener[] listeners;
+ private BaseSystemService[] services;
public ActivationSpec[] getActivationSpecs() {
return activationSpecs;
@@ -37,4 +46,41 @@
this.activationSpecs = activationSpecs;
}
+ /**
+ * @org.apache.xbean.Map flat="true" keyName="name"
+ */
+ public Map getComponents() {
+ return components;
+ }
+
+ public void setComponents(Map components) {
+ this.components = components;
+ }
+
+ /**
+ * @org.apache.xbean.Map flat="true" dups="always" keyName="component" defaultKey=""
+ */
+ public Map getEndpoints() {
+ return endpoints;
+ }
+
+ public void setEndpoints(Map endpoints) {
+ this.endpoints = endpoints;
+ }
+
+ public EventListener[] getListeners() {
+ return listeners;
+ }
+
+ public void setListeners(EventListener[] listeners) {
+ this.listeners = listeners;
+ }
+
+ public BaseSystemService[] getServices() {
+ return services;
+ }
+
+ public void setServices(BaseSystemService[] services) {
+ this.services = services;
+ }
}
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/pom.xml?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/pom.xml (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/pom.xml Mon Oct 15 18:09:27 2007
@@ -48,6 +48,11 @@
<artifactId>commons-logging</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>quartz</groupId>
+ <artifactId>quartz</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerExtra.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerExtra.java?rev=584990&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerExtra.java (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerExtra.java Mon Oct 15 18:09:27 2007
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.lwcontainer;
+
+import java.lang.reflect.Method;
+import java.util.EventListener;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.Component;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.id.IdGenerator;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.ComponentContextImpl;
+import org.apache.servicemix.jbi.management.BaseSystemService;
+import org.apache.xbean.spring.context.impl.NamespaceHelper;
+import org.springframework.beans.BeanUtils;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.util.ClassUtils;
+
+/**
+ * Fake endpoint that hold components, endpoints, listeners and services.
+ */
+public class LwContainerExtra extends Endpoint {
+
+ private Map components;
+ private Map endpoints;
+ private EventListener[] listeners;
+ private BaseSystemService[] services;
+ private IdGenerator idGenerator = new IdGenerator();
+ private Map<Object, Component> endpointToComponent = new IdentityHashMap<Object, Component>();
+
+ public LwContainerExtra(Map components, Map endpoints, EventListener[] listeners, BaseSystemService[] services) {
+ this.service = new QName("http://servicemix.apache.org/lwcontainer", "extra");
+ this.endpoint = idGenerator.generateSanitizedId();
+ this.components = components;
+ this.endpoints = endpoints;
+ this.listeners = listeners;
+ this.services = services;
+ }
+
+ public void activate() throws Exception {
+ if (components != null) {
+ for (Iterator it = components.entrySet().iterator(); it.hasNext();) {
+ Map.Entry e = (Map.Entry) it.next();
+ if (!(e.getKey() instanceof String)) {
+ throw new JBIException("Component must have a non null string name");
+ }
+ if (!(e.getValue() instanceof Component)) {
+ throw new JBIException("Component is not a known component");
+ }
+ String name = (String) e.getKey();
+ getContainer().activateComponent((Component) e.getValue(), name);
+ getContainer().getComponent(name).init();
+ }
+ }
+
+ if (endpoints != null) {
+ initEndpoints();
+ }
+ if (listeners != null) {
+ for (int i = 0; i < listeners.length; i++) {
+ getContainer().addListener(listeners[i]);
+ }
+ }
+ if (services != null) {
+ for (int i = 0; i < services.length; i++) {
+ services[i].init(getContainer());
+ services[i].start();
+ }
+ }
+ }
+
+ public void deactivate() throws Exception {
+ // Remove endpoints
+ if (endpoints != null) {
+ for (Iterator it = endpoints.entrySet().iterator(); it.hasNext();) {
+ Map.Entry e = (Map.Entry) it.next();
+ List l = (List) e.getValue();
+ for (Iterator itEp = l.iterator(); itEp.hasNext();) {
+ Object endpoint = itEp.next();
+ Component c = endpointToComponent.remove(endpoint);
+ ((DefaultComponent) c).removeEndpoint((Endpoint) endpoint);
+ }
+ }
+ }
+ // Deactivate components
+ if (components != null) {
+ for (Iterator it = components.entrySet().iterator(); it.hasNext();) {
+ Map.Entry e = (Map.Entry) it.next();
+ String name = (String) e.getKey();
+ getContainer().deactivateComponent(name);
+ }
+ }
+ // Remove listeners
+ if (listeners != null) {
+ for (int i = 0; i < listeners.length; i++) {
+ getContainer().removeListener(listeners[i]);
+ }
+ }
+ // Remove services
+ if (services != null) {
+ for (int i = 0; i < services.length; i++) {
+ services[i].stop();
+ services[i].shutDown();
+ }
+ }
+ }
+
+ public ExchangeProcessor getProcessor() {
+ return null;
+ }
+
+ public MessageExchange.Role getRole() {
+ return null;
+ }
+
+ private void initEndpoints() throws Exception {
+ if (components == null) {
+ components = new LinkedHashMap();
+ }
+ Method getEndpointClassesMethod = DefaultComponent.class.getDeclaredMethod("getEndpointClasses", null);
+ getEndpointClassesMethod.setAccessible(true);
+ for (Iterator it = endpoints.entrySet().iterator(); it.hasNext();) {
+ Map.Entry e = (Map.Entry) it.next();
+ String key = (String) e.getKey();
+ List l = (List) e.getValue();
+ for (Iterator itEp = l.iterator(); itEp.hasNext();) {
+ Object endpoint = itEp.next();
+ Component c = null;
+ if (key.length() > 0) {
+ Component comp = (Component) components.get(key);
+ if (comp == null) {
+ throw new JBIException("Could not find component '" + key + "' specified for endpoint");
+ }
+ c = comp;
+ } else {
+ for (Iterator itCmp = components.values().iterator(); itCmp.hasNext();) {
+ Component comp = (Component) itCmp.next();
+ Class[] endpointClasses = (Class[]) getEndpointClassesMethod.invoke(comp, null);
+ if (isKnownEndpoint(endpoint, endpointClasses)) {
+ c = comp;
+ break;
+ }
+ }
+ if (c == null) {
+ c = getComponentForEndpoint(getEndpointClassesMethod, endpoint);
+ if (c == null) {
+ throw new JBIException("Unable to find a component for endpoint class: " + endpoint.getClass());
+ }
+ }
+ }
+ ((DefaultComponent) c).addEndpoint((Endpoint) endpoint);
+ endpointToComponent.put(endpoint, c);
+ }
+ }
+ }
+
+ private Component getComponentForEndpoint(Method getEndpointClassesMethod, Object endpoint) throws Exception {
+ Properties namespaces = PropertiesLoaderUtils.loadAllProperties("META-INF/spring.handlers");
+ for (Iterator itNs = namespaces.keySet().iterator(); itNs.hasNext();) {
+ String namespaceURI = (String) itNs.next();
+ String uri = NamespaceHelper.createDiscoveryPathName(namespaceURI);
+ Properties props = PropertiesLoaderUtils.loadAllProperties(uri);
+ String compClassName = props.getProperty("component");
+ if (compClassName != null) {
+ Class compClass = ClassUtils.forName(compClassName);
+ Component comp = (Component) BeanUtils.instantiateClass(compClass);
+ Class[] endpointClasses = (Class[]) getEndpointClassesMethod.invoke(comp, null);
+ if (isKnownEndpoint(endpoint, endpointClasses)) {
+ String name = chooseComponentName(comp);
+ getContainer().activateComponent(comp, name);
+ components.put(name, comp);
+ return comp;
+ }
+ }
+ }
+ return null;
+ }
+
+ private String chooseComponentName(Object c) {
+ String className = c.getClass().getName();
+ if (className.startsWith("org.apache.servicemix.")) {
+ int idx1 = className.lastIndexOf('.');
+ int idx0 = className.lastIndexOf('.', idx1 - 1);
+ String name = "servicemix-" + className.substring(idx0 + 1, idx1);
+ return name + "-" + createComponentID();
+ }
+ return createComponentID();
+ }
+
+ private boolean isKnownEndpoint(Object endpoint, Class[] knownClasses) {
+ if (knownClasses != null) {
+ for (int i = 0; i < knownClasses.length; i++) {
+ if (knownClasses[i].isInstance(endpoint)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private JBIContainer getContainer() {
+ ComponentContext context = getServiceUnit().getComponent().getComponentContext();
+ if (context instanceof ComponentContextImpl) {
+ return ((ComponentContextImpl) context).getContainer();
+ }
+ throw new IllegalStateException("LwContainer component can only be deployed in ServiceMix");
+ }
+
+ protected String createComponentID() {
+ return idGenerator.generateId();
+ }
+
+}
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/main/java/org/apache/servicemix/lwcontainer/LwContainerXBeanDeployer.java Mon Oct 15 18:09:27 2007
@@ -42,8 +42,15 @@
SpringServiceUnitContainer suContainer = (SpringServiceUnitContainer) jbi;
ActivationSpec[] specs = suContainer.getActivationSpecs();
List services = new ArrayList();
- for (int i = 0; i < specs.length; i++) {
- services.add(new LwContainerEndpoint(specs[i]));
+ if (specs != null) {
+ for (int i = 0; i < specs.length; i++) {
+ services.add(new LwContainerEndpoint(specs[i]));
+ }
+ }
+ if (suContainer.getComponents() != null || suContainer.getEndpoints() != null
+ || suContainer.getListeners() != null || suContainer.getServices() != null) {
+ services.add(new LwContainerExtra(suContainer.getComponents(), suContainer.getEndpoints(),
+ suContainer.getListeners(), suContainer.getServices()));
}
return services;
} catch (Exception e) {
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/java/org/apache/servicemix/lwcontainer/LwContainerComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/java/org/apache/servicemix/lwcontainer/LwContainerComponentTest.java?rev=584990&r1=584989&r2=584990&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/java/org/apache/servicemix/lwcontainer/LwContainerComponentTest.java (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/java/org/apache/servicemix/lwcontainer/LwContainerComponentTest.java Mon Oct 15 18:09:27 2007
@@ -25,11 +25,12 @@
import javax.xml.namespace.QName;
import junit.framework.TestCase;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.container.InstallComponent;
+import org.apache.servicemix.jbi.container.InstallSharedLibrary;
import org.apache.servicemix.jbi.container.JBIContainer;
/**
@@ -103,10 +104,40 @@
}
}
+ public void testEndpoints() throws Exception {
+ LwContainerComponent component = new LwContainerComponent();
+ container.activateComponent(component, "#ServiceMixComponent#");
+
+ InstallSharedLibrary isl = new InstallSharedLibrary();
+ isl.setGroupId("org.apache.servicemix");
+ isl.setArtifactId("servicemix-shared");
+ isl.setVersion("3.2-SNAPSHOT");
+ isl.afterPropertiesSet();
+ isl.deploy(container);
+
+ InstallComponent ic = new InstallComponent();
+ ic.setGroupId("org.apache.servicemix");
+ ic.setArtifactId("servicemix-quartz");
+ ic.setVersion("3.2-SNAPSHOT");
+ ic.afterPropertiesSet();
+ ic.deploy(container);
+
+ URL url = getClass().getResource("su2-src/servicemix.xml");
+ File path = new File(new URI(url.toString()));
+ path = path.getParentFile();
+
+ // Deploy and start su
+ component.getServiceUnitManager().deploy("su2", path.getAbsolutePath());
+ component.getServiceUnitManager().init("su2", path.getAbsolutePath());
+ component.getServiceUnitManager().start("su2");
+
+ component.getServiceUnitManager().stop("su2");
+ component.getServiceUnitManager().shutDown("su2");
+ }
+
/*
* @see TestCase#tearDown()
*/
-
protected void tearDown() throws Exception {
super.tearDown();
container.stop();
Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/servicemix.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/servicemix.xml?rev=584990&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/servicemix.xml (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-lwcontainer/src/test/resources/org/apache/servicemix/lwcontainer/su2-src/servicemix.xml Mon Oct 15 18:09:27 2007
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<!-- START SNIPPET: servicemix -->
+<beans xmlns:my="http://servicemix.apache.org/demo/"
+ xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:quartz="http://servicemix.apache.org/quartz/1.0">
+
+ <classpath inverse="true">
+ <component>servicemix-quartz</component>
+ </classpath>
+
+ <sm:serviceunit id="jbi">
+ <sm:endpoints>
+
+ <quartz:endpoint service="my:service" endpoint="endpoint1" targetService="my:receiver1">
+ <quartz:trigger>
+ <quartz:cron cronExpression="0/5 * * * * ?" />
+ </quartz:trigger>
+ </quartz:endpoint>
+
+ </sm:endpoints>
+ </sm:serviceunit>
+
+</beans>
+<!-- END SNIPPET: servicemix -->