[jboss-cvs] JBossAS SVN: r95116 - in projects/jboss-osgi: projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 19 10:48:15 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-10-19 10:48:13 -0400 (Mon, 19 Oct 2009)
New Revision: 95116
Added:
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/BasicLifecycleInterceptor.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorException.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/LifecycleInterceptorPlugin.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelPlugin.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorPluginImpl.java
Removed:
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerServiceBase.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelServicePlugin.java
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeploymentRegistryService.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java
projects/jboss-osgi/trunk/reactor/framework/pom.xml
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
[JBOSGI-183] Initial implementation of OSGi Deployers
Call lifecycle plugins from MC framework
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -48,7 +48,7 @@
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.osgi.deployment.common.Deployment;
-import org.jboss.osgi.deployment.deployer.DeployerServiceBase;
+import org.jboss.osgi.deployment.deployer.AbstractDeployerService;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
@@ -65,7 +65,7 @@
* @author thomas.diesler at jboss.com
* @since 23-Jan-2009
*/
-public abstract class AbstractMicrocontainerService extends DeployerServiceBase implements MicrocontainerService
+public abstract class AbstractMicrocontainerService extends AbstractDeployerService implements MicrocontainerService
{
private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
private ServiceTracker registryTracker;
@@ -113,14 +113,13 @@
deploy(new Deployment[] { dep });
}
- public boolean undeploy(URL url) throws BundleException
+ public void undeploy(URL url) throws BundleException
{
DeploymentRegistryService registry = getDeploymentRegistry();
Deployment dep = registry.getDeployment(url);
if (dep == null)
{
logWarning("Package not deployed: " + url);
- return false;
}
try
@@ -129,12 +128,10 @@
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
mainDeployer.removeDeployment(vfsdep.getName());
mainDeployer.process();
- return true;
}
catch (Exception ex)
{
logWarning("Cannot undeploy bundle", ex);
- return false;
}
}
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -31,6 +31,8 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -92,13 +94,29 @@
}
catch (IOException ex)
{
- throw new BundleException("Cannot get manifest from: " + url);
+ throw new BundleException("Cannot get manifest from: " + url, ex);
}
return new BundleInfo(url, manifest);
}
+ public static BundleInfo createBundleInfo(VirtualFile vFile) throws BundleException
+ {
+ URL url;
+ Manifest manifest;
+ try
+ {
+ manifest = VFSUtils.getManifest(vFile);
+ url = vFile.toURL();
+ }
+ catch (Exception ex)
+ {
+ throw new BundleException("Cannot get manifest from: " + vFile, ex);
+ }
+ return new BundleInfo(url, manifest);
+ }
+
private BundleInfo(URL location, Manifest manifest) throws BundleException
{
if (location == null)
Modified: projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/blueprint/testsuite/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:48:13 UTC (rev 95116)
@@ -100,6 +100,9 @@
<bean name="PackageAdminService" class="org.jboss.osgi.framework.service.internal.PackageAdminImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorPluginImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java (from rev 95096, projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerServiceBase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/AbstractDeployerService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployment.deployer;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.internal.DeploymentImpl;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+//$Id$
+
+/**
+ * An abstract base implementation of the DeployerService.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 16-Oct-2009
+ */
+public abstract class AbstractDeployerService implements DeployerService
+{
+ public Deployment createDeployment(String location) throws BundleException
+ {
+ // Try location as URL
+ URL url = null;
+ try
+ {
+ url = new URL(location);
+ }
+ catch (MalformedURLException ex)
+ {
+ // ignore
+ }
+
+ // Try location as File
+ if (url == null)
+ {
+ try
+ {
+ File file = new File(location);
+ if (file.exists())
+ url = file.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+
+ if (url == null)
+ throw new IllegalArgumentException("Invalid bundle location: " + location);
+
+ return createDeploymentInternal(url);
+ }
+
+ private Deployment createDeploymentInternal(URL url) throws BundleException
+ {
+ Manifest manifest;
+ try
+ {
+ JarFile jarFile = new JarFile(url.getPath());
+ manifest = jarFile.getManifest();
+ jarFile.close();
+ }
+ catch (IOException ex)
+ {
+ throw new BundleException("Cannot get manifest from: " + url);
+
+ }
+
+ Attributes attribs = manifest.getMainAttributes();
+ String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ if (symbolicName == null)
+ throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
+
+ String version = attribs.getValue(Constants.BUNDLE_VERSION);
+ return new DeploymentImpl(url, symbolicName, version);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -66,15 +66,6 @@
/**
* Undeploy bundle from URL.
- *
- * Note, due to the dynamic nature of OSGi services it is
- * possible that a {@link DeployerService} is asked to undeploy
- * a bundle URL which it did not deploy itself.
- *
- * In this case this method should return false, so that
- * another {@link DeployerService} can be tried.
- *
- * @return true if this service could undeploy the bundle
*/
- boolean undeploy(URL url) throws BundleException;
+ void undeploy(URL url) throws BundleException;
}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerServiceBase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerServiceBase.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeployerServiceBase.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -1,104 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.deployment.deployer;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import org.jboss.osgi.deployment.common.Deployment;
-import org.jboss.osgi.deployment.internal.DeploymentImpl;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-
-//$Id$
-
-/**
- * An abstract base implementation of the DeployerService.
- *
- * @author thomas.diesler at jboss.com
- * @since 16-Oct-2009
- */
-public abstract class DeployerServiceBase implements DeployerService
-{
- public Deployment createDeployment(String location) throws BundleException
- {
- // Try location as URL
- URL url = null;
- try
- {
- url = new URL(location);
- }
- catch (MalformedURLException ex)
- {
- // ignore
- }
-
- // Try location as File
- if (url == null)
- {
- try
- {
- File file = new File(location);
- if (file.exists())
- url = file.toURI().toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
-
- if (url == null)
- throw new IllegalArgumentException("Invalid bundle location: " + location);
-
- return createDeploymentInternal(url);
- }
-
- private Deployment createDeploymentInternal(URL url) throws BundleException
- {
- Manifest manifest;
- try
- {
- JarFile jarFile = new JarFile(url.getPath());
- manifest = jarFile.getManifest();
- jarFile.close();
- }
- catch (IOException ex)
- {
- throw new BundleException("Cannot get manifest from: " + url);
-
- }
-
- Attributes attribs = manifest.getMainAttributes();
- String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
- if (symbolicName == null)
- throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
-
- String version = attribs.getValue(Constants.BUNDLE_VERSION);
- return new DeploymentImpl(url, symbolicName, version);
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeploymentRegistryService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeploymentRegistryService.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeploymentRegistryService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -37,7 +37,7 @@
public interface DeploymentRegistryService
{
/**
- * Create a bundle deployment from the given bundle URL
+ * Get the bundle deployment for the given bundle URL
* @return null, if this service does not maintain the bundle deployment
*/
Deployment getDeployment(URL url);
Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployment.interceptor;
+
+//$Id$
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.osgi.deployment.common.Deployment;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+/**
+ * A basic service that manages bundle lifecycle interceptors.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+public abstract class AbstractLifecycleInterceptorService implements LifecycleInterceptorService
+{
+ // The interceptor chain
+ private List<LifecycleInterceptor> interceptorChain = new ArrayList<LifecycleInterceptor>();
+
+ /**
+ * Add a LifecycleInterceptor to the service.
+ *
+ * The interceptor is added according to its input requirements
+ * and relative order.
+ *
+ * @param interceptor The interceptor
+ */
+ public void addInterceptor(LifecycleInterceptor interceptor)
+ {
+ synchronized (interceptorChain)
+ {
+ Set<LifecycleInterceptor> unsortedSet = new HashSet<LifecycleInterceptor>();
+ unsortedSet.addAll(interceptorChain);
+ unsortedSet.add(interceptor);
+
+ List<LifecycleInterceptor> sortedList = new ArrayList<LifecycleInterceptor>();
+
+ // Add interceptors with no inputs first
+ Iterator<LifecycleInterceptor> itUnsorted = unsortedSet.iterator();
+ while(itUnsorted.hasNext())
+ {
+ LifecycleInterceptor aux = itUnsorted.next();
+ if (aux.getInput() == null)
+ {
+ addWithRelativeOrder(sortedList, aux);
+ itUnsorted.remove();
+ }
+ }
+
+ // Get the set of provided outputs
+ Set<Class<?>> providedOutputs = new HashSet<Class<?>>();
+ for (LifecycleInterceptor aux : sortedList)
+ {
+ Set<Class<?>> auxOutput = aux.getOutput();
+ if (auxOutput != null)
+ providedOutputs.addAll(auxOutput);
+ }
+
+ // Add interceptors with sattisfied inputs
+ itUnsorted = unsortedSet.iterator();
+ while(itUnsorted.hasNext())
+ {
+ LifecycleInterceptor aux = itUnsorted.next();
+ Set<Class<?>> input = aux.getInput();
+ if (input == null)
+ throw new IllegalStateException("Interceptor with no inputs should have been added already");
+
+ if (providedOutputs.containsAll(input))
+ {
+ addWithRelativeOrder(sortedList, aux);
+ itUnsorted.remove();
+ }
+ }
+
+ // Add the remaining interceptors
+ for (LifecycleInterceptor aux : unsortedSet)
+ {
+ addWithRelativeOrder(sortedList, aux);
+ }
+
+ // Use the sorted result as the new interceptor chain
+ interceptorChain.clear();
+ interceptorChain.addAll(sortedList);
+ }
+ }
+
+ private void addWithRelativeOrder(List<LifecycleInterceptor> sortedList, LifecycleInterceptor interceptor)
+ {
+ Set<Class<?>> providedOutputs = new HashSet<Class<?>>();
+ int relOrder = interceptor.getRelativeOrder();
+ Set<Class<?>> input = interceptor.getInput();
+
+ for (int i = 0; i < sortedList.size(); i++)
+ {
+ LifecycleInterceptor aux = sortedList.get(i);
+ int auxOrder = aux.getRelativeOrder();
+
+ // Add if all inputs are satisfied and the rel order is less or equal
+ boolean inputsProvided = (input == null || providedOutputs.containsAll(input));
+ if (inputsProvided && relOrder <= auxOrder)
+ {
+ sortedList.add(i, interceptor);
+ return;
+ }
+
+ // Add the this interceptor output the list
+ Set<Class<?>> auxOutput = aux.getOutput();
+ if (auxOutput != null)
+ providedOutputs.addAll(auxOutput);
+ }
+
+ // If not added yet, add at end
+ sortedList.add(interceptor);
+ }
+
+ /**
+ * Remove an LifecycleInterceptor to the service.
+ *
+ * @param interceptor The interceptor
+ */
+ public void removeInterceptor(LifecycleInterceptor interceptor)
+ {
+ synchronized (interceptorChain)
+ {
+ interceptorChain.remove(interceptor);
+ }
+ }
+
+ protected List<LifecycleInterceptor> getInterceptorChain()
+ {
+ synchronized (interceptorChain)
+ {
+ return Collections.unmodifiableList(interceptorChain);
+ }
+ }
+
+ /**
+ * Invoke the registered set of interceptors for the given bundle state change.
+ *
+ * @param state The future state of the bundle
+ * @param bundle The bundle that changes state
+ * @throws LifecycleInterceptorException if the invocation of an interceptor fails
+ */
+ public void handleStateChange(int state, Bundle bundle)
+ {
+ synchronized (interceptorChain)
+ {
+ // Nothing to do
+ if (interceptorChain.size() == 0)
+ return;
+
+ String name = bundle.getSymbolicName();
+ Version version = bundle.getVersion();
+ Deployment dep = getDeployment(name, version);
+ if (dep == null)
+ throw new IllegalStateException("Cannot get deployment for: " + name + "-" + version);
+
+ // Attach the bundle if not already done so
+ Bundle attBundle = dep.getAttachment(Bundle.class);
+ if (attBundle == null)
+ dep.addAttachment(Bundle.class, bundle);
+
+ // Call the interceptor chain
+ for (LifecycleInterceptor interceptor : interceptorChain)
+ {
+ interceptor.invoke(state, dep);
+ }
+ }
+ }
+
+ /**
+ * Get the deployment for the given bundle symbolic name and version
+ */
+ protected abstract Deployment getDeployment(String symbolicName, Version version);
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/AbstractLifecycleInterceptorService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/BasicLifecycleInterceptor.java (from rev 95111, projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/BasicLifecycleInterceptor.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/BasicLifecycleInterceptor.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployment.interceptor;
+
+//$Id$
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.osgi.deployment.common.Deployment;
+
+/**
+ * A basic implementation of a LifecycleInterceptor.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+public class BasicLifecycleInterceptor implements LifecycleInterceptor
+{
+ private Set<Class<?>> input;
+ private Set<Class<?>> output;
+
+ /**
+ * No relative order
+ * @return 0
+ */
+ public int getRelativeOrder()
+ {
+ return 0;
+ }
+
+ /**
+ * Get the required set of inputs.
+ *
+ * @return null if there are no inputs required
+ */
+ public Set<Class<?>> getInput()
+ {
+ return input;
+ }
+
+ /**
+ * Get the provided set of outputs.
+ *
+ * @return null if there are no outputs provided
+ */
+ public Set<Class<?>> getOutput()
+ {
+ return output;
+ }
+
+ /**
+ * Add an input requirement.
+ */
+ public void addInput(Class<?> in)
+ {
+ if (input == null)
+ input = new HashSet<Class<?>>();
+
+ input.add(in);
+ }
+
+ /**
+ * Add an output capability.
+ */
+ public void addOutput(Class<?> out)
+ {
+ if (output == null)
+ output = new HashSet<Class<?>>();
+
+ output.add(out);
+ }
+
+ /**
+ * Does nothing.
+ * Overwrite to provide a meaningful implementation.
+ */
+ public void invoke(int state, Deployment dep)
+ {
+ // do nothing
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -26,7 +26,7 @@
import java.util.Set;
import org.jboss.osgi.deployment.common.Deployment;
-import org.osgi.framework.BundleException;
+import org.osgi.framework.Bundle;
/**
* An OSGi bundle lifecycle interceptor.
@@ -64,6 +64,7 @@
*
* @param state The future state of the bundle
* @param dep The deployment that represents the bundle
+ * @throws LifecycleInterceptorException if the invocation of the interceptor fails
*/
- void invoke(int state, Deployment dep) throws BundleException;
+ void invoke(int state, Deployment dep) throws LifecycleInterceptorException;
}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.deployment.interceptor;
-
-//$Id$
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.osgi.deployment.common.Deployment;
-import org.osgi.framework.BundleException;
-
-/**
- * A basic implementation of a LifecycleInterceptor.
- *
- * @author thomas.diesler at jboss.com
- * @since 15-Oct-2009
- */
-public class LifecycleInterceptorBase implements LifecycleInterceptor
-{
- private Set<Class<?>> input;
- private Set<Class<?>> output;
-
- /**
- * No relative order
- * @return 0
- */
- public int getRelativeOrder()
- {
- return 0;
- }
-
- /**
- * Get the required set of inputs.
- *
- * @return null if there are no inputs required
- */
- public Set<Class<?>> getInput()
- {
- return input;
- }
-
- /**
- * Get the provided set of outputs.
- *
- * @return null if there are no outputs provided
- */
- public Set<Class<?>> getOutput()
- {
- return output;
- }
-
- /**
- * Add an input requirement.
- */
- public void addInput(Class<?> in)
- {
- if (input == null)
- input = new HashSet<Class<?>>();
-
- input.add(in);
- }
-
- /**
- * Add an output capability.
- */
- public void addOutput(Class<?> out)
- {
- if (output == null)
- output = new HashSet<Class<?>>();
-
- output.add(out);
- }
-
- /**
- * Does nothing.
- * Overwrite to provide a meaningful implementation.
- */
- public void invoke(int state, Deployment dep) throws BundleException
- {
- // do nothing
- }
-}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorException.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorException.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorException.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployment.interceptor;
+
+//$Id$
+
+
+/**
+ * A runtime exception that may be thrown from a lifecycle interceptor.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+ at SuppressWarnings("serial")
+public class LifecycleInterceptorException extends RuntimeException
+{
+ private LifecycleInterceptorException(String message)
+ {
+ super(message);
+ }
+
+ private LifecycleInterceptorException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorException.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -24,7 +24,6 @@
//$Id$
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
/**
* A service that manages bundle lifecycle interceptors.
@@ -52,11 +51,11 @@
void removeInterceptor(LifecycleInterceptor interceptor);
/**
- * Invoke the interceptor chain for the given bundle state change.
+ * Invoke the registered set of interceptors for the given bundle state change.
*
* @param state The future state of the bundle
* @param bundle The bundle that changes state
- * @throws BundleException
+ * @throws LifecycleInterceptorException if the invocation of an interceptor fails
*/
- void invokeInterceptorChain(int state, Bundle bundle) throws BundleException;
+ void handleStateChange(int state, Bundle bundle);
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentImpl.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -26,6 +26,7 @@
import org.jboss.osgi.deployment.common.Deployment;
import org.jboss.osgi.deployment.common.DeploymentBase;
+import org.jboss.osgi.spi.util.BundleInfo;
//$Id$
@@ -46,6 +47,16 @@
private boolean autoStart;
private Object metadata;
+ public DeploymentImpl(BundleInfo info)
+ {
+ if (info == null)
+ throw new IllegalArgumentException("Bundle info cannot be null");
+
+ this.symbolicName = info.getSymbolicName();
+ this.location = info.getLocation();
+ this.version = info.getVersion().toString();
+ }
+
public DeploymentImpl(URL location, String symbolicName, String version)
{
if (location == null)
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -23,20 +23,13 @@
//$Id$
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
-import java.util.Set;
import org.jboss.osgi.deployment.common.Deployment;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
@@ -46,142 +39,26 @@
* @author thomas.diesler at jboss.com
* @since 15-Oct-2009
*/
-public class LifecycleInterceptorServiceImpl implements LifecycleInterceptorService
+public class LifecycleInterceptorServiceImpl extends AbstractLifecycleInterceptorService
{
private BundleContext context;
- // The interceptor chain
- private List<LifecycleInterceptor> interceptorChain = new ArrayList<LifecycleInterceptor>();
-
public LifecycleInterceptorServiceImpl(BundleContext context)
{
this.context = context;
}
-
- public void addInterceptor(LifecycleInterceptor interceptor)
- {
- synchronized (interceptorChain)
- {
- Set<LifecycleInterceptor> unsortedSet = new HashSet<LifecycleInterceptor>();
- unsortedSet.addAll(interceptorChain);
- unsortedSet.add(interceptor);
-
- List<LifecycleInterceptor> sortedList = new ArrayList<LifecycleInterceptor>();
-
- // Add interceptors with no inputs first
- Iterator<LifecycleInterceptor> itUnsorted = unsortedSet.iterator();
- while(itUnsorted.hasNext())
- {
- LifecycleInterceptor aux = itUnsorted.next();
- if (aux.getInput() == null)
- {
- addWithRelativeOrder(sortedList, aux);
- itUnsorted.remove();
- }
- }
-
- // Get the set of provided outputs
- Set<Class<?>> providedOutputs = new HashSet<Class<?>>();
- for (LifecycleInterceptor aux : sortedList)
- {
- Set<Class<?>> auxOutput = aux.getOutput();
- if (auxOutput != null)
- providedOutputs.addAll(auxOutput);
- }
-
- // Add interceptors with sattisfied inputs
- itUnsorted = unsortedSet.iterator();
- while(itUnsorted.hasNext())
- {
- LifecycleInterceptor aux = itUnsorted.next();
- Set<Class<?>> input = aux.getInput();
- if (input == null)
- throw new IllegalStateException("Interceptor with no inputs should have been added already");
-
- if (providedOutputs.containsAll(input))
- {
- addWithRelativeOrder(sortedList, aux);
- itUnsorted.remove();
- }
- }
-
- // Add the remaining interceptors
- for (LifecycleInterceptor aux : unsortedSet)
- {
- addWithRelativeOrder(sortedList, aux);
- }
-
- // Use the sorted result as the new interceptor chain
- interceptorChain.clear();
- interceptorChain.addAll(sortedList);
- }
- }
-
- private void addWithRelativeOrder(List<LifecycleInterceptor> sortedList, LifecycleInterceptor interceptor)
- {
- Set<Class<?>> providedOutputs = new HashSet<Class<?>>();
- int relOrder = interceptor.getRelativeOrder();
- Set<Class<?>> input = interceptor.getInput();
-
- for (int i = 0; i < sortedList.size(); i++)
- {
- LifecycleInterceptor aux = sortedList.get(i);
- int auxOrder = aux.getRelativeOrder();
-
- // Add if all inputs are satisfied and the rel order is less or equal
- boolean inputsProvided = (input == null || providedOutputs.containsAll(input));
- if (inputsProvided && relOrder <= auxOrder)
- {
- sortedList.add(i, interceptor);
- return;
- }
-
- // Add the this interceptor output the list
- Set<Class<?>> auxOutput = aux.getOutput();
- if (auxOutput != null)
- providedOutputs.addAll(auxOutput);
- }
-
- // If not added yet, add at end
- sortedList.add(interceptor);
- }
- public void removeInterceptor(LifecycleInterceptor interceptor)
- {
- synchronized (interceptorChain)
- {
- interceptorChain.remove(interceptor);
- }
- }
-
+ @Override
public List<LifecycleInterceptor> getInterceptorChain()
{
- synchronized (interceptorChain)
- {
- return Collections.unmodifiableList(interceptorChain);
- }
+ return super.getInterceptorChain();
}
- public void invokeInterceptorChain(int state, Bundle bundle) throws BundleException
+ @Override
+ protected Deployment getDeployment(String symbolicName, Version version)
{
- String name = bundle.getSymbolicName();
- Version version = bundle.getVersion();
- Deployment dep = getDeploymentRegistryService().getDeployment(name, version);
- if (dep == null)
- throw new IllegalStateException("Cannot get deployment for: " + name + "-" + version);
-
- // Attach the bundle if not already done so
- Bundle attBundle = dep.getAttachment(Bundle.class);
- if (attBundle == null)
- dep.addAttachment(Bundle.class, bundle);
-
- synchronized (interceptorChain)
- {
- for (LifecycleInterceptor interceptor : interceptorChain)
- {
- interceptor.invoke(state, dep);
- }
- }
+ DeploymentRegistryService service = getDeploymentRegistryService();
+ return service.getDeployment(symbolicName, version);
}
private DeploymentRegistryService getDeploymentRegistryService()
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -32,7 +32,7 @@
import org.jboss.osgi.deployment.common.Deployment;
import org.jboss.osgi.deployment.deployer.DeployerService;
-import org.jboss.osgi.deployment.deployer.DeployerServiceBase;
+import org.jboss.osgi.deployment.deployer.AbstractDeployerService;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
import org.jboss.osgi.spi.logging.ExportedPackageHelper;
import org.jboss.osgi.spi.management.ManagedBundleService;
@@ -53,7 +53,7 @@
* @author thomas.diesler at jboss.com
* @since 27-May-2009
*/
-public class SystemDeployerService extends DeployerServiceBase
+public class SystemDeployerService extends AbstractDeployerService
{
// Provide logging
private Logger log = LoggerFactory.getLogger(SystemDeployerService.class);
@@ -174,19 +174,17 @@
deploy(new Deployment[] { dep });
}
- public boolean undeploy(URL url) throws BundleException
+ public void undeploy(URL url) throws BundleException
{
DeploymentRegistryService registry = getDeploymentRegistry();
Deployment dep = registry.getDeployment(url);
if (dep != null)
{
undeploy(new Deployment[] { dep });
- return true;
}
else
{
log.warn( "Cannot find deployment for: " + url);
- return false;
}
}
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -28,7 +28,7 @@
import java.util.List;
import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorBase;
+import org.jboss.osgi.deployment.interceptor.BasicLifecycleInterceptor;
import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
import org.jboss.osgi.deployment.internal.LifecycleInterceptorServiceImpl;
import org.junit.Test;
@@ -44,8 +44,8 @@
@Test
public void testRelativeOrder()
{
- LifecycleInterceptor rel000 = new LifecycleInterceptorBase();
- LifecycleInterceptor rel100 = new LifecycleInterceptorBase()
+ LifecycleInterceptor rel000 = new BasicLifecycleInterceptor();
+ LifecycleInterceptor rel100 = new BasicLifecycleInterceptor()
{
public int getRelativeOrder()
{
@@ -81,10 +81,10 @@
{
}
- LifecycleInterceptorBase inA = new LifecycleInterceptorBase();
+ BasicLifecycleInterceptor inA = new BasicLifecycleInterceptor();
inA.addInput(A.class);
- LifecycleInterceptorBase outA = new LifecycleInterceptorBase();
+ BasicLifecycleInterceptor outA = new BasicLifecycleInterceptor();
outA.addOutput(A.class);
// Add ordered
Modified: projects/jboss-osgi/trunk/reactor/framework/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/pom.xml 2009-10-19 14:48:13 UTC (rev 95116)
@@ -137,12 +137,14 @@
<dependency>
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-spi</artifactId>
- <version>${version.jboss.osgi.spi}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.osgi.bundles</groupId>
+ <artifactId>jboss-osgi-deployment</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss.osgi.runtime</groupId>
<artifactId>jboss-osgi-deployers</artifactId>
- <version>${version.jboss.osgi.runtime.deployers}</version>
</dependency>
<!-- OSGi Dependencies -->
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -39,6 +39,7 @@
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
import org.jboss.osgi.framework.plugins.FrameworkEventsPlugin;
+import org.jboss.osgi.framework.plugins.LifecycleInterceptorPlugin;
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.util.ConstantsHelper;
import org.jboss.util.collection.ConcurrentSet;
@@ -649,47 +650,58 @@
public void changeState(int state)
{
int previous = getState();
- int type = 0;
+
+ // Get the corresponding bundle event type
+ int bundleEventType = 0;
switch (state)
{
case Bundle.STARTING:
- type = BundleEvent.STARTING;
+ bundleEventType = BundleEvent.STARTING;
break;
case Bundle.ACTIVE:
- type = BundleEvent.STARTED;
+ bundleEventType = BundleEvent.STARTED;
break;
case Bundle.STOPPING:
- type = BundleEvent.STOPPING;
+ bundleEventType = BundleEvent.STOPPING;
break;
case Bundle.UNINSTALLED:
- type = BundleEvent.UNINSTALLED;
+ bundleEventType = BundleEvent.UNINSTALLED;
break;
case Bundle.INSTALLED:
{
if (previous == Bundle.RESOLVED)
- type = BundleEvent.UNRESOLVED;
+ bundleEventType = BundleEvent.UNRESOLVED;
else
- type = BundleEvent.INSTALLED;
+ bundleEventType = BundleEvent.INSTALLED;
break;
}
case Bundle.RESOLVED:
{
if (previous == Bundle.STOPPING)
- type = BundleEvent.STOPPED;
+ bundleEventType = BundleEvent.STOPPED;
else
- type = BundleEvent.RESOLVED;
+ bundleEventType = BundleEvent.RESOLVED;
break;
}
default:
throw new IllegalArgumentException("Unknown bundle state: " + state);
}
+
+ // Invoke the bundle lifecycle interceptors
+ if (getBundleManager().isActive() && getBundleId() != 0)
+ {
+ LifecycleInterceptorPlugin plugin = getBundleManager().getPlugin(LifecycleInterceptorPlugin.class);
+ plugin.handleStateChange(state, getBundleInternal());
+ }
+
this.state.set(state);
log.debug(this + " change state=" + ConstantsHelper.bundleState(state));
+ // Fire the bundle event
if (getBundleManager().isActive())
{
FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
- plugin.fireBundleEvent(this, type);
+ plugin.fireBundleEvent(this, bundleEventType);
}
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -63,6 +63,8 @@
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.kernel.Kernel;
import org.jboss.logging.Logger;
+import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.internal.DeploymentImpl;
import org.jboss.osgi.framework.filter.NoFilter;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
@@ -73,6 +75,7 @@
import org.jboss.osgi.framework.plugins.Plugin;
import org.jboss.osgi.framework.plugins.ServicePlugin;
import org.jboss.osgi.framework.resolver.BundleResolver;
+import org.jboss.osgi.spi.util.BundleInfo;
import org.jboss.util.collection.ConcurrentSet;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VFSUtils;
@@ -87,6 +90,7 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
import org.osgi.service.packageadmin.PackageAdmin;
/**
@@ -471,6 +475,11 @@
att.addAttachment(PROPERTY_AUTO_START, Boolean.FALSE);
att.addAttachment(PROPERTY_BUNDLE_LOCATION, location);
+ // Add the deployment used by lifecycle interceptors
+ BundleInfo info = BundleInfo.createBundleInfo(root);
+ Deployment dep = new DeploymentImpl(info);
+ att.addAttachment(Deployment.class, dep);
+
deployerClient.deploy(deployment);
try
{
@@ -635,9 +644,11 @@
}
bundleState.setBundleManager(this);
+ bundles.add(bundleState);
+
bundleState.changeState(Bundle.INSTALLED);
- bundles.add(bundleState);
- log.debug("Added " + bundleState.getCanonicalName() + " id=" + bundleState.getBundleId());
+
+ log.debug("Added: " + bundleState);
}
/**
@@ -717,6 +728,29 @@
}
/**
+ * Get a bundle by symbolic name and version
+ *
+ * @param symbolicName the symbolic name of the bundle
+ * @param version the version of the bundle
+ * @return the bundle or null if there is no bundle with that id
+ */
+ public AbstractBundleState getBundle(String symbolicName, Version version)
+ {
+ AbstractBundleState result = null;
+ for (AbstractBundleState aux : bundles)
+ {
+ String auxName = aux.getSymbolicName();
+ Version auxVersion = aux.getVersion();
+ if (auxName.equals(symbolicName) && auxVersion.equals(version))
+ {
+ result = aux;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
* Get a bundle by location
*
* @param location the location of the bundle
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/LifecycleInterceptorPlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/LifecycleInterceptorPlugin.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/LifecycleInterceptorPlugin.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.plugins;
+
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+
+/**
+ * The LifecycleInterceptorService service plugin
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 19-Oct-2009
+ */
+public interface LifecycleInterceptorPlugin extends ServicePlugin, LifecycleInterceptorService
+{
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/LifecycleInterceptorPlugin.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelPlugin.java (from rev 95091, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelServicePlugin.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelPlugin.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelPlugin.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.plugins;
+
+import org.osgi.service.startlevel.StartLevel;
+
+/**
+ * The StartLevel service plugin
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 07-Sep-2009
+ */
+public interface StartLevelPlugin extends ServicePlugin, StartLevel
+{
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelServicePlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelServicePlugin.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/plugins/StartLevelServicePlugin.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.plugins;
-
-import org.osgi.service.startlevel.StartLevel;
-
-/**
- * The StartLevel service plugin
- *
- * @author thomas.diesler at jboss.com
- * @since 07-Sep-2009
- */
-public interface StartLevelServicePlugin extends ServicePlugin, StartLevel
-{
-}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorPluginImpl.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorPluginImpl.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.service.internal;
+
+//$Id$
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.deployment.common.Deployment;
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.plugins.LifecycleInterceptorPlugin;
+import org.jboss.osgi.framework.plugins.internal.AbstractPluginImpl;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.Version;
+
+/**
+ * A plugin that manages bundle lifecycle interceptors.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 19-Oct-2009
+ */
+public class LifecycleInterceptorPluginImpl extends AbstractPluginImpl implements LifecycleInterceptorPlugin
+{
+ // Provide logging
+ final Logger log = Logger.getLogger(LifecycleInterceptorPluginImpl.class);
+
+ private LifecycleInterceptorService service;
+ private ServiceRegistration registration;
+
+ public LifecycleInterceptorPluginImpl(OSGiBundleManager bundleManager)
+ {
+ super(bundleManager);
+ }
+
+ public BundleContext getSystemContext()
+ {
+ return bundleManager.getSystemBundle();
+ }
+
+ public void startService()
+ {
+ BundleContext context = getSystemContext();
+ service = new AbstractLifecycleInterceptorService()
+ {
+ protected Deployment getDeployment(String name, Version version)
+ {
+ OSGiBundleState bundle = (OSGiBundleState)bundleManager.getBundle(name, version);
+ if (bundle == null)
+ throw new IllegalStateException("Cannot obtain bundle for: " + name + "-" + version);
+
+ DeploymentUnit unit = bundle.getDeploymentUnit();
+ Deployment dep = unit.getAttachment(Deployment.class);
+ if (dep == null)
+ throw new IllegalStateException("Cannot obtain deployment for: " + bundle);
+
+ return dep;
+ }
+ };
+ registration = context.registerService(LifecycleInterceptorService.class.getName(), service, null);
+ }
+
+ public void stopService()
+ {
+ if (registration != null)
+ {
+ registration.unregister();
+ registration = null;
+ service = null;
+ }
+ }
+
+ public void addInterceptor(LifecycleInterceptor interceptor)
+ {
+ service.addInterceptor(interceptor);
+ }
+
+ public void removeInterceptor(LifecycleInterceptor interceptor)
+ {
+ service.removeInterceptor(interceptor);
+ }
+
+ public void handleStateChange(int state, Bundle bundle)
+ {
+ service.handleStateChange(state, bundle);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorPluginImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/StartLevelImpl.java 2009-10-19 14:48:13 UTC (rev 95116)
@@ -25,7 +25,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.plugins.StartLevelServicePlugin;
+import org.jboss.osgi.framework.plugins.StartLevelPlugin;
import org.jboss.osgi.framework.plugins.internal.AbstractServicePluginImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
@@ -39,7 +39,7 @@
* @author thomas.diesler at jboss.com
* @since 31-Aug-2009
*/
-public class StartLevelImpl extends AbstractServicePluginImpl implements StartLevelServicePlugin
+public class StartLevelImpl extends AbstractServicePluginImpl implements StartLevelPlugin
{
/** The log */
private static final Logger log = Logger.getLogger(StartLevelImpl.class);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:48:13 UTC (rev 95116)
@@ -72,6 +72,9 @@
<bean name="PackageAdminService" class="org.jboss.osgi.framework.service.internal.PackageAdminImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorPluginImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:48:13 UTC (rev 95116)
@@ -100,6 +100,9 @@
<bean name="PackageAdminService" class="org.jboss.osgi.framework.service.internal.PackageAdminImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorPluginImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:39:15 UTC (rev 95115)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-10-19 14:48:13 UTC (rev 95116)
@@ -99,6 +99,9 @@
<bean name="PackageAdminService" class="org.jboss.osgi.framework.service.internal.PackageAdminImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorPluginImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
More information about the jboss-cvs-commits
mailing list