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 2009/02/17 13:33:08 UTC
svn commit: r745010 [4/6] - in /servicemix/smx4/nmr/trunk: ./ assembly/
assembly/src/main/distribution/ant/ assembly/src/main/filtered-resources/
bundle/ jbi/ jbi/deployer/
jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/
jbi/deployer/src...
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=745010&r1=745009&r2=745010&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 Tue Feb 17 12:33:05 2009
@@ -17,15 +17,9 @@
package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.net.URL;
-import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -34,47 +28,54 @@
import javax.jbi.JBIException;
import javax.jbi.management.LifeCycleMBean;
+import javax.management.StandardMBean;
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.DeployedAssembly;
+import org.apache.servicemix.jbi.deployer.NamingStrategy;
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.artifacts.ComponentImpl;
+import org.apache.servicemix.jbi.deployer.artifacts.ServiceAssemblyImpl;
+import org.apache.servicemix.jbi.deployer.artifacts.ServiceUnitImpl;
+import org.apache.servicemix.jbi.deployer.artifacts.SharedLibraryImpl;
import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
+import org.apache.servicemix.jbi.deployer.descriptor.Identification;
import org.apache.servicemix.jbi.deployer.descriptor.ServiceAssemblyDesc;
import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
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.deployer.utils.FileUtil;
+import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
import org.apache.servicemix.jbi.runtime.ComponentWrapper;
+import org.apache.servicemix.jbi.runtime.Environment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.prefs.Preferences;
import org.osgi.service.prefs.PreferencesService;
import org.osgi.util.tracker.ServiceTracker;
-import org.springframework.osgi.util.BundleDelegatingClassLoader;
import org.springframework.osgi.util.OsgiStringUtils;
/**
* Deployer for JBI artifacts
- *
*/
public class Deployer extends AbstractBundleWatcher {
public static final String NAME = "NAME";
public static final String TYPE = "TYPE";
+ public static final String TYPE_SERVICE_ENGINE = "service-engine";
+ public static final String TYPE_BINDING_COMPONENT = "binding-component";
private static final Log LOGGER = LogFactory.getLog(Deployer.class);
- private static final String JBI_DESCRIPTOR = "META-INF/jbi.xml";
-
private Map<String, SharedLibraryImpl> sharedLibraries;
private Map<String, ServiceAssemblyImpl> serviceAssemblies;
@@ -98,7 +99,20 @@
private ServiceTracker deployedAssembliesTracker;
private AssemblyReferencesListener endpointListener;
- public Deployer() throws JBIException{
+ private ThreadLocal<ComponentInstaller> componentInstaller = new ThreadLocal<ComponentInstaller>();
+
+ private NamingStrategy namingStrategy;
+ private ManagementAgent managementAgent;
+
+ private Runnable checkPendingBundlesCallback;
+ private Environment environment;
+
+ public Deployer() throws JBIException {
+ checkPendingBundlesCallback = new Runnable() {
+ public void run() {
+ checkPendingBundles();
+ }
+ };
sharedLibraries = new ConcurrentHashMap<String, SharedLibraryImpl>();
serviceAssemblies = new ConcurrentHashMap<String, ServiceAssemblyImpl>();
components = new ConcurrentHashMap<String, ComponentImpl>();
@@ -134,6 +148,30 @@
return endpointListener;
}
+ public NamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ public void setNamingStrategy(NamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
+
+ public ManagementAgent getManagementAgent() {
+ return managementAgent;
+ }
+
+ public void setManagementAgent(ManagementAgent managementAgent) {
+ this.managementAgent = managementAgent;
+ }
+
+ public ComponentInstaller getComponentInstaller() {
+ return componentInstaller.get();
+ }
+
+ public void setComponentInstaller(ComponentInstaller installer) {
+ componentInstaller.set(installer);
+ }
+
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
@@ -176,7 +214,7 @@
@Override
protected boolean match(Bundle bundle) {
LOGGER.debug("Checking bundle: '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "'");
- URL url = bundle.getResource(JBI_DESCRIPTOR);
+ URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
if (url == null) {
LOGGER.debug("Bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' does not contain any JBI descriptor.");
return false;
@@ -189,7 +227,7 @@
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- URL url = bundle.getResource(JBI_DESCRIPTOR);
+ URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
Descriptor descriptor = DescriptorFactory.buildDescriptor(url);
DescriptorFactory.checkDescriptor(descriptor);
if (descriptor.getComponent() != null) {
@@ -217,16 +255,16 @@
pendingBundles.remove(bundle);
List<ServiceRegistration> registrations = services.remove(bundle);
if (registrations != null) {
- for (ServiceRegistration reg : registrations) {
+ for (ServiceRegistration reg : registrations) {
try {
- reg.unregister();
+ reg.unregister();
} catch (IllegalStateException e) {
// Ignore
}
}
}
try {
- URL url = bundle.getResource(JBI_DESCRIPTOR);
+ URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
Descriptor descriptor = DescriptorFactory.buildDescriptor(url);
if (descriptor.getComponent() != null) {
uninstallComponent(descriptor.getComponent(), bundle);
@@ -240,30 +278,33 @@
}
}
- protected void installComponent(ComponentDesc componentDesc, Bundle bundle) throws Exception {
+ protected void installComponent(final ComponentDesc componentDesc, Bundle bundle) throws Exception {
LOGGER.info("Deploying bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' as a JBI component");
- // Check requirements
- if (componentDesc.getSharedLibraries() != null) {
- for (SharedLibraryList sl : componentDesc.getSharedLibraries()) {
- if (sharedLibraries.get(sl.getName()) == null) {
- throw new PendingException(bundle, "SharedLibrary not installed: " + sl.getName());
+ // If an installer has been registered, this means that we are using JMX or ant tasks to deploy the JBI artifact.
+ // In such a case, let the installer do the work.
+ // Else, the bundle has been deployed through the deploy folder or the command line or any other
+ // non JBI way, which means we need to create an installer and install the component now.
+ if (getComponentInstaller() == null) {
+ // Check requirements
+ if (componentDesc.getSharedLibraries() != null) {
+ for (SharedLibraryList sl : componentDesc.getSharedLibraries()) {
+ if (sharedLibraries.get(sl.getName()) == null) {
+ throw new PendingException(bundle, "SharedLibrary not installed: " + sl.getName());
+ }
}
}
+ ComponentInstaller installer = new ComponentInstaller(this, componentDesc, null);
+ installer.setAutoStart(true);
+ installer.setBundle(bundle);
+ installer.init();
+ installer.install();
}
+ }
+
+ public Component registerComponent(Bundle bundle, ComponentDesc componentDesc, javax.jbi.component.Component innerComponent) throws Exception {
String name = componentDesc.getIdentification().getName();
- // Create component class loader
- ClassLoader classLoader = createComponentClassLoader(componentDesc, bundle);
- Thread.currentThread().setContextClassLoader(classLoader);
- // Extract component (needed to feed the installRoot)
- // Few components actually use this, but Ode is one of them
- File installRoot = new File(System.getProperty("servicemix.base"), "data/jbi/" + name + "/install");
- installRoot.mkdirs();
- extractBundle(installRoot, bundle, "/");
- // Instanciate component
Preferences prefs = preferencesService.getUserPreferences(name);
- Class clazz = classLoader.loadClass(componentDesc.getComponentClassName());
- javax.jbi.component.Component innerComponent = (javax.jbi.component.Component) clazz.newInstance();
- ComponentImpl component = new ComponentImpl(componentDesc, innerComponent, prefs, autoStart, this);
+ ComponentImpl component = new ComponentImpl(componentDesc, innerComponent, prefs, autoStart, checkPendingBundlesCallback);
components.put(name, component);
// populate props from the component meta-data
Dictionary<String, String> props = new Hashtable<String, String>();
@@ -274,35 +315,18 @@
registerService(bundle, Component.class.getName(), component, props);
registerService(bundle, ComponentWrapper.class.getName(), component, props);
registerService(bundle, javax.jbi.component.Component.class.getName(), innerComponent, props);
- }
-
- private void extractBundle(File installRoot, Bundle bundle, String path) throws IOException {
- Enumeration e = bundle.getEntryPaths(path);
- while (e != null && e.hasMoreElements()) {
- String entry = (String) e.nextElement();
- File fout = new File(installRoot, entry);
- if (entry.endsWith("/")) {
- fout.mkdirs();
- extractBundle(installRoot, bundle, entry);
- } else {
- InputStream in = bundle.getEntry(entry).openStream();
- OutputStream out = new FileOutputStream(fout);
- try {
- FileUtil.copyInputStream(in, out);
- } finally {
- in.close();
- out.close();
- }
- }
- }
+ getManagementAgent().register(new StandardMBean(component, Component.class),
+ getNamingStrategy().getObjectName(component));
+ return component;
}
protected void deployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
+ // TODO: use servce assembly installer
LOGGER.info("Deploying bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' as a JBI service assembly");
// Check requirements
for (ServiceUnitDesc sud : serviceAssembyDesc.getServiceUnits()) {
String componentName = sud.getTarget().getComponentName();
- ComponentImpl component = components.get(componentName);
+ Component component = QueryUtils.getComponent(getBundleContext(), componentName);
if (component == null) {
throw new PendingException(bundle, "Component not installed: " + componentName);
}
@@ -357,10 +381,10 @@
}
- protected void registerSA(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle, List<ServiceUnitImpl> sus) throws JBIException {
+ protected void registerSA(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle, List<ServiceUnitImpl> sus) throws Exception {
// Now create the SA and initialize it
Preferences prefs = preferencesService.getUserPreferences(serviceAssembyDesc.getIdentification().getName());
- ServiceAssemblyImpl sa = new ServiceAssemblyImpl(serviceAssembyDesc, sus, prefs, endpointListener, autoStart);
+ ServiceAssemblyImpl sa = new ServiceAssemblyImpl(bundle, serviceAssembyDesc, sus, prefs, endpointListener, autoStart);
sa.init();
serviceAssemblies.put(sa.getName(), sa);
// populate props from the component meta-data
@@ -369,9 +393,12 @@
// register the service assembly in the OSGi registry
LOGGER.debug("Registering JBI service assembly");
registerService(bundle, ServiceAssembly.class.getName(), sa, props);
+ getManagementAgent().register(new StandardMBean(sa, ServiceAssembly.class),
+ getNamingStrategy().getObjectName(sa));
}
- protected void installSharedLibrary(SharedLibraryDesc sharedLibraryDesc, Bundle bundle) {
+ protected void installSharedLibrary(SharedLibraryDesc sharedLibraryDesc, Bundle bundle) throws Exception {
+ // TODO: use shared library installer
LOGGER.info("Deploying bundle '" + OsgiStringUtils.nullSafeNameAndSymName(bundle) + "' as a JBI shared library");
SharedLibraryImpl sl = new SharedLibraryImpl(sharedLibraryDesc, bundle);
sharedLibraries.put(sl.getName(), sl);
@@ -380,6 +407,8 @@
props.put(NAME, sharedLibraryDesc.getIdentification().getName());
LOGGER.debug("Registering JBI Shared Library");
registerService(bundle, SharedLibrary.class.getName(), sl, props);
+ getManagementAgent().register(new StandardMBean(sl, SharedLibrary.class),
+ getNamingStrategy().getObjectName(sl));
// Check pending bundles
checkPendingBundles();
}
@@ -401,6 +430,7 @@
FileUtil.deleteFile(file);
}
}
+
protected void undeployServiceAssembly(ServiceAssemblyDesc serviceAssembyDesc, Bundle bundle) throws Exception {
String name = serviceAssembyDesc.getIdentification().getName();
unregisterSA(name);
@@ -434,7 +464,7 @@
componentDesc.setIdentification(new Identification());
componentDesc.getIdentification().setName(name);
componentDesc.setType(type);
- ComponentImpl wrapper = new ComponentImpl(componentDesc, component, prefs, autoStart, this);
+ ComponentImpl wrapper = new ComponentImpl(componentDesc, component, prefs, autoStart, checkPendingBundlesCallback);
wrappedComponents.put(name, true);
components.put(name, wrapper);
Dictionary<String, String> props = new Hashtable<String, String>();
@@ -456,11 +486,11 @@
pendingBundles.remove(reference.getBundle());
List<ServiceRegistration> registrations = services.remove(reference.getBundle());
if (registrations != null) {
- for (ServiceRegistration reg : registrations) {
+ for (ServiceRegistration reg : registrations) {
try {
- reg.unregister();
+ reg.unregister();
} catch (IllegalStateException e) {
- e.printStackTrace();
+ e.printStackTrace();
// Ignore
}
}
@@ -495,58 +525,6 @@
registrations.add(reg);
}
- protected ClassLoader createComponentClassLoader(ComponentDesc component, Bundle bundle) {
- // Create parents classloaders
- ClassLoader[] parents;
- if (component.getSharedLibraries() != null) {
- parents = new ClassLoader[component.getSharedLibraries().length + 2];
- for (int i = 0; i < component.getSharedLibraries().length; i++) {
- parents[i + 2] = getSharedLibraryClassLoader(component.getSharedLibraries()[i]);
- }
- } else {
- parents = new ClassLoader[2];
- }
- parents[0] = BundleDelegatingClassLoader.createBundleClassLoaderFor(getBundleContext().getBundle(0));
- parents[1] = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle, getClass().getClassLoader());
-
- // Create urls
- String[] classPathNames = component.getComponentClassPath().getPathElements();
- URL[] urls = new URL[classPathNames.length];
- for (int i = 0; i < classPathNames.length; i++) {
- urls[i] = bundle.getResource(classPathNames[i]);
- if (urls[i] == null) {
- throw new IllegalArgumentException("SharedLibrary classpath entry not found: '" + classPathNames[i] + "'");
- }
- Enumeration en = bundle.findEntries(classPathNames[i], null, false);
- if (en != null && en.hasMoreElements()) {
- try {
- urls[i] = new URL(urls[i].toString() + "/");
- } catch (MalformedURLException e) {
- // Ignore
- }
- }
- }
-
- // Create classloader
- return new OsgiMultiParentClassLoader(
- bundle,
- component.getIdentification().getName(),
- urls,
- parents,
- component.isComponentClassLoaderDelegationSelfFirst(),
- new String[] {"javax.xml.bind"},
- new String[] {"java.", "javax." });
- }
-
- protected ClassLoader getSharedLibraryClassLoader(SharedLibraryList sharedLibraryList) {
- SharedLibraryImpl sl = sharedLibraries.get(sharedLibraryList.getName());
- if (sl != null) {
- return sl.getClassLoader();
- } else {
- throw new IllegalStateException("SharedLibrary not installed: " + sharedLibraryList.getName());
- }
- }
-
public void registerDeployedServiceAssembly(ServiceReference serviceReference, DeployedAssembly assembly) {
try {
assembly.deploy();
@@ -576,17 +554,24 @@
LOGGER.error("Error unregistering deployed service assembly", e);
}
}
-
+
public Set<String> getInstalledComponents() {
- return this.components.keySet();
+ return this.components.keySet();
}
-
+
public Set<String> getInstalledSharedLibararies() {
- return this.sharedLibraries.keySet();
+ return this.sharedLibraries.keySet();
}
-
+
public Set<String> getDeployServiceAssemblies() {
- return this.serviceAssemblies.keySet();
+ return this.serviceAssemblies.keySet();
}
+ public void setEnvironment(Environment environment) {
+ this.environment = environment;
+ }
+
+ public Environment getEnvironment() {
+ return environment;
+ }
}
Copied: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java (from r744748, servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java?p2=servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java&p1=servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java&r1=744748&r2=745010&rev=745010&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java Tue Feb 17 12:33:05 2009
@@ -14,14 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.management;
+package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
-import java.util.Map;
+import java.util.HashSet;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import javax.jbi.JBIException;
import javax.jbi.management.DeploymentServiceMBean;
import javax.jbi.management.LifeCycleMBean;
@@ -29,31 +27,41 @@
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.descriptor.Descriptor;
+import org.apache.servicemix.jbi.deployer.descriptor.DescriptorFactory;
import org.apache.servicemix.jbi.deployer.descriptor.ServiceAssemblyDesc;
import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
import org.apache.servicemix.jbi.deployer.handler.Transformer;
-import org.apache.servicemix.jbi.deployer.impl.ComponentImpl;
-import org.apache.servicemix.jbi.deployer.impl.Deployer;
-import org.apache.servicemix.jbi.deployer.impl.ServiceAssemblyImpl;
+import org.apache.servicemix.jbi.deployer.utils.ManagementSupport;
+import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.context.BundleContextAware;
-public class DeploymentService implements DeploymentServiceMBean {
-
- private static final Log LOG = LogFactory.getLog(DeploymentService.class);
- private AdminService adminService;
-
- private Map<String, ServiceAssemblyInstaller> serviceAssemblyInstallers = new ConcurrentHashMap<String, ServiceAssemblyInstaller>();
+public class DeploymentService implements DeploymentServiceMBean, BundleContextAware {
+
+ private static final Log LOG = LogFactory.getLog(DeploymentService.class);
+
+ private BundleContext bundleContext;
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
public String deploy(String saZipURL) throws Exception {
- try {
+ try {
if (saZipURL == null) {
throw ManagementSupport.failure("deploy", "saZipURL must not be null");
}
File jarfile = new File(saZipURL);
- if (jarfile.exists()) {
- Descriptor root = null;
+ if (jarfile.exists() && jarfile.isFile()) {
+ Descriptor root;
try {
root = Transformer.getDescriptor(jarfile);
} catch (Exception e) {
@@ -62,96 +70,76 @@
if (root == null) {
throw ManagementSupport.failure("deploy", "Unable to find jbi descriptor: " + saZipURL);
}
+ DescriptorFactory.checkDescriptor(root);
ServiceAssemblyDesc sa = root.getServiceAssembly();
if (sa == null) {
throw ManagementSupport.failure("deploy", "JBI descriptor is not an assembly descriptor: " + saZipURL);
}
- return deployServiceAssembly(saZipURL, sa);
+ checkSus(sa.getServiceUnits());
+ String name = sa.getIdentification().getName();
+ LOG.info("Deploy ServiceAssembly " + name);
+ ServiceAssemblyInstaller saInstaller = new ServiceAssemblyInstaller(bundleContext, name);
+ saInstaller.deploy(saZipURL);
+ return ManagementSupport.createSuccessMessage("deploy SA", name);
} else {
- throw new RuntimeException("location for deployment SA: " + saZipURL + " isn't valid");
+ throw new RuntimeException("location for deployment SA: " + saZipURL + " isn't a valid file");
}
-
- } catch (Exception e) {
+
+ } catch (Exception e) {
LOG.error("Error deploying service assembly", e);
throw e;
}
}
- private String deployServiceAssembly(String saZipURL, ServiceAssemblyDesc sa) throws Exception {
- String assemblyName = sa.getIdentification().getName();
-
- // Check all SUs requirements
- ServiceUnitDesc[] sus = sa.getServiceUnits();
+ private void checkSus(ServiceUnitDesc[] sus) throws Exception {
if (sus != null) {
- checkSus(sus);
- }
- LOG.info("Deploy ServiceAssembly " + assemblyName);
- ServiceAssemblyInstaller saInstaller;
- if (serviceAssemblyInstallers.containsKey(assemblyName)) {
- saInstaller = serviceAssemblyInstallers.get(assemblyName);
- } else {
- saInstaller = new ServiceAssemblyInstaller(assemblyName, this.getAdminService());
- }
- saInstaller.deploy(saZipURL);
- serviceAssemblyInstallers.put(assemblyName, saInstaller);
- return ManagementSupport.createSuccessMessage("deploy SA", assemblyName);
- }
-
- private void checkSus(ServiceUnitDesc[] sus) throws Exception {
- for (int i = 0; i < sus.length; i++) {
- String suName = sus[i].getIdentification().getName();
- String componentName = sus[i].getTarget().getComponentName();
- ComponentImpl componentImpl = (ComponentImpl) getComponentByName(componentName);
- if (componentImpl == null) {
- throw ManagementSupport.failure("deploy", "Target component " + componentName
- + " for service unit " + suName + " is not installed");
- }
- if (!componentImpl.getCurrentState().equals(LifeCycleMBean.STARTED)) {
- throw ManagementSupport.failure("deploy", "Target component " + componentName
- + " for service unit " + suName + " is not started");
- }
- if (componentImpl.getComponent().getServiceUnitManager() == null) {
- throw ManagementSupport.failure("deploy", "Target component " + componentName
- + " for service unit " + suName + " does not accept deployments");
- }
-
- if (isDeployedServiceUnit(componentName, suName)) {
- throw ManagementSupport.failure("deploy", "Service unit " + suName
- + " is already deployed on component " + componentName);
- }
- }
- }
+ for (int i = 0; i < sus.length; i++) {
+ String suName = sus[i].getIdentification().getName();
+ String componentName = sus[i].getTarget().getComponentName();
+ Component component = QueryUtils.getComponent(bundleContext, componentName);
+ if (component == null) {
+ throw ManagementSupport.failure("deploy", "Target component " + componentName
+ + " for service unit " + suName + " is not installed");
+ }
+ if (!component.getCurrentState().equals(LifeCycleMBean.STARTED)) {
+ throw ManagementSupport.failure("deploy", "Target component " + componentName
+ + " for service unit " + suName + " is not started");
+ }
+ if (component.getComponent().getServiceUnitManager() == null) {
+ throw ManagementSupport.failure("deploy", "Target component " + componentName
+ + " for service unit " + suName + " does not accept deployments");
+ }
- private Component getComponentByName(String name) throws Exception {
- ServiceReference ref = getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + name + ")");
- if (ref == null) {
- throw new JBIException("Component '" + name + "' not found");
+ if (isDeployedServiceUnit(componentName, suName)) {
+ throw ManagementSupport.failure("deploy", "Service unit " + suName
+ + " is already deployed on component " + componentName);
+ }
+ }
}
- Component component = (Component) getAdminService().getBundleContext().getService(ref);
- return component;
- }
-
- public String undeploy(String saName) throws Exception {
- if (saName == null) {
+ }
+
+ public String undeploy(String saName) throws Exception {
+ if (saName == null) {
throw ManagementSupport.failure("undeploy", "SA name must not be null");
}
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + saName + ")");
- if (ref == null) {
+ ServiceReference ref = QueryUtils.getServiceAssemblyServiceReference(bundleContext, "(" + Deployer.NAME + "=" + saName + ")");
+ if (ref == null) {
throw ManagementSupport.failure("undeploy", "SA has not been deployed: " + saName);
}
Bundle bundle = ref.getBundle();
- ServiceAssemblyImpl sa = (ServiceAssemblyImpl) getAdminService().getBundleContext().getService(ref);
-
-
+ ServiceAssembly sa = (ServiceAssembly) bundleContext.getService(ref);
+
+
String state = sa.getCurrentState();
if (!LifeCycleMBean.SHUTDOWN.equals(state)) {
throw ManagementSupport.failure("undeploy", "SA must be shut down: " + saName);
}
try {
+ // TODO: shutdown sa before uninstalling bundle
if (bundle != null) {
- bundle.stop();
- bundle.uninstall();
- return ManagementSupport.createSuccessMessage("undeploy service assembly successfully", saName);
+ bundle.stop();
+ bundle.uninstall();
+ return ManagementSupport.createSuccessMessage("undeploy service assembly successfully", saName);
}
} catch (Exception e) {
@@ -162,61 +150,47 @@
}
public String[] getDeployedServiceUnitList(String componentName) throws Exception {
- return getAdminService().getDeployedServiceUnitsForComponent(componentName);
+ Component component = QueryUtils.getComponent(bundleContext, componentName);
+ ServiceUnit[] serviceUnits = component.getServiceUnits();
+ String[] sus = new String[serviceUnits.length];
+ for (int i = 0; i < serviceUnits.length; i++) {
+ sus[i] = serviceUnits[i].getName();
+ }
+ return sus;
}
public String[] getDeployedServiceAssemblies() throws Exception {
- String[] ret = null;
- Set<String> sas = getAdminService().getDeployer().getDeployServiceAssemblies();
- ret = new String[sas.size()];
- sas.toArray(ret);
- return ret;
- }
-
- public String getServiceAssemblyDescriptor(String saName) throws Exception {
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + saName + ")");
- if (ref == null) {
- throw new JBIException("ServiceAssembly '" + saName + "' not found");
+ ServiceAssembly[] assemblies = QueryUtils.getAllServiceAssemblies(bundleContext);
+ String[] sas = new String[assemblies.length];
+ for (int i = 0; i < assemblies.length; i++) {
+ sas[i] = assemblies[i].getName();
}
- ServiceAssembly sa = (ServiceAssembly) getAdminService().getBundleContext().getService(ref);
- return sa.getDescription();
- }
-
- public String[] getDeployedServiceAssembliesForComponent(String componentName) throws Exception {
- return getAdminService().getDeployedServiceAssembliesForComponent(componentName);
- }
-
- public String[] getComponentsForDeployedServiceAssembly(String saName) throws Exception {
- return getAdminService().getComponentsForDeployedServiceAssembly(saName);
+ return sas;
}
- public boolean isDeployedServiceUnit(String componentName, String suName) throws Exception {
- return getAdminService().isDeployedServiceUnit(componentName, suName);
+ public String getServiceAssemblyDescriptor(String saName) throws Exception {
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(bundleContext, saName);
+ return sa != null ? sa.getDescriptor() : null;
}
public boolean canDeployToComponent(String componentName) {
- ServiceReference ref = getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + componentName + ")");
- if (ref == null) {
- return false;
- }
- ComponentImpl componentImpl = (ComponentImpl) getAdminService().getBundleContext().getService(ref);
- return componentImpl != null
- && componentImpl.getCurrentState() == LifeCycleMBean.STARTED
- && componentImpl.getComponent().getServiceUnitManager() != null;
+ Component component = QueryUtils.getComponent(bundleContext, componentName);
+ return component != null
+ && LifeCycleMBean.STARTED.equals(component.getCurrentState())
+ && component.getComponent().getServiceUnitManager() != null;
}
public String start(String serviceAssemblyName) throws Exception {
- try {
- if (serviceAssemblyName == null) {
+ try {
+ if (serviceAssemblyName == null) {
throw ManagementSupport.failure("start", "SA name must not be null");
}
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + serviceAssemblyName + ")");
- if (ref == null) {
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(bundleContext, serviceAssemblyName);
+ if (sa == null) {
throw ManagementSupport.failure("start", "SA has not exist: " + serviceAssemblyName);
}
- ServiceAssemblyImpl sa = (ServiceAssemblyImpl) getAdminService().getBundleContext().getService(ref);
- sa.start();
- return ManagementSupport.createSuccessMessage("start service assembly successfully", serviceAssemblyName);
+ sa.start();
+ return ManagementSupport.createSuccessMessage("start service assembly successfully", serviceAssemblyName);
} catch (Exception e) {
LOG.info("Error in start", e);
throw e;
@@ -224,17 +198,16 @@
}
public String stop(String serviceAssemblyName) throws Exception {
- try {
- if (serviceAssemblyName == null) {
+ try {
+ if (serviceAssemblyName == null) {
throw ManagementSupport.failure("stop", "SA name must not be null");
}
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + serviceAssemblyName + ")");
- if (ref == null) {
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(bundleContext, serviceAssemblyName);
+ if (sa == null) {
throw ManagementSupport.failure("stop", "SA has not exist: " + serviceAssemblyName);
}
- ServiceAssemblyImpl sa = (ServiceAssemblyImpl) getAdminService().getBundleContext().getService(ref);
- sa.stop();
- return ManagementSupport.createSuccessMessage("stop service assembly successfully", serviceAssemblyName);
+ sa.stop();
+ return ManagementSupport.createSuccessMessage("stop service assembly successfully", serviceAssemblyName);
} catch (Exception e) {
LOG.info("Error in stop", e);
throw e;
@@ -242,17 +215,16 @@
}
public String shutDown(String serviceAssemblyName) throws Exception {
- try {
- if (serviceAssemblyName == null) {
+ try {
+ if (serviceAssemblyName == null) {
throw ManagementSupport.failure("shutdown", "SA name must not be null");
}
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + serviceAssemblyName + ")");
- if (ref == null) {
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(bundleContext, serviceAssemblyName);
+ if (sa == null) {
throw ManagementSupport.failure("shutdown", "SA has not exist: " + serviceAssemblyName);
}
- ServiceAssemblyImpl sa = (ServiceAssemblyImpl) getAdminService().getBundleContext().getService(ref);
- sa.shutDown();
- return ManagementSupport.createSuccessMessage("shutdown service assembly successfully", serviceAssemblyName);
+ sa.shutDown();
+ return ManagementSupport.createSuccessMessage("shutdown service assembly successfully", serviceAssemblyName);
} catch (Exception e) {
LOG.info("Error in shutdown", e);
throw e;
@@ -260,30 +232,104 @@
}
public String getState(String serviceAssemblyName) throws Exception {
- try {
- if (serviceAssemblyName == null) {
+ try {
+ if (serviceAssemblyName == null) {
throw ManagementSupport.failure("getState", "SA name must not be null");
}
- ServiceReference ref = getAdminService().getSAServiceReference("(" + Deployer.NAME + "=" + serviceAssemblyName + ")");
- if (ref == null) {
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(bundleContext, serviceAssemblyName);
+ if (sa == null) {
throw ManagementSupport.failure("getState", "SA has not exist: " + serviceAssemblyName);
}
- ServiceAssemblyImpl sa = (ServiceAssemblyImpl) getAdminService().getBundleContext().getService(ref);
- sa.getState();
- return ManagementSupport.createSuccessMessage("getState service assembly successfully", serviceAssemblyName);
+ return sa.getCurrentState();
} catch (Exception e) {
LOG.info("Error in getState", e);
throw e;
}
}
- public void setAdminService(AdminService adminService) {
- this.adminService = adminService;
- }
-
- public AdminService getAdminService() {
- return adminService;
- }
-
-
+ /**
+ * Returns a list of Service Assemblies that contain SUs for the given component.
+ *
+ * @param componentName name of the component.
+ * @return list of Service Assembly names.
+ */
+ public String[] getDeployedServiceAssembliesForComponent(String componentName) {
+ String[] result;
+ // iterate through the service assemblies
+ Set<String> tmpList = new HashSet<String>();
+ ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
+ for (ServiceReference ref : serviceRefs) {
+ ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
+ for (ServiceUnit su : sa.getServiceUnits()) {
+ if (su.getComponent().getName().equals(componentName)) {
+ tmpList.add(sa.getName());
+ }
+ }
+ }
+ result = new String[tmpList.size()];
+ tmpList.toArray(result);
+ return result;
+ }
+
+ public String[] getDeployedServiceUnitsForComponent(String componentName) {
+ String[] result;
+ // iterate through the service assembilies
+ Set<String> tmpList = new HashSet<String>();
+ ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
+ for (ServiceReference ref : serviceRefs) {
+ ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
+ for (ServiceUnit su : sa.getServiceUnits()) {
+ if (su.getComponent().getName().equals(componentName)) {
+ tmpList.add(su.getName());
+ }
+ }
+ }
+ result = new String[tmpList.size()];
+ tmpList.toArray(result);
+ return result;
+ }
+
+ public String[] getComponentsForDeployedServiceAssembly(String saName) {
+ String[] result;
+ // iterate through the service assembilies
+ Set<String> tmpList = new HashSet<String>();
+ ServiceAssembly sa = QueryUtils.getServiceAssembly(getBundleContext(), saName);
+ if (sa != null) {
+ for (ServiceUnit su : sa.getServiceUnits()) {
+ if (su.getComponent().getName().equals(saName)) {
+ tmpList.add(su.getComponent().getName());
+ }
+ }
+ }
+ result = new String[tmpList.size()];
+ tmpList.toArray(result);
+ return result;
+ }
+
+ /**
+ * Returns a boolean value indicating whether the SU is currently deployed.
+ *
+ * @param componentName - name of component.
+ * @param suName - name of the Service Unit.
+ * @return boolean value indicating whether the SU is currently deployed.
+ */
+ public boolean isDeployedServiceUnit(String componentName, String suName) {
+ boolean result = false;
+ ServiceReference[] serviceRefs = QueryUtils.getServiceAssembliesServiceReferences(getBundleContext(), null);
+ for (ServiceReference ref : serviceRefs) {
+ ServiceAssembly sa = (ServiceAssembly) getBundleContext().getService(ref);
+ ServiceUnit[] sus = sa.getServiceUnits();
+ if (sus != null) {
+ for (int i = 0; i < sus.length; i++) {
+ if (sus[i].getComponent().getName().equals(componentName)
+ && sus[i].getName().equals(suName)) {
+ result = true;
+ break;
+ }
+ }
+ }
+ }
+ return result;
+ }
+
}
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/DeploymentService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java (from r744748, servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java?p2=servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java&p1=servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java&r1=744748&r2=745010&rev=745010&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java Tue Feb 17 12:33:05 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.management;
+package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
import java.util.ArrayList;
@@ -40,27 +40,31 @@
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
+import org.apache.servicemix.jbi.deployer.NamingStrategy;
import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
import org.apache.servicemix.jbi.deployer.descriptor.InstallationDescriptorExtension;
import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
+import org.apache.servicemix.jbi.runtime.Environment;
/**
* This context contains information necessary for a JBI component to perform its installation/uninstallation
- * processing. This is provided to the init() method of the component {@link javax.jbi.component.Bootstrap}interface.
- *
+ * processing. This is provided to the init() method of the component's {@link javax.jbi.component.Bootstrap} interface.
*/
public class InstallationContextImpl implements InstallationContext, ComponentContext, MBeanNames {
private ComponentDesc descriptor;
private NamingStrategy namingStrategy;
private ManagementAgent managementAgent;
+ private Environment environment;
private File installRoot;
private List<String> classPathElements = Collections.emptyList();
private boolean install = true;
- public InstallationContextImpl(ComponentDesc descriptor, NamingStrategy namingStrategy,
- ManagementAgent managementAgent) {
+ public InstallationContextImpl(ComponentDesc descriptor,
+ Environment environment,
+ NamingStrategy namingStrategy,
+ ManagementAgent managementAgent) {
this.descriptor = descriptor;
this.namingStrategy = namingStrategy;
this.managementAgent = managementAgent;
@@ -111,7 +115,7 @@
* <code>File.separator</code>).
*
* @return a list of String objects, each of which contains a class path elements. The list must contain at least
- * one class path element.
+ * one class path element.
*/
public List getClassPathElements() {
return classPathElements;
@@ -156,12 +160,12 @@
/**
* Return a DOM document fragment representing the installation descriptor (jbi.xml) extension data for the
* component, if any.
- * <p>
+ * <p/>
* The Installation Descriptor Extension data are located at the end of the <component> element of the
* installation descriptor.
*
* @return a DOM document fragment containing the installation descriptor (jbi.xml) extension data, or
- * <code>null</code> if none is present in the descriptor.
+ * <code>null</code> if none is present in the descriptor.
*/
public DocumentFragment getInstallationDescriptorExtension() {
InstallationDescriptorExtension desc = descriptor.getDescriptorExtension();
@@ -171,13 +175,13 @@
/**
* Returns <code>true</code> if this context was created in order to install a component into the JBI environment.
* Returns <code>false</code> if this context was created to uninstall a previously installed component.
- * <p>
+ * <p/>
* This method is provided to allow {@link javax.jbi.component.Bootstrap}implementations to tailor their behaviour according to use
* case. For example, the {@link javax.jbi.component.Bootstrap#init(InstallationContext)}method implementation may create different
* types of extension MBeans, depending on the use case specified by this method.
*
* @return <code>true</code> if this context was created in order to install a component into the JBI environment;
- * otherwise the context was created to uninstall an existing component.
+ * otherwise the context was created to uninstall an existing component.
*/
public boolean isInstall() {
return install;
@@ -188,16 +192,16 @@
* directory (containing class files) or a library file. Elements are reached from the install root. These elements
* represent class path items that the component's execution-time component class loader uses, in search order. All
* file paths are relative to the install root of the component.
- * <p>
+ * <p/>
* This method allows the component's bootstrap to alter the execution-time class path specified by the component's
* installation descriptor. The component configuration determined during installation can affect the class path
* needed by the component at execution-time. All path elements must use the file separator character appropriate to
* the system (i.e., <code>File.separator</code>.
*
* @param classPathElements a list of String objects, each of which contains a class path elements; the list must be
- * non-null and contain at least one class path element.
- * @exception IllegalArgumentException if the class path elements is null, empty, or if an individual element is
- * ill-formed.
+ * non-null and contain at least one class path element.
+ * @throws IllegalArgumentException if the class path elements is null, empty, or if an individual element is
+ * ill-formed.
*/
public final void setClassPathElements(List classPathElements) {
if (classPathElements == null) {
@@ -217,7 +221,7 @@
if (offset > -1) {
throw new IllegalArgumentException("classPathElements contains an invalid file separator '" + sep + "'");
}
- File f = new File((String) element);
+ File f = new File(element);
if (f.isAbsolute()) {
throw new IllegalArgumentException("classPathElements should not contain absolute paths");
}
@@ -305,24 +309,28 @@
public void setInstall(boolean install) {
this.install = install;
}
+
/**
* @param installRoot The installRoot to set.
*/
public void setInstallRoot(File installRoot) {
this.installRoot = installRoot;
}
+
/**
* @return Returns the binding.
*/
public boolean isBinding() {
return descriptor.isBindingComponent();
}
+
/**
* @return Returns the engine.
*/
public boolean isEngine() {
return descriptor.isServiceEngine();
}
+
/**
* @return Returns the componentDescription.
*/
@@ -341,18 +349,16 @@
return names;
}
- public MBeanServer getMBeanServer() {
- return managementAgent.getMbeanServer();
- }
-
- public InitialContext getNamingContext() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Object getTransactionManager() {
- // TODO Auto-generated method stub
- return null;
- }
+ public MBeanServer getMBeanServer() {
+ return managementAgent.getMbeanServer();
+ }
+
+ public InitialContext getNamingContext() {
+ return environment.getNamingContext();
+ }
+
+ public Object getTransactionManager() {
+ return environment.getTransactionManager();
+ }
}
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationContextImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java (from r744748, servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java?p2=servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java&p1=servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java&r1=744748&r2=745010&rev=745010&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java Tue Feb 17 12:33:05 2009
@@ -14,16 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.management;
+package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
-import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import javax.jbi.JBIException;
import javax.jbi.management.DeploymentException;
import javax.jbi.management.InstallationServiceMBean;
import javax.management.Attribute;
@@ -33,65 +30,46 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.NamingStrategy;
import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
import org.apache.servicemix.jbi.deployer.handler.Transformer;
-import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.apache.servicemix.jbi.deployer.utils.QueryUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.context.BundleContextAware;
-public class InstallationService implements InstallationServiceMBean {
+public class InstallationService implements InstallationServiceMBean, BundleContextAware {
private static final Log LOG = LogFactory.getLog(InstallationService.class);
- private Map<String, ComponentInstaller> installers = new ConcurrentHashMap<String, ComponentInstaller>();
+ private Map<String, ComponentInstaller> componentInstallers = new ConcurrentHashMap<String, ComponentInstaller>();
- private Map<String, ComponentInstaller> nonLoadedInstallers = new ConcurrentHashMap<String, ComponentInstaller>();
-
- private Map<String, SharedLibInstaller> sharedLibinstallers = new ConcurrentHashMap<String, SharedLibInstaller>();
+ private Map<String, SharedLibraryInstaller> sharedLibinstallers = new ConcurrentHashMap<String, SharedLibraryInstaller>();
+
+ private Deployer deployer;
+ private BundleContext bundleContext;
- private AdminService adminService;
-
private NamingStrategy namingStrategy;
private ManagementAgent managementAgent;
-
+
/**
* Load the installer for a new component from a component installation
* package.
*
* @param installJarURL -
- * URL locating a jar file containing a JBI Installable
- * Component.
+ * URL locating a jar file containing a JBI Installable
+ * Component.
* @return - the JMX ObjectName of the InstallerMBean loaded from
* installJarURL.
*/
public synchronized ObjectName loadNewInstaller(String installJarURL) {
- try {
- ObjectName result = null;
+ try {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading new installer from " + installJarURL);
}
- File jarfile = new File(installJarURL);
- if (jarfile.exists()) {
- Descriptor desc = Transformer.getDescriptor(jarfile);
- if (desc != null && desc.getComponent() != null) {
- String componentName = desc.getComponent().getIdentification().getName();
- if (!installers.containsKey(componentName)) {
- ComponentInstaller installer = doInstallArchive(desc, jarfile);
- if (installer != null) {
- result = getNamingStrategy().createCustomComponentMBeanName("LifeCycle", componentName);
- installer.setObjectName(result);
- installers.put(componentName, installer);
- }
- } else {
- throw new RuntimeException("An installer already exists for " + componentName);
- }
- } else {
- throw new RuntimeException("Could not find Component from: " + installJarURL);
- }
- } else {
- throw new RuntimeException("location: " + installJarURL + " isn't valid");
- }
- return result;
+ ComponentInstaller installer = doLoadNewInstaller(installJarURL, false);
+ return installer.getObjectName();
} catch (Throwable t) {
LOG.error("Deployment failed", t);
if (t instanceof Error) {
@@ -105,75 +83,52 @@
}
}
- private ComponentInstaller doInstallArchive(Descriptor desc, File jarfile) throws Exception {
- return new ComponentInstaller(new InstallationContextImpl(desc.getComponent(), getNamingStrategy(), getManagementAgent()),
- jarfile, getAdminService());
- }
-
- /**
+ /**
* Load the InstallerMBean for a previously installed component.
*
- * @param aComponentName -
- * the component name identifying the installer to load.
+ * @param componentName -
+ * the component name identifying the installer to load.
* @return - the JMX ObjectName of the InstallerMBean loaded from an
* existing installation context.
*/
- public ObjectName loadInstaller(String aComponentName) {
- ComponentInstaller installer = installers.get(aComponentName);
- if (installer == null) {
- installer = nonLoadedInstallers.get(aComponentName);
+ public ObjectName loadInstaller(String componentName) {
+ try {
+ ComponentInstaller installer = componentInstallers.get(componentName);
if (installer != null) {
- try {
- // create an MBean for the installer
- ObjectName objectName = getNamingStrategy().createCustomComponentMBeanName("LifeCycle", aComponentName);
- installer.setObjectName(objectName);
- getManagementAgent().register(installer, objectName);
- } catch (Exception e) {
- throw new RuntimeException("Could not load installer", e);
- }
- return installer.getObjectName();
+ installer.register();
}
+ return installer != null ? installer.getObjectName() : null;
+ } catch (Exception e) {
+ String errStr = "Error loading installer: " + componentName;
+ LOG.error(errStr, e);
+ return null;
}
- return null;
}
/**
* Unload a JBI Installable Component installer.
*
* @param componentName -
- * the component name identifying the installer to unload.
+ * the component name identifying the installer to unload.
* @param isToBeDeleted -
- * true if the component is to be deleted as well.
+ * true if the component is to be deleted as well.
* @return - true if the operation was successful, otherwise false.
*/
public boolean unloadInstaller(String componentName, boolean isToBeDeleted) {
- boolean result = false;
+ boolean result = false;
try {
- ComponentInstaller installer = installers.remove(componentName);
- result = installer != null;
- if (result) {
- getManagementAgent().unregister(installer.getObjectName());
+ ComponentInstaller installer = isToBeDeleted ? componentInstallers.remove(componentName)
+ : componentInstallers.get(componentName);
+ if (installer != null) {
+ installer.unregister();
if (isToBeDeleted) {
installer.uninstall();
- } else {
- nonLoadedInstallers.put(componentName, installer);
}
- } else {
- //the component may not installed from Mbeans, so check the componet bundle directly
- ServiceReference ref = getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + componentName + ")");
- if (ref != null) {
- Bundle bundle = ref.getBundle();
- if (bundle != null) {
- bundle.stop();
- bundle.uninstall();
- result = true;
- }
- }
+ result = true;
}
} catch (Exception e) {
- String errStr = "Problem shutting down Component: " + componentName;
+ String errStr = "Error unloading installer: " + componentName;
LOG.error(errStr, e);
- } finally {
}
return result;
}
@@ -181,81 +136,80 @@
/**
* Install a shared library jar.
*
- * @param aSharedLibURI -
- * URI locating a jar file containing a shared library.
- * @return - the name of the shared library loaded from aSharedLibURI.
+ * @param location URI locating a jar file containing a shared library.
+ * @return the name of the shared library loaded from aSharedLibURI.
*/
public String installSharedLibrary(String location) {
- File jarfile = new File(location);
- String slName = null;
- try {
- if (jarfile.exists()) {
- Descriptor desc = null;
- try {
- desc = Transformer.getDescriptor(jarfile);
- } catch (Exception e) {
- LOG.error("install sharedLib failed", e);
- throw new DeploymentException("install sharedLib failed", e);
- }
- if (desc != null) {
- if (desc.getSharedLibrary() == null) {
- throw new DeploymentException("JBI descriptor is not a sharedLib descriptor");
+ File jarfile = new File(location);
+ String slName = null;
+ try {
+ if (jarfile.exists()) {
+ Descriptor desc;
+ try {
+ desc = Transformer.getDescriptor(jarfile);
+ } catch (Exception e) {
+ LOG.error("install sharedLib failed", e);
+ throw new DeploymentException("install sharedLib failed", e);
}
- slName = desc.getSharedLibrary().getIdentification().getName();
- LOG.info("Install ShareLib " + slName);
- if (sharedLibinstallers.containsKey(slName)) {
- ServiceReference ref = getAdminService().getSLServiceReference("(" + Deployer.NAME + "=" + slName + ")");
- if (ref == null) {
- //the Shared lib bundle uninstalled from console using osgi/uninstall
- sharedLibinstallers.remove(slName);
- } else {
- throw new DeploymentException("ShareLib " + slName+ " is already installed");
- }
+ if (desc != null) {
+ if (desc.getSharedLibrary() == null) {
+ throw new DeploymentException("JBI descriptor is not a sharedLib descriptor");
+ }
+ slName = desc.getSharedLibrary().getIdentification().getName();
+ LOG.info("Install ShareLib " + slName);
+ if (sharedLibinstallers.containsKey(slName)) {
+ ServiceReference ref = QueryUtils.getSharedLibraryServiceReference(bundleContext, "(" + Deployer.NAME + "=" + slName + ")");
+ if (ref == null) {
+ //the Shared lib bundle uninstalled from console using osgi/uninstall
+ sharedLibinstallers.remove(slName);
+ } else {
+ throw new DeploymentException("ShareLib " + slName + " is already installed");
+ }
+ }
+ SharedLibraryInstaller slInstaller = new SharedLibraryInstaller(bundleContext, slName);
+ slInstaller.install(location);
+ sharedLibinstallers.put(slName, slInstaller);
+
+ return slName;
+ } else {
+ throw new DeploymentException("Could not find JBI descriptor");
}
- SharedLibInstaller slInstaller = new SharedLibInstaller(slName, this.getAdminService());
- slInstaller.install(location);
- sharedLibinstallers.put(slName, slInstaller);
-
- return slName;
} else {
- throw new DeploymentException("Could not find JBI descriptor");
+ throw new DeploymentException("Could not find sharedLib");
}
- } else {
- throw new DeploymentException("Could not find sharedLib");
+ } catch (Exception e) {
+ LOG.error("install SharedLib failed", e);
}
- } catch (Exception e) {
- LOG.error("install SharedLib failed", e);
- }
- return slName;
+ return slName;
}
/**
* Uninstall a shared library.
*
* @param aSharedLibName -
- * the name of the shared library to uninstall.
+ * the name of the shared library to uninstall.
* @return - true iff the uninstall was successful.
*/
public boolean uninstallSharedLibrary(String aSharedLibName) {
- boolean result = false;
+ boolean result = false;
try {
- SharedLibInstaller installer = sharedLibinstallers.remove(aSharedLibName);
- result = installer != null;
+ SharedLibraryInstaller installer = sharedLibinstallers.remove(aSharedLibName);
+ result = installer != null;
if (result) {
- //the SL installed from Mbean
- installer.uninstall();
-
+ //the SL installed from Mbean
+ installer.uninstall();
+
} else {
- //the SL not installed from Mbeans, so check the SL bundle directly
- ServiceReference ref = getAdminService().getSLServiceReference("(" + Deployer.NAME + "=" + aSharedLibName + ")");
- if (ref != null) {
- Bundle bundle = ref.getBundle();
- if (bundle != null) {
- bundle.stop();
- bundle.uninstall();
- result = true;
- }
- }
+ //the SL not installed from Mbeans, so check the SL bundle directly
+ ServiceReference ref = QueryUtils.getSharedLibraryServiceReference(bundleContext, "(" + Deployer.NAME + "=" + aSharedLibName + ")");
+ if (ref != null) {
+ Bundle bundle = ref.getBundle();
+ if (bundle != null) {
+ bundle.stop();
+ bundle.uninstall();
+ result = true;
+ }
+ }
}
} catch (Exception e) {
String errStr = "Problem uninstall SL: " + aSharedLibName;
@@ -265,124 +219,113 @@
return result;
}
- /**
- * Install an archive
- *
- * @param location
- * @param props
- * @param autoStart
- * @throws DeploymentException
- */
- public void install(String location, Properties props, boolean autoStart) throws DeploymentException {
- File jarfile = new File(location);
+ protected ComponentInstaller doLoadNewInstaller(String installJarURL, boolean autoStart) throws Exception {
+ File jarfile = new File(installJarURL);
if (jarfile.exists()) {
- Descriptor desc = null;
- try {
- desc = Transformer.getDescriptor(jarfile);
- } catch (Exception e) {
- LOG.error("install component failed", e);
- throw new DeploymentException("install component failed", e);
- }
- if (desc != null) {
- if (desc.getComponent() == null) {
- throw new DeploymentException("JBI descriptor is not a component descriptor");
+ Descriptor desc = Transformer.getDescriptor(jarfile);
+ if (desc != null && desc.getComponent() != null) {
+ String componentName = desc.getComponent().getIdentification().getName();
+ if (!componentInstallers.containsKey(componentName)) {
+ ComponentInstaller installer;
+ try {
+ installer = new ComponentInstaller(deployer, desc.getComponent(), jarfile);
+ deployer.setComponentInstaller(installer);
+ installer.deployBundle();
+ installer.setAutoStart(autoStart);
+ installer.init();
+ installer.register();
+ componentInstallers.put(componentName, installer);
+ return installer;
+ } finally {
+ deployer.setComponentInstaller(null);
+ }
+ } else {
+ throw new RuntimeException("An installer already exists for " + componentName);
}
- install(jarfile, props, desc, autoStart);
} else {
- throw new DeploymentException("Could not find JBI descriptor");
+ throw new RuntimeException("Could not find Component from: " + installJarURL);
}
} else {
- throw new DeploymentException("Could not find component");
+ throw new RuntimeException("location: " + installJarURL + " isn't valid");
}
}
-
+
/**
* Install an archive
- *
- * @param tmpDir
- * @param root
+ *
+ * @param location
+ * @param props
* @param autoStart
* @throws DeploymentException
*/
- protected void install(File jarfile, Properties props, Descriptor desc, boolean autoStart) throws DeploymentException {
- if (desc.getComponent() != null) {
- String componentName = desc.getComponent().getIdentification().getName();
- if (installers.containsKey(componentName)) {
- ServiceReference ref = getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + componentName + ")");
- if (ref == null) {
- //the component bundle uninstalled from console using osgi/uninstall
- installers.remove(componentName);
- } else {
- throw new DeploymentException("Component " + componentName + " is already installed");
- }
- }
- ComponentInstaller installer = null;
- try {
- installer = doInstallArchive(desc, jarfile);
- } catch (Exception e1) {
- LOG.error("create installer for component " + desc.getComponent().getIdentification().getName()
- + " failed", e1);
- throw new DeploymentException("create installer for component " + desc.getComponent().getIdentification().getName()
- + " failed", e1);
- }
- if (installer != null) {
- try {
- if (props != null && props.size() > 0) {
- ObjectName on = installer.getInstallerConfigurationMBean();
- if (on == null) {
- LOG.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
- } else {
- MBeanServer mbs = getManagementAgent().getMbeanServer();
- for (Iterator it = props.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- String val = props.getProperty(key);
- try {
- mbs.setAttribute(on, new Attribute(key, val));
- } catch (JMException e) {
- throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
- }
- }
+ public void install(String location, Properties props, boolean autoStart) throws DeploymentException {
+ ComponentInstaller installer = null;
+ boolean success = false;
+ try {
+ installer = doLoadNewInstaller(location, autoStart);
+ if (props != null && props.size() > 0) {
+ ObjectName on = installer.getInstallerConfigurationMBean();
+ if (on == null) {
+ LOG.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
+ } else {
+ MBeanServer mbs = getManagementAgent().getMbeanServer();
+ for (Object o : props.keySet()) {
+ String key = (String) o;
+ String val = props.getProperty(key);
+ try {
+ mbs.setAttribute(on, new Attribute(key, val));
+ } catch (JMException e) {
+ throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
}
}
- installer.install();
- } catch (JBIException e) {
- throw new DeploymentException(e);
}
- installers.put(componentName, installer);
+ }
+ installer.install();
+ success = true;
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ } finally {
+ if (installer != null) {
+ unloadInstaller(installer.getName(), !success);
}
}
}
- public void setAdminService(AdminService adminService) {
- this.adminService = adminService;
- }
-
- public AdminService getAdminService() {
- return adminService;
- }
-
- public void setNamingStrategy(NamingStrategy namingStrategy) {
- this.namingStrategy = namingStrategy;
- }
-
- public NamingStrategy getNamingStrategy() {
- return namingStrategy;
- }
-
- public void setManagementAgent(ManagementAgent managementAgent) {
- this.managementAgent = managementAgent;
- }
-
- public ManagementAgent getManagementAgent() {
- return managementAgent;
- }
-
- public boolean containsSharedLibrary(String sharedLibraryName) {
- return sharedLibinstallers.containsKey(sharedLibraryName);
- }
-
- public Set<String> getInstalledSharedLibs() {
- return sharedLibinstallers.keySet();
- }
-
+ public void setNamingStrategy(NamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
+
+ public NamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ public Deployer getDeployer() {
+ return deployer;
+ }
+
+ public void setDeployer(Deployer deployer) {
+ this.deployer = deployer;
+ }
+
+ public void setManagementAgent(ManagementAgent managementAgent) {
+ this.managementAgent = managementAgent;
+ }
+
+ public ManagementAgent getManagementAgent() {
+ return managementAgent;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public boolean containsSharedLibrary(String sharedLibraryName) {
+ // TODO: remove this method
+ return sharedLibinstallers.containsKey(sharedLibraryName);
+ }
+
}
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/InstallationService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ManagementAgent.java (from r744748, servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ManagementAgent.java?p2=servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ManagementAgent.java&p1=servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java&r1=744748&r2=745010&rev=745010&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementAgent.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ManagementAgent.java Tue Feb 17 12:33:05 2009
@@ -14,26 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.management;
+package org.apache.servicemix.jbi.deployer.impl;
-import java.util.Set;
import java.util.HashSet;
+import java.util.Set;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
+import javax.management.InstanceAlreadyExistsException;
import javax.management.JMException;
+import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
-import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.RequiredModelMBean;
-import javax.management.modelmbean.InvalidTargetObjectTypeException;
-import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
-import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
-import org.springframework.beans.factory.DisposableBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource;
+import org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler;
/**
*/
@@ -43,7 +43,7 @@
private MBeanServer mbeanServer;
private MetadataMBeanInfoAssembler assembler;
- private Set<ObjectName> mbeans = new HashSet<ObjectName>();
+ final private Set<ObjectName> mbeans = new HashSet<ObjectName>();
public ManagementAgent() {
assembler = new MetadataMBeanInfoAssembler();
@@ -61,12 +61,15 @@
public void destroy() throws Exception {
// Using the array to hold the busMBeans to avoid the
// CurrentModificationException
- Object[] mBeans = mbeans.toArray();
+ ObjectName[] mBeans;
+ synchronized (mbeans) {
+ mBeans = mbeans.toArray(new ObjectName[mbeans.size()]);
+ mbeans.clear();
+ }
int caught = 0;
- for (Object name : mBeans) {
- mbeans.remove((ObjectName)name);
+ for (ObjectName name : mBeans) {
try {
- unregister((ObjectName)name);
+ unregister(name);
} catch (JMException jmex) {
LOG.info("Exception unregistering MBean", jmex);
caught++;
@@ -74,21 +77,20 @@
}
if (caught > 0) {
LOG.warn("A number of " + caught
- + " exceptions caught while unregistering MBeans during stop operation. "
- + "See INFO log for details.");
+ + " exceptions caught while unregistering MBeans during stop operation. "
+ + "See INFO log for details.");
}
}
public void register(Object obj, ObjectName name) throws JMException {
- register(obj, name, false);
+ register(obj, name, true);
}
public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
try {
registerMBeanWithServer(obj, name, forceRegistration);
} catch (NotCompliantMBeanException e) {
- // If this is not a "normal" MBean, then try to deploy it using JMX
- // annotations
+ // If this is not a "normal" MBean, then try to deploy it using JMX annotations
LOG.info("It's not a normal MBean");
ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString());
RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer.instantiate(RequiredModelMBean.class.getName());
@@ -102,15 +104,17 @@
}
}
- public synchronized void unregister(ObjectName name) throws JMException {
- if (mbeans.contains(name)) {
- //check if this bean already get removed in destory method
+ public void unregister(ObjectName name) throws JMException {
+ synchronized (mbeans) {
+ mbeans.remove(name);
+ }
+ if (mbeanServer.isRegistered(name)) {
mbeanServer.unregisterMBean(name);
}
}
private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
- ObjectInstance instance = null;
+ ObjectInstance instance;
try {
instance = mbeanServer.registerMBean(obj, name);
} catch (InstanceAlreadyExistsException e) {
@@ -120,12 +124,12 @@
} else {
throw e;
}
- } catch (NotCompliantMBeanException e) {
- throw e;
}
if (instance != null) {
- mbeans.add(name);
+ synchronized (mbeans) {
+ mbeans.add(name);
+ }
}
}
Copied: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java (from r744748, servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java)
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java?p2=servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java&p1=servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java&r1=744748&r2=745010&rev=745010&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ServiceAssemblyInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java Tue Feb 17 12:33:05 2009
@@ -14,50 +14,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.jbi.management;
+package org.apache.servicemix.jbi.deployer.impl;
import javax.jbi.JBIException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.servicemix.jbi.deployer.impl.ComponentImpl;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.prefs.BackingStoreException;
-import org.osgi.service.prefs.PreferencesService;
-import org.osgi.service.prefs.Preferences;
public class ServiceAssemblyInstaller extends AbstractInstaller {
-private static final Log LOGGER = LogFactory.getLog(SharedLibInstaller.class);
-
- private String name;
- private AdminService adminService;
-
- public ServiceAssemblyInstaller(String name, AdminService adminService) {
- this.name = name;
- this.adminService = adminService;
- setBundleContext(adminService.getBundleContext());
- }
-
- public void deploy(String filename) {
+ private String name;
+
+ public ServiceAssemblyInstaller(BundleContext bundleContext, String name) {
+ this.name = name;
+ this.bundleContext = bundleContext;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void deploy(String filename) {
try {
initializePreferences();
} catch (BackingStoreException e) {
LOGGER.warn("Error initializing persistent state for service assembly: " + name, e);
}
- deployFile(filename);
- }
-
- public void undeploy() throws javax.jbi.JBIException {
- try {
- Bundle bundle = getBundle();
+ deployFile(filename);
+ }
+
+ public void undeploy() throws javax.jbi.JBIException {
+ try {
+ Bundle bundle = getBundle();
if (bundle == null) {
LOGGER.warn("Could not find Bundle for Service Assembly: " + name);
- }
- else {
+ } else {
bundle.stop();
bundle.uninstall();
try {
@@ -67,38 +61,9 @@
}
}
} catch (BundleException e) {
- LOGGER.error("failed to uninstall Service Assembly: " + name, e);
- throw new JBIException(e);
- }
- }
-
- protected void initializePreferences() throws BackingStoreException {
- PreferencesService preferencesService = getPreferencesService();
- Preferences prefs = preferencesService.getUserPreferences(name);
- prefs.put(ComponentImpl.STATE, ComponentImpl.State.Shutdown.name());
- prefs.flush();
- }
-
- protected void deletePreferences() throws BackingStoreException {
- PreferencesService preferencesService = getPreferencesService();
- Preferences prefs = preferencesService.getUserPreferences(name);
- prefs.clear();
- prefs.flush();
- }
-
- private PreferencesService getPreferencesService() throws BackingStoreException {
- PreferencesService preferencesService = null;
- for (Bundle bundle : getBundleContext().getBundles()) {
- if ("org.apache.servicemix.jbi.deployer".equals(bundle.getSymbolicName())) {
- ServiceReference ref = bundle.getBundleContext().getServiceReference(PreferencesService.class.getName());
- preferencesService = (PreferencesService) bundle.getBundleContext().getService(ref);
- break;
- }
- }
- if (preferencesService == null) {
- throw new BackingStoreException("Unable to find bundle 'org.apache.servicemix.jbi.deployer'");
+ LOGGER.error("failed to uninstall Service Assembly: " + name, e);
+ throw new JBIException(e);
}
- return preferencesService;
}
}
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
------------------------------------------------------------------------------
svn:keywords = Rev Date