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 2008/10/03 14:44:21 UTC
svn commit: r701366 - in /servicemix/smx4/nmr/trunk/jbi/deployer: ./
src/main/java/org/apache/servicemix/jbi/deployer/
src/main/java/org/apache/servicemix/jbi/deployer/impl/
Author: gnodet
Date: Fri Oct 3 05:44:20 2008
New Revision: 701366
URL: http://svn.apache.org/viewvc?rev=701366&view=rev
Log:
SMX4NMR-24: JBI endpoints not using the JBI packaging should still abide by the JBI lifecycle to be able to cleanly shutdown a JBI application
Added:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
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/ServiceUnitImpl.java
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml?rev=701366&r1=701365&r2=701366&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/pom.xml Fri Oct 3 05:44:20 2008
@@ -54,7 +54,7 @@
</exclusion>
</exclusions>
</dependency>
- <dependency>
+ <dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-classloader</artifactId>
<version>${xbean.version}</version>
Added: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java?rev=701366&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/DeployedAssembly.java Fri Oct 3 05:44:20 2008
@@ -0,0 +1,31 @@
+/*
+ * 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.jbi.deployer;
+
+import java.util.Map;
+
+/**
+ * This interface should be used by service assemblies deployed using another packaging
+ * than the JBI packaging to be able to leverage the JBI life cycle.
+ */
+public interface DeployedAssembly {
+
+ String getName();
+
+ Map<String, String> getServiceUnits();
+
+}
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=701366&r1=701365&r2=701366&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 Fri Oct 3 05:44:20 2008
@@ -28,7 +28,6 @@
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.jbi.JBIException;
@@ -40,6 +39,7 @@
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.DeployedAssembly;
import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
@@ -48,6 +48,7 @@
import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryDesc;
import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
import org.apache.servicemix.jbi.deployer.descriptor.Identification;
+import org.apache.servicemix.jbi.deployer.descriptor.Target;
import org.apache.servicemix.jbi.runtime.ComponentWrapper;
import org.apache.xbean.classloader.MultiParentClassLoader;
import org.osgi.framework.Bundle;
@@ -93,6 +94,8 @@
private ServiceTracker tracker;
+ private ServiceTracker deployedAssembliesTracker;
+
public Deployer() throws JBIException{
sharedLibraries = new ConcurrentHashMap<String, SharedLibraryImpl>();
serviceAssemblies = new ConcurrentHashMap<String, ServiceAssemblyImpl>();
@@ -137,11 +140,26 @@
}
};
tracker.open();
+
+ deployedAssembliesTracker = new ServiceTracker(getBundleContext(), DeployedAssembly.class.getName(), null) {
+ public Object addingService(ServiceReference serviceReference) {
+ Object o = super.addingService(serviceReference);
+ registerDeployedServiceAssembly(serviceReference, (DeployedAssembly) o);
+ return o;
+ }
+
+ public void removedService(ServiceReference serviceReference, Object o) {
+ unregisterDeployedServiceAssembly(serviceReference, (DeployedAssembly) o);
+ super.removedService(serviceReference, o);
+ }
+ };
+ deployedAssembliesTracker.open();
}
@Override
public void destroy() throws Exception {
tracker.close();
+ deployedAssembliesTracker.close();
super.destroy();
}
@@ -324,6 +342,11 @@
}
return;
}
+ registerSA(serviceAssembyDesc, bundle, sus);
+
+ }
+
+ protected void registerSA(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle, List<ServiceUnitImpl> sus) throws JBIException {
// Now create the SA and initialize it
Preferences prefs = preferencesService.getUserPreferences(serviceAssembyDesc.getIdentification().getName());
ServiceAssemblyImpl sa = new ServiceAssemblyImpl(serviceAssembyDesc, sus, prefs, autoStart);
@@ -366,6 +389,10 @@
}
protected void undeployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
String name = serviceAssembyDesc.getIdentification().getName();
+ unregisterSA(name);
+ }
+
+ protected void unregisterSA(String name) throws JBIException {
ServiceAssemblyImpl sa = serviceAssemblies.remove(name);
if (sa != null) {
if (sa.getState() == ServiceAssemblyImpl.State.Started) {
@@ -483,4 +510,33 @@
}
}
+ public void registerDeployedServiceAssembly(ServiceReference serviceReference, DeployedAssembly assembly) {
+ try {
+ ServiceAssemblyDesc desc = new ServiceAssemblyDesc();
+ desc.setIdentification(new Identification());
+ desc.getIdentification().setName(assembly.getName());
+ List<ServiceUnitImpl> sus = new ArrayList<ServiceUnitImpl>();
+ for (Map.Entry<String, String> unit : assembly.getServiceUnits().entrySet()) {
+ ServiceUnitDesc suDesc = new ServiceUnitDesc();
+ suDesc.setIdentification(new Identification());
+ suDesc.getIdentification().setName(unit.getKey());
+ suDesc.setTarget(new Target());
+ suDesc.getTarget().setComponentName(unit.getValue());
+ ServiceUnitImpl su = new ServiceUnitImpl(suDesc, null, components.get(unit.getValue()));
+ sus.add(su);
+ }
+ registerSA(desc, serviceReference.getBundle(), sus);
+ } catch (Exception e) {
+ LOGGER.error("Error registering deployed service assembly", e);
+ }
+ }
+
+ public void unregisterDeployedServiceAssembly(ServiceReference serviceReference, DeployedAssembly assembly) {
+ try {
+ unregisterSA(assembly.getName());
+ } catch (Exception e) {
+ LOGGER.error("Error unregistering deployed service assembly", e);
+ }
+ }
+
}
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=701366&r1=701365&r2=701366&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 Fri Oct 3 05:44:20 2008
@@ -86,12 +86,12 @@
}
public void deploy() throws JBIException {
- component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir().getAbsolutePath());
+ component.getComponent().getServiceUnitManager().deploy(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
component.addServiceUnit(this);
}
public void init() throws JBIException {
- component.getComponent().getServiceUnitManager().init(getName(), getRootDir().getAbsolutePath());
+ component.getComponent().getServiceUnitManager().init(getName(), getRootDir() != null ? getRootDir().getAbsolutePath() : null);
}
public void start() throws JBIException {