[jboss-cvs] JBossAS SVN: r95111 - in projects/jboss-osgi: trunk/reactor/deployment and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 19 08:41:13 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-10-19 08:41:12 -0400 (Mon, 19 Oct 2009)
New Revision: 95111
Added:
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/LifecycleInterceptorBase.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/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/reactor/deployment/src/test/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/
projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java
Removed:
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptor.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptorService.java
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java
projects/jboss-osgi/trunk/reactor/deployment/.classpath
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/internal/DeploymentRegistryServiceImpl.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentServicesActivator.java
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java
Log:
[JBOSGI-183] Initial implementation of OSGi Deployers
Add initial interceptor impl
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 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/integration/AbstractMicrocontainerService.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -116,7 +116,7 @@
public boolean undeploy(URL url) throws BundleException
{
DeploymentRegistryService registry = getDeploymentRegistry();
- Deployment dep = registry.getBundleDeployment(url);
+ Deployment dep = registry.getDeployment(url);
if (dep == null)
{
logWarning("Package not deployed: " + url);
@@ -154,7 +154,7 @@
VirtualFile file = VFS.createNewRoot(dep.getLocation());
VFSDeployment vfsdep = deploymentFactory.createVFSDeployment(file);
dep.addAttachment(VFSDeployment.class, vfsdep);
- registry.registerBundleDeployment(dep);
+ registry.registerDeployment(dep);
depList.add(vfsdep);
MutableAttachments att = (MutableAttachments)vfsdep.getPredeterminedManagedObjects();
@@ -194,7 +194,7 @@
for (Deployment dep : depArr)
{
- registry.unregisterBundleDeployment(dep);
+ registry.unregisterDeployment(dep);
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
mainDeployer.removeDeployment(vfsdep.getName());
}
Modified: projects/jboss-osgi/trunk/reactor/deployment/.classpath
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/.classpath 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/.classpath 2009-10-19 12:41:12 UTC (rev 95111)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
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 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/deployer/DeploymentRegistryService.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -40,21 +40,21 @@
* Create a bundle deployment from the given bundle URL
* @return null, if this service does not maintain the bundle deployment
*/
- Deployment getBundleDeployment(URL url);
+ Deployment getDeployment(URL url);
/**
* Get the bundle deployment for the given bundle symbolicName and version
* @return null, if this service does not maintain the bundle deployment
*/
- Deployment getBundleDeployment(String symbolicName, Version version);
+ Deployment getDeployment(String symbolicName, Version version);
/**
* Register a bundle deployment
*/
- void registerBundleDeployment(Deployment dep);
+ void registerDeployment(Deployment dep);
/**
* Unregister a bundle deployment
*/
- void unregisterBundleDeployment(Deployment dep);
+ void unregisterDeployment(Deployment dep);
}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptor.java 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptor.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -1,49 +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;
-
-import org.jboss.osgi.deployment.common.Deployment;
-
-//$Id$
-
-
-/**
- * An OSGi deployer
- *
- * @author thomas.diesler at jboss.com
- * @since 15-Oct-2009
- */
-public interface DeploymentInterceptor
-{
- enum Phase {
- BEFORE_INSTALLED,
- AFTER_INSTALLED,
- BEFORE_RESOLVED,
- AFTER_RESOLVED,
- BEFORE_ACTIVE,
- AFTER_ACTIVE
- }
-
- void deploy(Deployment dep);
-
- void undeploy(Deployment dep);
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptorService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptorService.java 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptorService.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -1,39 +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$
-
-
-/**
- * The deployers service
- *
- * @author thomas.diesler at jboss.com
- * @since 15-Oct-2009
- */
-public interface DeploymentInterceptorService
-{
- void addInterceptor(DeploymentInterceptor deployer);
-
- void removeInterceptor(DeploymentInterceptor deployer);
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java (from rev 95096, projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptor.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptor.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -0,0 +1,69 @@
+/*
+ * 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.Set;
+
+import org.jboss.osgi.deployment.common.Deployment;
+import org.osgi.framework.BundleException;
+
+/**
+ * An OSGi bundle lifecycle interceptor.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+public interface LifecycleInterceptor
+{
+ /**
+ * Get the relative order of this interceptor
+ */
+ int getRelativeOrder();
+
+ /**
+ * Get the required set of inputs.
+ *
+ * @return null if there are no inputs required
+ */
+ Set<Class<?>> getInput();
+
+ /**
+ * Get the provided set of outputs.
+ *
+ * @return null if there are no outputs provided
+ */
+ Set<Class<?>> getOutput();
+
+ /**
+ * Called by the {@link LifecycleInterceptorService} when the
+ * given bundle is about to change to the given state
+ *
+ * The deployment that represents the bundle has the {@link Bundle}
+ * object attached.
+ *
+ * @param state The future state of the bundle
+ * @param dep The deployment that represents the bundle
+ */
+ void invoke(int state, Deployment dep) throws BundleException;
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -0,0 +1,102 @@
+/*
+ * 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
Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorBase.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/LifecycleInterceptorService.java (from rev 95096, projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/DeploymentInterceptorService.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/interceptor/LifecycleInterceptorService.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -0,0 +1,62 @@
+/*
+ * 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 org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * A service that manages bundle lifecycle interceptors.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+public interface LifecycleInterceptorService
+{
+ /**
+ * Add a LifecycleInterceptor to the service.
+ *
+ * The interceptor is added according to its input requirements
+ * and relative order.
+ *
+ * @param interceptor The interceptor
+ */
+ void addInterceptor(LifecycleInterceptor interceptor);
+
+ /**
+ * Remove an LifecycleInterceptor to the service.
+ *
+ * @param interceptor The interceptor
+ */
+ void removeInterceptor(LifecycleInterceptor interceptor);
+
+ /**
+ * Invoke the interceptor chain for the given bundle state change.
+ *
+ * @param state The future state of the bundle
+ * @param bundle The bundle that changes state
+ * @throws BundleException
+ */
+ void invokeInterceptorChain(int state, Bundle bundle) throws BundleException;
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentRegistryServiceImpl.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -47,17 +47,17 @@
{
}
- public void registerBundleDeployment(Deployment dep)
+ public void registerDeployment(Deployment dep)
{
deployments.add(dep);
}
- public void unregisterBundleDeployment(Deployment dep)
+ public void unregisterDeployment(Deployment dep)
{
deployments.remove(dep);
}
- public Deployment getBundleDeployment(String symbolicName, Version version)
+ public Deployment getDeployment(String symbolicName, Version version)
{
if (symbolicName == null)
throw new IllegalArgumentException("Cannot obtain bundle deployment for null symbolic name");
@@ -77,7 +77,7 @@
return dep;
}
- public Deployment getBundleDeployment(URL url)
+ public Deployment getDeployment(URL url)
{
if (url == null)
throw new IllegalArgumentException("Cannot obtain bundle deployment for: null");
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentServicesActivator.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentServicesActivator.java 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/DeploymentServicesActivator.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -31,9 +31,7 @@
import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
-import org.jboss.osgi.deployment.interceptor.DeploymentInterceptor;
-import org.jboss.osgi.deployment.interceptor.DeploymentInterceptorService;
-import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -51,25 +49,15 @@
{
// Provide logging
private Logger log = LoggerFactory.getLogger(DeploymentServicesActivator.class);
-
+
public void start(BundleContext context) throws Exception
{
// Register the deployer related services
registerDeployerService(context);
-
- DeploymentInterceptorService service = new DeploymentInterceptorService()
- {
- public void removeInterceptor(DeploymentInterceptor deployer)
- {
- throw new NotImplementedException();
- }
-
- public void addInterceptor(DeploymentInterceptor deployer)
- {
- throw new NotImplementedException();
- }
- };
- context.registerService(DeploymentInterceptorService.class.getName(), service, null);
+
+ // Register the lifecycle interceptor related services
+ LifecycleInterceptorService service = new LifecycleInterceptorServiceImpl(context);
+ context.registerService(LifecycleInterceptorService.class.getName(), service, null);
}
public void stop(BundleContext context) throws Exception
@@ -81,7 +69,7 @@
// Register the DeploymentRegistryService
DeploymentRegistryService registry = new DeploymentRegistryServiceImpl(context);
context.registerService(DeploymentRegistryService.class.getName(), registry, null);
-
+
// Register the SystemDeployerService
Properties props = new Properties();
props.put("provider", "system");
@@ -148,11 +136,11 @@
ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
if (sref == null)
throw new IllegalStateException("Cannot obtain deployer service");
-
+
// Unregister the DeployerService with a potentialy lower ranking
if (mbeanServer.isRegistered(DeployerService.MBEAN_DEPLOYER_SERVICE))
mbeanServer.unregisterMBean(DeployerService.MBEAN_DEPLOYER_SERVICE);
-
+
// Register the DeployerService with the highest ranking
DeployerService service = (DeployerService)context.getService(sref);
StandardMBean mbean = new StandardMBean(service, DeployerService.class);
Added: 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 (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -0,0 +1,195 @@
+/*
+ * 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.internal;
+
+//$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.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;
+
+/**
+ * A basic service that manages bundle lifecycle interceptors.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 15-Oct-2009
+ */
+public class LifecycleInterceptorServiceImpl implements LifecycleInterceptorService
+{
+ 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);
+ }
+ }
+
+ public List<LifecycleInterceptor> getInterceptorChain()
+ {
+ synchronized (interceptorChain)
+ {
+ return Collections.unmodifiableList(interceptorChain);
+ }
+ }
+
+ public void invokeInterceptorChain(int state, Bundle bundle) throws BundleException
+ {
+ 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);
+ }
+ }
+ }
+
+ private DeploymentRegistryService getDeploymentRegistryService()
+ {
+ ServiceReference sref = context.getServiceReference(DeploymentRegistryService.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("Cannot obtain deployment registry service");
+
+ return (DeploymentRegistryService)context.getService(sref);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.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/internal/SystemDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java 2009-10-19 12:23:47 UTC (rev 95110)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/SystemDeployerService.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -88,7 +88,7 @@
if (dep.isAutoStart())
resolvableBundles.add(bundle);
- registry.registerBundleDeployment(dep);
+ registry.registerDeployment(dep);
}
catch (BundleException ex)
{
@@ -155,7 +155,7 @@
Bundle bundle = getBundle(dep);
if (bundle != null)
{
- registry.unregisterBundleDeployment(dep);
+ registry.unregisterDeployment(dep);
unregisterManagedBundle(bundle);
bundle.uninstall();
@@ -177,7 +177,7 @@
public boolean undeploy(URL url) throws BundleException
{
DeploymentRegistryService registry = getDeploymentRegistry();
- Deployment dep = registry.getBundleDeployment(url);
+ Deployment dep = registry.getDeployment(url);
if (dep != null)
{
undeploy(new Deployment[] { dep });
Added: 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 (rev 0)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java 2009-10-19 12:41:12 UTC (rev 95111)
@@ -0,0 +1,110 @@
+/*
+ * 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.test.osgi.deployment.interceptor;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorBase;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
+import org.jboss.osgi.deployment.internal.LifecycleInterceptorServiceImpl;
+import org.junit.Test;
+
+/**
+ * Test the {@link LifecycleInterceptorService}
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 19-Oct-2009
+ */
+public class LifecycleInterceptorTestCase
+{
+ @Test
+ public void testRelativeOrder()
+ {
+ LifecycleInterceptor rel000 = new LifecycleInterceptorBase();
+ LifecycleInterceptor rel100 = new LifecycleInterceptorBase()
+ {
+ public int getRelativeOrder()
+ {
+ return 100;
+ }
+ };
+
+ // Add ordered
+ LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(null);
+ service.addInterceptor(rel000);
+ service.addInterceptor(rel100);
+
+ List<LifecycleInterceptor> chain = service.getInterceptorChain();
+ assertEquals(2, chain.size());
+ assertEquals(0, chain.get(0).getRelativeOrder());
+ assertEquals(100, chain.get(1).getRelativeOrder());
+
+ // Add unordered
+ service = new LifecycleInterceptorServiceImpl(null);
+ service.addInterceptor(rel100);
+ service.addInterceptor(rel000);
+
+ chain = service.getInterceptorChain();
+ assertEquals(2, chain.size());
+ assertEquals(0, chain.get(0).getRelativeOrder());
+ assertEquals(100, chain.get(1).getRelativeOrder());
+ }
+
+ @Test
+ public void testInputOutput()
+ {
+ class A
+ {
+ }
+
+ LifecycleInterceptorBase inA = new LifecycleInterceptorBase();
+ inA.addInput(A.class);
+
+ LifecycleInterceptorBase outA = new LifecycleInterceptorBase();
+ outA.addOutput(A.class);
+
+ // Add ordered
+ LifecycleInterceptorServiceImpl service = new LifecycleInterceptorServiceImpl(null);
+ service.addInterceptor(outA);
+ service.addInterceptor(inA);
+
+ List<LifecycleInterceptor> chain = service.getInterceptorChain();
+ assertEquals(2, chain.size());
+ assertEquals(outA, chain.get(0));
+ assertEquals(inA, chain.get(1));
+
+ // Add unordered
+ service = new LifecycleInterceptorServiceImpl(null);
+ service.addInterceptor(inA);
+ service.addInterceptor(outA);
+
+ chain = service.getInterceptorChain();
+ assertEquals(2, chain.size());
+ assertEquals(outA, chain.get(0));
+ assertEquals(inA, chain.get(1));
+ }
+}
Property changes on: projects/jboss-osgi/trunk/reactor/deployment/src/test/java/org/jboss/test/osgi/deployment/interceptor/LifecycleInterceptorTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jboss-cvs-commits
mailing list