Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 11:13:33 -0500 (Mon, 30 Nov 2009)
New Revision: 97175
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java
Removed:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
Log:
More work on MC service restart issue
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 16:09:19
UTC (rev 97174)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 16:13:33
UTC (rev 97175)
@@ -49,7 +49,7 @@
<version.jboss.osgi.jaxb>2.1.10-SNAPSHOT</version.jboss.osgi.jaxb>
<version.jboss.osgi.jmx>1.0.2-SNAPSHOT</version.jboss.osgi.jmx>
<version.jboss.osgi.reflect>2.0.2-SNAPSHOT</version.jboss.osgi.reflect>
-
<version.jboss.osgi.runtime.deployers>1.0.3</version.jboss.osgi.runtime.deployers>
+
<version.jboss.osgi.runtime.deployers>1.0.3-SNAPSHOT</version.jboss.osgi.runtime.deployers>
<version.jboss.osgi.spi>1.0.3-SNAPSHOT</version.jboss.osgi.spi>
<version.jboss.osgi.xml.binding>2.0.2-SNAPSHOT</version.jboss.osgi.xml.binding>
<version.osgi>4.2.0</version.osgi>
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -35,7 +35,6 @@
import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.deployment.deployer.DeploymentRegistryService;
-import org.jboss.osgi.spi.OSGiConstants;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -131,8 +130,7 @@
depList.add(vfsdep);
MutableAttachments att =
(MutableAttachments)vfsdep.getPredeterminedManagedObjects();
- att.addAttachment(OSGiConstants.PROPERTY_START_LEVEL, new
Integer(dep.getStartLevel()));
- att.addAttachment(OSGiConstants.PROPERTY_AUTO_START, new
Boolean(dep.isAutoStart()));
+ att.addAttachment(Deployment.class, dep);
getMainDeployer().addDeployment(vfsdep);
}
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeanDeployer.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -27,12 +27,11 @@
import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.jboss.osgi.spi.NotImplementedException;
-import org.jboss.virtual.VirtualFile;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
import org.jboss.xb.util.JBossXBHelper;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.FrameworkUtil;
import org.xml.sax.InputSource;
/**
@@ -43,33 +42,6 @@
*/
public class EmbeddedBeanDeployer extends BeanDeployer
{
- private BundleContext systemContext;
-
- public void setSystemContext(BundleContext systemContext)
- {
- this.systemContext = systemContext;
- }
-
- static UnmarshallerService getUnmarshallerService(BundleContext context)
- {
- ServiceReference sref =
context.getServiceReference(UnmarshallerService.class.getName());
- if (sref == null)
- throw new IllegalStateException("Cannot obtain: " +
UnmarshallerService.class.getName());
-
- UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
- unmarshaller.addClassBinding("urn:jboss:aop-beans:1.0",
"org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
- unmarshaller.addClassBinding("urn:jboss:bean-deployer",
"org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
- unmarshaller.addClassBinding("urn:jboss:bean-deployer:2.0",
"org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
- unmarshaller.addClassBinding("urn:jboss:javabean:1.0",
"org.jboss.javabean.plugins.jaxb.JavaBean10");
- unmarshaller.addClassBinding("urn:jboss:javabean:2.0",
"org.jboss.javabean.plugins.jaxb.JavaBean20");
- unmarshaller.addClassBinding("urn:jboss:policy:1.0",
"org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
- unmarshaller.addClassBinding("urn:jboss:classloading:1.0",
"org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
- unmarshaller.addClassBinding("urn:jboss:classloader:1.0",
"org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
- unmarshaller.addClassBinding("urn:jboss:deployers:2.0",
"org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
-
- return unmarshaller;
- }
-
@Override
protected JBossXBHelper<KernelDeployment> getHelper()
{
@@ -86,7 +58,9 @@
@Override
public void setFeature(String featureName, boolean flag) throws Exception
{
- UnmarshallerService unmarshaller = getUnmarshallerService(systemContext);
+ // Get the UnmarshallerService in the context of the microcontainer bundle
+ BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
+ UnmarshallerService unmarshaller =
EmbeddedXMLDeployer.getUnmarshallerService(context);
unmarshaller.setFeature(featureName, flag);
}
@@ -94,7 +68,9 @@
@SuppressWarnings("unchecked")
public T parse(InputSource source) throws Exception
{
- UnmarshallerService unmarshaller = getUnmarshallerService(systemContext);
+ // Get the UnmarshallerService in the context of the microcontainer bundle
+ BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
+ UnmarshallerService unmarshaller =
EmbeddedXMLDeployer.getUnmarshallerService(context);
return (T)unmarshaller.unmarshal(source);
}
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedKernelBootstrap.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -23,8 +23,6 @@
// $Id$
-import java.net.URL;
-
import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
@@ -40,8 +38,6 @@
{
// Provide logging
private static Logger log = LoggerFactory.getLogger(EmbeddedKernelBootstrap.class);
-
- private EmbeddedXMLDeployer deployer;
public EmbeddedKernelBootstrap(BundleContext context)
{
@@ -57,46 +53,7 @@
{
throw new IllegalStateException("Cannot bootstrap kernel", e);
}
+ kernel = getKernel();
}
- deployer = new EmbeddedXMLDeployer(context, kernel);
}
-
- /**
- * Deploy MC beans from URL
- */
- public void deploy(URL url)
- {
- log.debug("deploy: " + url);
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
- deployer.deploy(url);
- deployer.validate();
- }
- catch (Throwable e)
- {
- throw new IllegalStateException("Cannot deploy beans from: " + url,
e);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
- }
-
- /**
- * Undeploy MC beans from URL
- */
- public void undeploy(URL url)
- {
- log.debug("undeploy: " + url);
- try
- {
- deployer.undeploy(url);
- }
- catch (Throwable e)
- {
- throw new IllegalStateException("Cannot undeploy beans from: " + url,
e);
- }
- }
}
\ No newline at end of file
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedXMLDeployer.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -24,9 +24,6 @@
// $Id$
import java.net.URL;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.deployment.BasicKernelDeployer;
@@ -35,6 +32,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* An XML deployer that unlike the {@link BasicXMLDeployer} does not cache
@@ -50,9 +48,6 @@
private BundleContext context;
- /** The deployments by url or name */
- private Map<String, KernelDeployment> deploymentsByName = new
ConcurrentHashMap<String, KernelDeployment>();
-
/**
* Create a new XML deployer
*
@@ -65,56 +60,7 @@
this.context = context;
}
- public Collection<String> getDeploymentNames()
- {
- return deploymentsByName.keySet();
- }
-
- public void deploy(KernelDeployment deployment) throws Throwable
- {
- super.deploy(deployment);
- deploymentsByName.put(deployment.getName(), deployment);
- }
-
- public void undeploy(KernelDeployment deployment)
- {
- deploymentsByName.remove(deployment.getName());
- super.undeploy(deployment);
- }
-
/**
- * Undeploy a url
- *
- * @param url the url to undeploy
- * @throws IllegalStateException if the url is unknown
- */
- public void undeploy(final URL url)
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
-
- undeploy(url.toString());
- }
-
- /**
- * Undeploy a name deployment
- *
- * @param name the name of the deployment to undeploy
- * @throws IllegalStateException if the name is unknown
- */
- public void undeploy(final String name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
-
- KernelDeployment deployment = deploymentsByName.remove(name);
- if (deployment == null)
- throw new IllegalStateException("Unknown deployment " + name);
-
- undeploy(deployment);
- }
-
- /**
* Deploy a url
*
* @param url the url to deploy
@@ -133,7 +79,7 @@
long start = System.currentTimeMillis();
- UnmarshallerService unmarshaller =
EmbeddedBeanDeployer.getUnmarshallerService(context);
+ UnmarshallerService unmarshaller =
EmbeddedXMLDeployer.getUnmarshallerService(context);
KernelDeployment deployment =
(KernelDeployment)unmarshaller.unmarshal(url.toString());
if (deployment == null)
throw new RuntimeException("The xml " + url + " is not well
formed!");
@@ -156,4 +102,24 @@
return deployment;
}
+
+ static UnmarshallerService getUnmarshallerService(BundleContext context)
+ {
+ ServiceReference sref =
context.getServiceReference(UnmarshallerService.class.getName());
+ if (sref == null)
+ throw new IllegalStateException("Cannot obtain: " +
UnmarshallerService.class.getName());
+
+ UnmarshallerService unmarshaller = (UnmarshallerService)context.getService(sref);
+ unmarshaller.addClassBinding("urn:jboss:aop-beans:1.0",
"org.jboss.aop.microcontainer.beans.metadata.AOPDeployment");
+ unmarshaller.addClassBinding("urn:jboss:bean-deployer",
"org.jboss.kernel.plugins.deployment.AbstractKernelDeployment10");
+ unmarshaller.addClassBinding("urn:jboss:bean-deployer:2.0",
"org.jboss.kernel.plugins.deployment.AbstractKernelDeployment");
+ unmarshaller.addClassBinding("urn:jboss:javabean:1.0",
"org.jboss.javabean.plugins.jaxb.JavaBean10");
+ unmarshaller.addClassBinding("urn:jboss:javabean:2.0",
"org.jboss.javabean.plugins.jaxb.JavaBean20");
+ unmarshaller.addClassBinding("urn:jboss:policy:1.0",
"org.jboss.beans.metadata.plugins.policy.AbstractPolicyMetaData");
+ unmarshaller.addClassBinding("urn:jboss:classloading:1.0",
"org.jboss.classloading.spi.metadata.ClassLoadingMetaData10");
+ unmarshaller.addClassBinding("urn:jboss:classloader:1.0",
"org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10");
+ unmarshaller.addClassBinding("urn:jboss:deployers:2.0",
"org.jboss.deployers.vfs.plugins.xb.SchemaResolverDeployerMetaData");
+
+ return unmarshaller;
+ }
}
\ No newline at end of file
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
(rev 0)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -0,0 +1,48 @@
+/*
+ * 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.microcontainer.internal;
+
+//$Id$
+
+import org.jboss.kernel.Kernel;
+
+/**
+ * An MBean that allows the the microcontainer bundle to
+ * register its kernel instance with the MBeanServer.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 30-Nov-2009
+ */
+public class KernelLocator implements KernelLocatorMBean
+{
+ private Kernel kernel;
+
+ public KernelLocator(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+ public Kernel getKernel()
+ {
+ return kernel;
+ }
+}
\ No newline at end of file
Property changes on:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocator.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
(rev 0)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -0,0 +1,46 @@
+/*
+ * 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.microcontainer.internal;
+
+//$Id$
+
+import javax.management.ObjectName;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
+/**
+ * An MBean that allows the the microcontainer bundle to
+ * register its kernel instance with the MBeanServer.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 23-Jan-2009
+ */
+public interface KernelLocatorMBean
+{
+ /**
+ * The object name under which the KernelLocator is registered:
'jboss.osgi:service=KernelLocator'
+ */
+ ObjectName MBEAN_KERNEL_LOCATOR =
ObjectNameFactory.create("jboss.osgi:service=KernelLocator");
+
+ Kernel getKernel();
+}
\ No newline at end of file
Property changes on:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/KernelLocatorMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -44,18 +44,8 @@
if ("org.jboss.osgi.framework".equals(systemBundleName))
return;
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
- mcService = new MicrocontainerServiceImpl(context);
- mcService.start();
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
+ mcService = new MicrocontainerServiceImpl(context);
+ mcService.start();
}
public void stop(BundleContext context)
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -58,35 +58,22 @@
public class MicrocontainerServiceImpl extends AbstractMicrocontainerService implements
MicrocontainerServiceMBean
{
private BundleContext context;
- private EmbeddedKernelBootstrap deployer;
+ private Kernel kernel;
public MicrocontainerServiceImpl(BundleContext context)
{
this.context = context;
-
VFS.init();
-
- deployer = new EmbeddedKernelBootstrap(context);
}
public Kernel getKernel()
{
- return deployer.getKernel();
+ return kernel;
}
void start()
{
- final MicrocontainerService mcServiceImpl = this;
-
- final Kernel kernel = getKernel();
- final KernelController controller = kernel.getController();
-
- // Preregister some beans
- installBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT, context);
- installBean(controller, BEAN_KERNEL, kernel);
- installBean(controller, BEAN_KERNEL_CONTROLLER, controller);
-
- // Setup a filter to track both services
+ // Setup a filter to track the JMX and XMLBinding service
Filter filter;
try
{
@@ -99,6 +86,8 @@
throw new IllegalArgumentException("Invalid filter syntax");
}
+ final MicrocontainerService mcService = this;
+
// Register the MicrocontainerServiceMBean
ServiceTracker tracker = new ServiceTracker(context, filter, null)
{
@@ -119,15 +108,10 @@
if (mbeanServer != null && xmlService != null)
{
- // Install the MBeanServer
- installBean(controller, BEAN_MBEAN_SERVER, mbeanServer);
+ initializeMicrocontainerService(mbeanServer);
- // Deploy the deployer beans
- URL deployersURL =
context.getBundle().getResource("META-INF/base-deployers-beans.xml");
- deployer.deploy(deployersURL);
-
// Register the MicrocontainerService
- context.registerService(MicrocontainerService.class.getName(),
mcServiceImpl, null);
+ context.registerService(MicrocontainerService.class.getName(), mcService,
null);
// Register the Microcontainer DeployerService
registerMicrocontainerDeployerService();
@@ -144,25 +128,44 @@
void stop()
{
- Kernel kernel = getKernel();
- KernelController controller = kernel.getController();
-
ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
if (sref != null)
{
MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
unregisterMicrocontainerServiceMBean(mbeanServer);
- uninstallBean(controller, BEAN_MBEAN_SERVER);
}
+ }
- // Undeploy the deployer beans
- URL deployersURL =
context.getBundle().getResource("META-INF/base-deployers-beans.xml");
- deployer.undeploy(deployersURL);
-
- // Uninstall preregister some beans
- uninstallBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT);
- uninstallBean(controller, BEAN_KERNEL);
- uninstallBean(controller, BEAN_KERNEL_CONTROLLER);
+ private void initializeMicrocontainerService(MBeanServer mbeanServer)
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ EmbeddedKernelBootstrap bootstrap = new EmbeddedKernelBootstrap(context);
+
+ kernel = bootstrap.getKernel();
+ KernelController controller = kernel.getController();
+ BundleContext sysContext = context.getBundle(0).getBundleContext();
+
+ // Preregister some beans
+ installBean(controller, BEAN_BUNDLE_CONTEXT, sysContext);
+ installBean(controller, BEAN_KERNEL, kernel);
+ installBean(controller, BEAN_KERNEL_CONTROLLER, controller);
+ installBean(controller, BEAN_MBEAN_SERVER, mbeanServer);
+
+ // Deploy the deployer beans
+ URL deployersURL =
context.getBundle().getResource("META-INF/base-deployers-beans.xml");
+ new EmbeddedXMLDeployer(context, kernel).deploy(deployersURL);
+ }
+ catch (Throwable th)
+ {
+ throw new IllegalStateException("Cannot initilize the
MicrocontainerService", th);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
}
private void registerMicrocontainerDeployerService()
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/resources/META-INF/base-deployers-beans.xml 2009-11-30
16:13:33 UTC (rev 97175)
@@ -52,7 +52,6 @@
<!-- POJO Deployment -->
<bean name="BeanDeployer"
class="org.jboss.osgi.microcontainer.internal.EmbeddedBeanDeployer">
- <property name="systemContext"><inject
bean="jboss.osgi:service=BundleContext" /></property>
<property name="suffix">jboss-beans.xml</property>
</bean>
<bean name="KernelDeploymentDeployer"
class="org.jboss.osgi.deployer.BundleContainedBeansDeployer">
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -24,9 +24,15 @@
//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com
$
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.util.List;
+
+import javax.management.ObjectName;
+
import org.jboss.osgi.microcontainer.MicrocontainerCapability;
import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiTest;
@@ -48,16 +54,25 @@
try
{
runtime.addCapability(new MicrocontainerCapability());
-
+
OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
bundle.start();
-
+
// The bean should have registered itself to the MBeanServer
SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class,
SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
assertEquals("hello", someBean.echo("hello"));
-
+
// The service should be able to access the bean via the MicrocontainerService
assertEquals("hello", someBean.callSomeService("hello"));
+
+ // Uninstall the user bundle
+ bundle.uninstall();
+
+ // Check that the beans are unregistered
+ ObjectName serviceOName =
MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
+ MicrocontainerServiceMBean mcService =
MBeanProxy.get(MicrocontainerServiceMBean.class, serviceOName, runtime.getMBeanServer());
+ List<String> beanNames = mcService.getRegisteredBeans();
+ assertFalse("SomeBean unregistered " + beanNames,
beanNames.contains("SomeBean"));
}
finally
{
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
(rev 0)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -0,0 +1,74 @@
+/*
+ * 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.microcontainer;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.deployment.deployer.DeployerService;
+import org.jboss.osgi.microcontainer.MicrocontainerCapability;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.Test;
+
+/**
+ * Test Microcontainer DeployerService
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+public class DeployerServiceTestCase extends OSGiTest
+{
+ @Test
+ public void testMicrocontainerService() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ OSGiServiceReference sref =
runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("system", sref.getProperty("provider"));
+
+ runtime.addCapability(new MicrocontainerCapability());
+ OSGiBundle serviceBundle =
runtime.getBundle("jboss-osgi-microcontainer", null);
+
+ sref = runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("microcontainer",
sref.getProperty("provider"));
+
+ // Uninstall the mc service bundle
+ serviceBundle.uninstall();
+
+ sref = runtime.getServiceReference(DeployerService.class.getName());
+ assertNotNull("DeployerService", sref);
+ assertEquals("system", sref.getProperty("provider"));
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Property changes on:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/DeployerServiceTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java
(from rev 97156,
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java)
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java
(rev 0)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/MicrocontainerServiceRefreshTestCase.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -0,0 +1,89 @@
+/*
+ * 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.microcontainer;
+
+//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com
$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.microcontainer.MicrocontainerCapability;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test MicrocontainerService restart
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+public class MicrocontainerServiceRefreshTestCase extends OSGiTest
+{
+ @Test
+ public void testMicrocontainerService() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ runtime.addCapability(new MicrocontainerCapability());
+
+ OSGiBundle serviceBundle =
runtime.getBundle("jboss-osgi-microcontainer", null);
+ assertEquals("MicrocontainerService ACTIVE", Bundle.ACTIVE,
serviceBundle.getState());
+
+ OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
+ bundle.start();
+
+ // The service should be able to access the bean via the MicrocontainerService
+ SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class,
SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
+ assertEquals("hello", someBean.callSomeService("hello"));
+
+ // Uninstall the user bundle
+ bundle.uninstall();
+
+ // Refresh all packages. This should stop/start the MC bundle
+ OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
+ packageAdmin.refreshPackages(null);
+
+ // Wait some time for the refresh to finish
+ Thread.sleep(1000);
+
+ // Check if the MC bundle is still active (or could be restarted)
+ assertEquals("MicrocontainerService ACTIVE", Bundle.ACTIVE,
serviceBundle.getState());
+
+ // Check if the service is available
+ OSGiServiceReference sref =
runtime.getServiceReference(MicrocontainerService.class.getName());
+ assertNotNull("MicrocontainerService available", sref);
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Deleted:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
===================================================================
---
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-30
16:09:19 UTC (rev 97174)
+++
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-30
16:13:33 UTC (rev 97175)
@@ -1,83 +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.test.osgi.microcontainer;
-
-//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com
$
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.jboss.osgi.microcontainer.MicrocontainerCapability;
-import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.service.MicrocontainerService;
-import org.jboss.osgi.testing.OSGiBundle;
-import org.jboss.osgi.testing.OSGiPackageAdmin;
-import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiServiceReference;
-import org.jboss.osgi.testing.OSGiTest;
-import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- * Test MicrocontainerService
- *
- * @author thomas.diesler(a)jboss.com
- * @since 26-Nov-2009
- */
-@Ignore
-public class RefreshMicrocontainerServiceTestCase extends OSGiTest
-{
- @Test
- public void testMicrocontainerService() throws Exception
- {
- OSGiRuntime runtime = getDefaultRuntime();
- try
- {
- runtime.addCapability(new MicrocontainerCapability());
-
- OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
- bundle.start();
-
- // The service should be able to access the bean via the MicrocontainerService
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class,
SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
- assertEquals("hello", someBean.callSomeService("hello"));
-
- // Uninstall the user bundle
- bundle.uninstall();
-
- // Refresh all packages. This should stop/start the MC bundle
- OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
- packageAdmin.refreshPackages(null);
-
- // Wait some time for the refresh to finish
- Thread.sleep(1000);
-
- OSGiServiceReference sref =
runtime.getServiceReference(MicrocontainerService.class.getName());
- assertNotNull("MicrocontainerService available", sref);
- }
- finally
- {
- runtime.shutdown();
- }
- }
-}
\ No newline at end of file