Diff
Modified: trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixComponent.java (964 => 965)
--- trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixComponent.java 2005-11-29 01:15:23 UTC (rev 964)
+++ trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixComponent.java 2005-11-29 01:22:34 UTC (rev 965)
@@ -1,12 +1,15 @@
package org.servicemix.components.servicemix;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.servicemix.jbi.container.JBIContainer;
-import org.servicemix.jbi.container.SpringServiceUnitContainer;
import org.servicemix.jbi.framework.ComponentContextImpl;
import org.servicemix.jbi.management.BaseLifeCycle;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
+import org.xbean.spring.context.FileSystemXmlApplicationContext;
import javax.jbi.JBIException;
import javax.jbi.component.Component;
@@ -25,6 +28,8 @@
*/
public class ServiceMixComponent extends BaseLifeCycle implements ComponentLifeCycle, Component, ServiceUnitManager {
+ private static Log logger = LogFactory.getLog(ServiceMixComponent.class);
+
private ComponentContext context;
public String getDescription() {
@@ -35,12 +40,12 @@
// ComponentLifeCycle implementation
// /////////////////////////////////////////////////////////////////
public void init(ComponentContext context) throws JBIException {
- System.out.println("ServiceMixComponent: init");
+ logger.debug("ServiceMixComponent: init");
this.context = context;
}
public ObjectName getExtensionMBeanName() {
- System.out.println("ServiceMixComponent: getExtensionMBeanName");
+ logger.debug("ServiceMixComponent: getExtensionMBeanName");
return null;
}
@@ -56,19 +61,18 @@
}
public Document getServiceDescription(ServiceEndpoint endpoint) {
- System.out.println("ServiceMixComponent: getServiceDescription");
- // TODO Auto-generated method stub
+ logger.debug("ServiceMixComponent: getServiceDescription");
return null;
}
public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
- System.out.println("ServiceMixComponent: isExchangeWithConsumerOkay");
+ logger.debug("ServiceMixComponent: isExchangeWithConsumerOkay");
return false;
}
public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
- System.out.println("ServiceMixComponent: isExchangeWithProviderOkay");
- return false;
+ logger.debug("ServiceMixComponent: isExchangeWithProviderOkay");
+ return true;
}
@@ -80,25 +84,24 @@
// /////////////////////////////////////////////////////////////////
// ServiceUnitManager implementation
// /////////////////////////////////////////////////////////////////
- Map serviceUnitRegistry = new edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap();
+ Map serviceUnitRegistry = new ConcurrentHashMap();
public String deploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
- System.out.println("ServiceMixComponent: deploy");
+ logger.debug("ServiceMixComponent: deploy");
return null;
}
public void init(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
- System.out.println("ServiceMixComponent: init: " + serviceUnitName + " path: " + serviceUnitRootPath);
+ logger.debug("ServiceMixComponent: init: " + serviceUnitName + " path: " + serviceUnitRootPath);
FileSystemXmlApplicationContext springContext = new FileSystemXmlApplicationContext("file:"+ serviceUnitRootPath +"/servicemix.xml" );
- SpringServiceUnitContainer ssuc = (SpringServiceUnitContainer) springContext.getBean("jbi");
- ServiceMixServiceUnit suc = new ServiceMixServiceUnit(this, serviceUnitName, serviceUnitRootPath, springContext, ssuc);
+ ServiceMixServiceUnit suc = new ServiceMixServiceUnit(this, serviceUnitName, serviceUnitRootPath, springContext);
serviceUnitRegistry.put(serviceUnitName, suc);
}
public void start(String serviceUnitName) throws DeploymentException {
- System.out.println("ServiceMixComponent: start: " + serviceUnitName);
+ logger.debug("ServiceMixComponent: start: " + serviceUnitName);
ServiceMixServiceUnit unit = (ServiceMixServiceUnit) serviceUnitRegistry.get(serviceUnitName);
if( unit == null )
throw new DeploymentException("Service Unit not registered: "+serviceUnitName);
@@ -110,7 +113,7 @@
}
public void stop(String serviceUnitName) throws DeploymentException {
- System.out.println("ServiceMixComponent: stop: " + serviceUnitName);
+ logger.debug("ServiceMixComponent: stop: " + serviceUnitName);
ServiceMixServiceUnit unit = (ServiceMixServiceUnit) serviceUnitRegistry.get(serviceUnitName);
if( unit == null )
throw new DeploymentException("Service Unit not registered: "+serviceUnitName);
@@ -122,15 +125,15 @@
}
public void shutDown(String serviceUnitName) throws DeploymentException {
- System.out.println("ServiceMixComponent: shutDown: " + serviceUnitName);
- ServiceMixServiceUnit unit = (ServiceMixServiceUnit) serviceUnitRegistry.remove(serviceUnitName);
+ logger.debug("ServiceMixComponent: shutDown: " + serviceUnitName);
+ ServiceMixServiceUnit unit = (ServiceMixServiceUnit) serviceUnitRegistry.get(serviceUnitName);
if( unit == null )
throw new DeploymentException("Service Unit not registered: "+serviceUnitName);
unit.shutdown();
}
public String undeploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException {
- System.out.println("ServiceMixComponent: undeploy: " + serviceUnitName);
+ logger.debug("ServiceMixComponent: undeploy: " + serviceUnitName);
ServiceMixServiceUnit unit = (ServiceMixServiceUnit) serviceUnitRegistry.remove(serviceUnitName);
if( unit == null )
throw new DeploymentException("Service Unit not registered: "+serviceUnitName);
@@ -148,7 +151,7 @@
public JBIContainer getContainer() {
if( context instanceof ComponentContextImpl ) {
- return ((ComponentContextImpl)context).getContainer();
+ return ((ComponentContextImpl) context).getContainer();
}
return null;
}
Modified: trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixServiceUnit.java (964 => 965)
--- trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixServiceUnit.java 2005-11-29 01:15:23 UTC (rev 964)
+++ trunk/core/src/main/java/org/servicemix/components/servicemix/ServiceMixServiceUnit.java 2005-11-29 01:22:34 UTC (rev 965)
@@ -19,37 +19,47 @@
package org.servicemix.components.servicemix;
+import org.servicemix.jbi.container.ActivationSpec;
import org.servicemix.jbi.container.JBIContainer;
-import org.servicemix.jbi.container.SpringServiceUnitContainer;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
+import org.springframework.context.ConfigurableApplicationContext;
import javax.jbi.JBIException;
+import java.util.Collection;
+import java.util.Iterator;
+
public class ServiceMixServiceUnit {
private final JBIContainer container;
private final ServiceMixComponent component;
private final String serviceUnitName;
private final String serviceUnitRootPath;
- private final FileSystemXmlApplicationContext springContext;
- private final SpringServiceUnitContainer ssuc;
+ private final ConfigurableApplicationContext springContext;
+ private final Collection activationSpecs;
public ServiceMixServiceUnit(ServiceMixComponent component, String serviceUnitName, String serviceUnitRootPath,
- FileSystemXmlApplicationContext springContext, SpringServiceUnitContainer ssuc) {
+ ConfigurableApplicationContext springContext) {
this.component = component;
-
this.container = component.getContainer();
this.serviceUnitName = serviceUnitName;
this.serviceUnitRootPath = serviceUnitRootPath;
this.springContext = springContext;
- this.ssuc = ssuc;
+ this.activationSpecs = springContext.getBeansOfType(ActivationSpec.class).values();
+
}
public void start() throws Exception {
- ssuc.start(container);
+ for (Iterator iter = this.activationSpecs.iterator(); iter.hasNext();) {
+ ActivationSpec as = (ActivationSpec) iter.next();
+ this.container.activateComponent(as);
+ }
}
+
public void stop() throws JBIException {
- ssuc.stop(container);
+ for (Iterator iter = this.activationSpecs.iterator(); iter.hasNext();) {
+ ActivationSpec as = (ActivationSpec) iter.next();
+ this.container.deactivateComponent(as.getId());
+ }
}
public void shutdown() {
@@ -71,10 +81,7 @@
public String getServiceUnitRootPath() {
return serviceUnitRootPath;
}
- public FileSystemXmlApplicationContext getSpringContext() {
+ public ConfigurableApplicationContext getSpringContext() {
return springContext;
}
- public SpringServiceUnitContainer getSsuc() {
- return ssuc;
- }
}
\ No newline at end of file
Modified: trunk/core/src/main/java/org/servicemix/jbi/container/EnvironmentContext.java (964 => 965)
--- trunk/core/src/main/java/org/servicemix/jbi/container/EnvironmentContext.java 2005-11-29 01:15:23 UTC (rev 964)
+++ trunk/core/src/main/java/org/servicemix/jbi/container/EnvironmentContext.java 2005-11-29 01:22:34 UTC (rev 965)
@@ -309,6 +309,9 @@
* @throws IOException
*/
public File getComponentRootDirectory(String componentName) throws IOException {
+ if (getComponentsDir() == null) {
+ return null;
+ }
File result = FileUtil.getDirectoryPath(getComponentsDir(), componentName);
return result;
}
@@ -431,12 +434,14 @@
public void removeComponentRootDirectory(String componentName) {
try {
File file = getComponentRootDirectory(componentName);
- if (!FileUtil.deleteFile(file)) {
- log.warn("Failed to remove directory structure for Component: " + componentName);
+ if (file != null) {
+ if (!FileUtil.deleteFile(file)) {
+ log.warn("Failed to remove directory structure for Component: " + componentName);
+ }
+ else {
+ log.info("Removed Component Root directory for " + componentName);
+ }
}
- else {
- log.info("Removed Component Root directory for " + componentName);
- }
}
catch (IOException e) {
log.warn("Failed to remove directory structure for Component: " + componentName, e);
Modified: trunk/core/src/test/java/org/servicemix/components/servicemix/ServiceMixComponentTest.java (964 => 965)
--- trunk/core/src/test/java/org/servicemix/components/servicemix/ServiceMixComponentTest.java 2005-11-29 01:15:23 UTC (rev 964)
+++ trunk/core/src/test/java/org/servicemix/components/servicemix/ServiceMixComponentTest.java 2005-11-29 01:22:34 UTC (rev 965)
@@ -17,9 +17,16 @@
**/
package org.servicemix.components.servicemix;
+import org.servicemix.client.DefaultServiceMixClient;
+import org.servicemix.client.ServiceMixClient;
import org.servicemix.jbi.container.JBIContainer;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
import java.io.File;
+import java.net.URI;
import java.net.URL;
import junit.framework.TestCase;
@@ -51,33 +58,48 @@
+ tempRootDir.getAbsolutePath() + "]");
container.setRootDir(tempRootDir.getAbsolutePath());
+ container.setMonitorInstallationDirectory(false);
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.setFlowName("st");
container.init();
container.start();
-
}
public void testComponentInstallation() throws Exception {
- try {
+ ServiceMixComponent component = new ServiceMixComponent();
+ container.activateComponent(component, "#ServiceMixComponent#");
+ URL url = ""
+ File path = new File(new URI(url.toString()));
+ path = path.getParentFile();
+ ServiceMixClient client = new DefaultServiceMixClient(container);
+
+ for (int i = 0; i < 2; i++) {
+ // Deploy and start su
+ component.deploy("su1", path.getAbsolutePath());
+ component.init("su1", path.getAbsolutePath());
+ component.start("su1");
- // Install the component.
- String resource = "component.zip";
- URL componentResource = getClass().getResource(resource);
- assertNotNull("The component JAR "+resource+" is missing from the classpath", componentResource);
- container.installArchive(componentResource.toExternalForm());
+ // Send message
+ InOut inout = client.createInOutExchange();
+ inout.setService(new QName("http://servicemix.org/demo/", "chained"));
+ client.send(inout);
- // Install the service assembly
- resource = "au1.zip";
- componentResource = getClass().getResource(resource);
- assertNotNull("The component JAR "+resource+" is missing from the classpath", componentResource);
- container.installArchive(componentResource.toExternalForm());
+ // Stop and undeploy
+ component.stop("su1");
+ component.shutDown("su1");
+ component.undeploy("su1", path.getAbsolutePath());
+
+ // Send message
+ inout = client.createInOutExchange();
+ inout.setService(new QName("http://servicemix.org/demo/", "chained"));
+ try {
+ client.send(inout);
+ } catch (MessagingException e) {
+ // Ok, the lw component is undeployed
+ }
- Thread.sleep(1000*10);
-
-
- } catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ }
}
/*
Modified: trunk/core/src/test/resources/org/servicemix/components/servicemix/su1-src/servicemix.xml (964 => 965)
--- trunk/core/src/test/resources/org/servicemix/components/servicemix/su1-src/servicemix.xml 2005-11-29 01:15:23 UTC (rev 964)
+++ trunk/core/src/test/resources/org/servicemix/components/servicemix/su1-src/servicemix.xml 2005-11-29 01:22:34 UTC (rev 965)
@@ -1,34 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: servicemix -->
-<beans xmlns:my="http://servicemix.org/demo/">
+<beans xmlns:my="http://servicemix.org/demo/"
+ xmlns:sm="http://servicemix.org/config/1.0">
- <serviceunit id="jbi">
- <components>
+ <sm:activationSpec service="my:echo">
+ <sm:component>
+ <bean class="org.servicemix.components.util.EchoComponent" />
+ </sm:component>
+ </sm:activationSpec>
- <!-- lets kick off a timer to send messages on an input destination topic -->
- <component id="timer" service="my:timer" class="org.servicemix.components.quartz.QuartzComponent" destinationService="my:trace">
- <property name="triggers">
- <map>
- <entry>
- <key>
- <bean class="org.quartz.SimpleTrigger">
- <property name="repeatInterval" value="500"/>
- <property name="repeatCount" value="-1"/>
- </bean>
- </key>
- <bean class="org.quartz.JobDetail">
- <property name="name" value="My Example Job"/>
- <property name="group" value="ServiceMix"/>
- </bean>
- </entry>
- </map>
+ <sm:activationSpec service="my:chained">
+ <sm:component>
+ <bean class="org.servicemix.components.util.ChainedComponent">
+ <property name="services">
+ <list>
+ <bean
+ class="javax.xml.namespace.QName">
+ <constructor-arg value="http://servicemix.org/demo/" />
+ <constructor-arg value="echo" />
+ </bean>
+ </list>
</property>
- </component>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
- <component id="trace" service="my:trace" class="org.servicemix.components.util.TraceComponent"/>
-
- </components>
- </serviceunit>
-
+ <sm:activationSpec service="my:trace">
+ <sm:component>
+ <bean class="org.servicemix.components.util.TraceComponent" />
+ </sm:component>
+ <sm:subscriptions>
+ <sm:subscriptionSpec service="my:chained"/>
+ </sm:subscriptions>
+ </sm:activationSpec>
+
</beans>
<!-- END SNIPPET: servicemix -->