servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r634410 - in /servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer: Component.java ServiceUnit.java impl/ComponentImpl.java impl/Deployer.java impl/ServiceAssemblyImpl.java impl/ServiceUnitImpl.java
Date Thu, 06 Mar 2008 20:43:58 GMT
Author: gnodet
Date: Thu Mar  6 12:43:55 2008
New Revision: 634410

URL: http://svn.apache.org/viewvc?rev=634410&view=rev
Log:
SMX4NMR-10: Stopping a component should stop SAs with SUs deployed onto it

Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/Component.java
Thu Mar  6 12:43:55 2008
@@ -40,4 +40,9 @@
      * @return
      */
     javax.jbi.component.Component getComponent();
+
+    /**
+     * Retrieve the ServiceUnits deployed on this component 
+     */
+    ServiceUnit[] getServiceUnits();
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceUnit.java
Thu Mar  6 12:43:55 2008
@@ -35,4 +35,16 @@
      */
     String getDescription();
 
+    /**
+     * Get the ServiceAssembly to which this ServiceUnit belongs
+     * @return
+     */
+    ServiceAssembly getServiceAssembly();
+
+    /**
+     * Retrieve the Component onto which this ServiceUnit is deployed
+     * @return
+     */
+    Component getComponent();
+
 }

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ComponentImpl.java
Thu Mar  6 12:43:55 2008
@@ -16,6 +16,11 @@
  */
 package org.apache.servicemix.jbi.deployer.impl;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
 import javax.jbi.JBIException;
 import javax.jbi.component.ComponentContext;
 import javax.jbi.component.ComponentLifeCycle;
@@ -28,19 +33,15 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 
-import org.apache.servicemix.jbi.deployer.Component;
-import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceUnit;
+import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
 
 /**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Jan 3, 2008
- * Time: 5:15:57 PM
- * To change this template use File | Settings | File Templates.
  */
 public class ComponentImpl implements Component {
 
@@ -62,6 +63,7 @@
     private Preferences prefs;
     private State runningState;
     private Deployer deployer;
+    private List<ServiceUnitImpl> serviceUnits;
 
     public ComponentImpl(ComponentDesc componentDesc,
                          javax.jbi.component.Component component,
@@ -73,6 +75,19 @@
         this.prefs = prefs;
         this.runningState = State.valueOf(this.prefs.get(STATE, (autoStart ? State.Started
: State.Initialized).name()));
         this.deployer = deployer;
+        this.serviceUnits = new ArrayList<ServiceUnitImpl>();
+    }
+
+    public void addServiceUnit(ServiceUnitImpl serviceUnit) {
+        serviceUnits.add(serviceUnit);
+    }
+
+    public void removeServiceUnit(ServiceUnitImpl serviceUnit) {
+        serviceUnits.remove(serviceUnit);
+    }
+
+    public ServiceUnit[] getServiceUnits() {
+        return serviceUnits.toArray(new ServiceUnit[serviceUnits.size()]);
     }
 
     public String getName() {
@@ -84,7 +99,7 @@
     }
 
     public ObjectName getExtensionMBeanName() throws JBIException {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        return component.getLifeCycle().getExtensionMBeanName();
     }
 
     public javax.jbi.component.Component getComponent() {
@@ -96,6 +111,7 @@
     }
 
     public void start(boolean saveState) throws JBIException {
+        LOGGER.info("Starting component " + getName());
         component.getLifeCycle().start();
         state = State.Started;
         if (saveState) {
@@ -105,12 +121,24 @@
 
     public void stop() throws JBIException {
         stop(true);
+    }
 
+    protected Set<ServiceAssemblyImpl> getServiceAssemblies() {
+        Set<ServiceAssemblyImpl> sas = new HashSet<ServiceAssemblyImpl>();
+        for (ServiceUnitImpl su : serviceUnits) {
+            sas.add(su.getServiceAssemblyImpl());
+        }
+        return sas;
     }
 
     public void stop(boolean saveState) throws JBIException {
-        // TODO: stop deployed SAs
+        LOGGER.info("Stopping component " + getName());
         if (state == State.Started) {
+            // Stop deployed SAs
+            for (ServiceAssemblyImpl sa : getServiceAssemblies()) {
+                sa.stop(false);
+            }
+            // Stop component
             component.getLifeCycle().stop();
             state = State.Stopped;
             if (saveState) {
@@ -124,11 +152,16 @@
     }
 
     public void shutDown(boolean saveState) throws JBIException {
-        // TODO: shutdown deployed SAs
+        LOGGER.info("Shutting down component " + getName());
         if (state == State.Started) {
             stop(saveState);
         }
         if (state == State.Stopped) {
+            // Shutdown deployed SAs
+            for (ServiceAssemblyImpl sa : getServiceAssemblies()) {
+                sa.shutDown(false);
+            }
+            // Shutdown component
             component.getLifeCycle().shutDown();
             state = State.Shutdown;
             if (saveState) {

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
Thu Mar  6 12:43:55 2008
@@ -49,12 +49,10 @@
 import org.apache.xbean.classloader.MultiParentClassLoader;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.prefs.Preferences;
 import org.osgi.service.prefs.PreferencesService;
 import org.springframework.osgi.util.BundleDelegatingClassLoader;
-import org.springframework.osgi.util.OsgiServiceReferenceUtils;
 import org.springframework.osgi.util.OsgiStringUtils;
 
 /**
@@ -240,7 +238,7 @@
         // Check requirements
         for (ServiceUnitDesc sud : serviceAssembyDesc.getServiceUnits()) {
             String componentName = sud.getTarget().getComponentName();
-            Component component = getComponent(componentName);
+            ComponentImpl component = components.get(componentName);
             if (component == null) {
                 throw new PendingException(bundle, "Component not installed: " + componentName);
             }
@@ -265,7 +263,7 @@
             FileUtil.unpackArchive(zipUrl, suRootDir);
             // Find component
             String componentName = sud.getTarget().getComponentName();
-            Component component = getComponent(componentName);
+            ComponentImpl component = components.get(componentName);
             // Create service unit object
             ServiceUnitImpl su = new ServiceUnitImpl(sud, suRootDir, component);
             try {
@@ -370,16 +368,6 @@
             services.put(bundle, registrations);
         }
         registrations.add(reg);
-    }
-
-    protected Component getComponent(String name) {
-        String filter = "(" + NAME + "=" + name + ")";
-        BundleContext context = getBundleContext();
-        ServiceReference reference = OsgiServiceReferenceUtils.getServiceReference(context,
Component.class.getName(), filter);
-        if (reference != null) {
-            return (Component) context.getService(reference);
-        }
-        return null;
     }
 
     protected ClassLoader createComponentClassLoader(ComponentDesc component, Bundle bundle)
{

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
Thu Mar  6 12:43:55 2008
@@ -39,8 +39,6 @@
 
     private static final String STATE = "state";
 
-
-
     protected enum State {
         Unknown,
         Initialized,
@@ -67,7 +65,10 @@
         this.serviceUnits = serviceUnits;
         this.prefs = prefs;
         this.runningState = State.valueOf(this.prefs.get(STATE, (autoStart ? State.Started
: State.Initialized).name()));
-	}
+        for (ServiceUnitImpl su : serviceUnits) {
+            su.setServiceAssemblyImpl(this);
+        }
+    }
 
 	public String getName() {
 		return serviceAssemblyDesc.getIdentification().getName();

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java?rev=634410&r1=634409&r2=634410&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java
(original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceUnitImpl.java
Thu Mar  6 12:43:55 2008
@@ -25,7 +25,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.ServiceUnit;
+import org.apache.servicemix.jbi.deployer.SharedLibrary;
 import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
 
 
@@ -37,9 +39,11 @@
 	
 	private File rootDir;
 	
-	private Component component;
-	
-	public ServiceUnitImpl(ServiceUnitDesc serviceUnitDesc, File rootDir, Component component)
{
+	private ComponentImpl component;
+
+    private ServiceAssemblyImpl serviceAssembly;
+
+    public ServiceUnitImpl(ServiceUnitDesc serviceUnitDesc, File rootDir, ComponentImpl component)
{
 		this.serviceUnitDesc = serviceUnitDesc;
 		this.rootDir = rootDir;
         this.component = component;
@@ -61,12 +65,29 @@
 		return serviceUnitDesc.getTarget().getComponentName();
 	}
 
-	public File getRootDir() {
+    public ServiceAssembly getServiceAssembly() {
+        return serviceAssembly;
+    }
+
+    protected ServiceAssemblyImpl getServiceAssemblyImpl() {
+        return serviceAssembly;
+    }
+
+    protected void setServiceAssemblyImpl(ServiceAssemblyImpl serviceAssembly) {
+        this.serviceAssembly = serviceAssembly;
+    }
+
+    public Component getComponent() {
+        return component;
+    }
+
+    public File getRootDir() {
 		return rootDir;
 	}
 
     public void deploy() throws JBIException {
         component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir().getAbsolutePath());
+        component.addServiceUnit(this);
     }
 
 	public void init() throws JBIException {
@@ -90,6 +111,7 @@
 
     public void undeploy() throws JBIException {
         component.getComponent().getServiceUnitManager().undeploy(getName(), getRootDir().getAbsolutePath());
+        component.removeServiceUnit(this);
     }
 
     protected void checkComponentStarted(String task) throws DeploymentException {



Mime
View raw message