[jboss-osgi-commits] JBoss-OSGI SVN: r97124 - in projects/jboss-osgi/projects/bundles/microcontainer/trunk: src/main/java/org/jboss/osgi/microcontainer and 5 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Sat Nov 28 06:33:12 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-11-28 06:33:12 -0500 (Sat, 28 Nov 2009)
New Revision: 97124
Added:
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/simple/SomeBeanMBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.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/AbstractMicrocontainerService.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/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java
Log:
[JBOSG-212] Add a test to the mc bundle module
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml 2009-11-28 11:33:12 UTC (rev 97124)
@@ -46,7 +46,7 @@
<!-- Please add alphabetically -->
<!-- simple-unmarshaller -->
- <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-unmarshaller.jar" files="${tests.resources.dir}/simple/simple-unmarshaller.bnd" />
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-bundle.jar" files="${tests.resources.dir}/simple/simple-bundle.bnd" />
<!-- Please add alphabetically -->
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-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -39,6 +39,8 @@
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,10 +59,10 @@
{
// Provide logging
private Logger log = LoggerFactory.getLogger(AbstractMicrocontainerDeployerService.class);
-
+
private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
private ServiceTracker registryTracker;
-
+
public abstract MainDeployer getMainDeployer();
public abstract BundleContext getBundleContext();
@@ -80,8 +82,17 @@
try
{
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
- getMainDeployer().removeDeployment(vfsdep.getName());
- getMainDeployer().process();
+ if (vfsdep != null)
+ {
+ getMainDeployer().removeDeployment(vfsdep.getName());
+ registry.unregisterDeployment(dep);
+ getMainDeployer().process();
+ }
+ else
+ {
+ DeployerService service = getSystemDeployerService();
+ service.undeploy(new Deployment[] { dep });
+ }
}
catch (Exception ex)
{
@@ -90,6 +101,17 @@
}
}
+ private DeployerService getSystemDeployerService() throws InvalidSyntaxException
+ {
+ BundleContext context = getBundleContext();
+ ServiceReference[] srefs = context.getServiceReferences(DeployerService.class.getName(), "(provider=system)");
+ if (srefs == null)
+ throw new IllegalStateException("Cannot obtain system DeployerService");
+
+ DeployerService service = (DeployerService)context.getService(srefs[0]);
+ return service;
+ }
+
public void deploy(Deployment[] depArr) throws BundleException
{
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
@@ -99,7 +121,7 @@
List<VFSDeployment> depList = new ArrayList<VFSDeployment>();
DeploymentRegistryService registry = getDeploymentRegistry();
-
+
for (Deployment dep : depArr)
{
VirtualFile root = dep.getRoot();
@@ -107,11 +129,11 @@
dep.addAttachment(VFSDeployment.class, vfsdep);
registry.registerDeployment(dep);
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()));
-
+
getMainDeployer().addDeployment(vfsdep);
}
@@ -138,26 +160,33 @@
public void undeploy(Deployment[] depArr) throws BundleException
{
- try
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ for (Deployment dep : depArr)
{
- DeploymentRegistryService registry = getDeploymentRegistry();
-
- for (Deployment dep : depArr)
+ try
{
- registry.unregisterDeployment(dep);
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
- getMainDeployer().removeDeployment(vfsdep.getName());
+ if (vfsdep != null)
+ {
+ getMainDeployer().removeDeployment(vfsdep.getName());
+ registry.unregisterDeployment(dep);
+ getMainDeployer().process();
+ }
+ else
+ {
+ DeployerService service = getSystemDeployerService();
+ service.undeploy(new Deployment[] { dep });
+ }
}
- getMainDeployer().process();
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.warn("Cannot undeploy bundles", ex);
+ }
}
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- log.warn("Cannot undeploy bundles", ex);
- }
}
private DeploymentRegistryService getDeploymentRegistry()
@@ -167,9 +196,11 @@
registryTracker = new ServiceTracker(getBundleContext(), DeploymentRegistryService.class.getName(), null);
registryTracker.open();
}
+
DeploymentRegistryService service = (DeploymentRegistryService)registryTracker.getService();
if (service == null)
throw new IllegalStateException("Cannot obtain DeploymentRegistryService");
+
return service;
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -102,10 +102,22 @@
}
catch (Throwable ex)
{
- throw new IllegalStateException("Cannot register bean: " + beanName, ex);
+ throw new IllegalStateException("Cannot install bean: " + beanName, ex);
}
}
+ protected void uninstallBean(KernelController controller, String beanName)
+ {
+ try
+ {
+ controller.uninstall(beanName);
+ }
+ catch (Throwable ex)
+ {
+ log.warn("Cannot uninstall bean: " + beanName, ex);
+ }
+ }
+
protected void registerMicrocontainerServiceMBean(MBeanServer mbeanServer)
{
try
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-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,16 +23,9 @@
//$Id$
-import java.util.Properties;
-
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
/**
* A BundleActivator that registers the {@link MicrocontainerService}
@@ -50,14 +43,12 @@
String systemBundleName = context.getBundle(0).getSymbolicName();
if ("org.jboss.osgi.framework".equals(systemBundleName))
return;
-
- // Get the classloader that is used to initialize the MC service
- ClassLoader classLoader = getClass().getClassLoader();
-
+
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try
{
- Thread.currentThread().setContextClassLoader(classLoader);
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
mcService = new MicrocontainerServiceImpl(context);
mcService.start();
}
@@ -65,10 +56,6 @@
{
Thread.currentThread().setContextClassLoader(ctxLoader);
}
-
- // Track the MicrocontainerService and register the DeployerService
- MicrocontainerServiceTracker tracker = new MicrocontainerServiceTracker(context, classLoader);
- tracker.open();
}
public void stop(BundleContext context)
@@ -76,41 +63,4 @@
if (mcService != null)
mcService.stop();
}
-
- /**
- * Register the DeployerService that uses the MC deployers
- */
- class MicrocontainerServiceTracker extends ServiceTracker
- {
- private ClassLoader classLoader;
-
- public MicrocontainerServiceTracker(BundleContext context, ClassLoader classLoader)
- {
- super(context, MicrocontainerService.class.getName(), null);
- this.classLoader = classLoader;
- }
-
- @Override
- public Object addingService(ServiceReference reference)
- {
- MicrocontainerService mcService = (MicrocontainerService)super.addingService(reference);
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(classLoader);
-
- Properties props = new Properties();
- props.setProperty("provider", "microcontainer");
- props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
- MainDeployer mainDeployer = (MainDeployer)mcService.getRegisteredBean("MainDeployer");
- MicrocontainerDeployerServiceImpl deployerService = new MicrocontainerDeployerServiceImpl(context, mainDeployer);
- context.registerService(DeployerService.class.getName(), deployerService, props);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
- return mcService;
- }
- }
}
\ No newline at end of file
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-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -28,17 +28,21 @@
import java.net.URL;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
import javax.management.MBeanServer;
+import org.jboss.deployers.client.spi.main.MainDeployer;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.jboss.osgi.microcontainer.AbstractMicrocontainerService;
import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.jboss.virtual.VFS;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -100,12 +104,12 @@
{
UnmarshallerService xmlService;
MBeanServer mbeanServer;
-
+
@Override
public Object addingService(ServiceReference sref)
{
Object service = super.addingService(sref);
-
+
List<String> classList = Arrays.asList((String[])sref.getProperty(OBJECTCLASS));
if (classList.contains(MBeanServer.class.getName()))
mbeanServer = (MBeanServer)service;
@@ -125,10 +129,13 @@
// Register the MicrocontainerService
context.registerService(MicrocontainerService.class.getName(), mcServiceImpl, null);
+ // Register the Microcontainer DeployerService
+ registerMicrocontainerDeployerService();
+
// Register the MicrocontainerServiceMBean
registerMicrocontainerServiceMBean(mbeanServer);
}
-
+
return service;
}
};
@@ -137,11 +144,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 registerMicrocontainerDeployerService()
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+ Properties props = new Properties();
+ props.setProperty("provider", "microcontainer");
+ props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+ MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+ MicrocontainerDeployerServiceImpl deployerService = new MicrocontainerDeployerServiceImpl(context, mainDeployer);
+ context.registerService(DeployerService.class.getName(), deployerService, props);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
+ }
}
\ No newline at end of file
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-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,18 +23,15 @@
//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler at jboss.com $
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
-import org.jboss.osgi.husky.HuskyCapability;
import org.jboss.osgi.microcontainer.MicrocontainerCapability;
-import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.spi.management.MBeanProxy;
+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.After;
-import org.junit.Before;
+import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
import org.junit.Test;
-import org.osgi.framework.BundleException;
/**
* Test MicrocontainerService
@@ -44,29 +41,27 @@
*/
public class BasicMicrocontainerTestCase extends OSGiTest
{
- private OSGiRuntime runtime;
-
- @Before
- public void setUp() throws Exception
- {
- runtime = getDefaultRuntime();
- runtime.addCapability(new HuskyCapability());
- runtime.addCapability(new MicrocontainerCapability());
-
- //OSGiBundle bundle = runtime.installBundle("simple-unmarshaller.jar");
- //bundle.start();
- }
-
- @After
- public void tearDown() throws BundleException
- {
- runtime.shutdown();
- }
-
@Test
public void testMicrocontainerService() throws Exception
{
- OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
- assertNotNull("MicrocontainerService available", sref);
+ OSGiRuntime runtime = getDefaultRuntime();
+ 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"));
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
}
}
\ No newline at end of file
Added: 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 (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,83 @@
+/*
+ * 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 at 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 at jboss.com
+ * @since 26-Nov-2009
+ */
+ at 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
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,8 +23,10 @@
//$Id: SomeServiceActivator.java 89664 2009-06-02 12:55:10Z thomas.diesler at jboss.com $
+import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* A Service Activator
@@ -36,6 +38,13 @@
{
public void start(BundleContext context)
{
+ ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
+ MicrocontainerService service = (MicrocontainerService)context.getService(sref);
+
+ SomeBean bean = (SomeBean)service.getRegisteredBean("SomeBean");
+ if (bean == null)
+ throw new IllegalStateException("No MC bean");
+
context.registerService(SomeService.class.getName(), new SomeService(context), null);
}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -21,8 +21,47 @@
*/
package org.jboss.test.osgi.microcontainer.simple;
+import javax.management.MBeanServer;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
//$Id: SomeBean.java 93025 2009-08-31 13:10:16Z thomas.diesler at jboss.com $
-public class SomeBean
+public class SomeBean implements SomeBeanMBean
{
+ private BundleContext bundleContext;
+ private MBeanServer mbeanServer;
+
+ public void setMbeanServer(MBeanServer server)
+ {
+ this.mbeanServer = server;
+ }
+
+ public void setBundleContext(BundleContext systemContext)
+ {
+ this.bundleContext = systemContext;
+ }
+
+ public String echo(String msg)
+ {
+ return msg;
+ }
+
+ public String callSomeService(String msg)
+ {
+ ServiceReference sref = bundleContext.getServiceReference(SomeService.class.getName());
+ SomeService service = (SomeService)bundleContext.getService(sref);
+ return service.callSomeBean(msg);
+ }
+
+ public void create() throws Exception
+ {
+ mbeanServer.registerMBean(this, MBEAN_NAME);
+ }
+
+ public void destroy() throws Exception
+ {
+ mbeanServer.unregisterMBean(MBEAN_NAME);
+ }
}
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,37 @@
+/*
+ * 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.simple;
+
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
+//$Id: SomeBeanMBean.java 93025 2009-08-31 13:10:16Z thomas.diesler at jboss.com $
+
+public interface SomeBeanMBean
+{
+ ObjectName MBEAN_NAME = ObjectNameFactory.create("jboss.osgi:bean=SomeBean");
+
+ String callSomeService(String msg);
+
+ String echo(String msg);
+}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -21,34 +21,34 @@
*/
package org.jboss.test.osgi.microcontainer.simple;
-//$Id: SomeService.java 93025 2009-08-31 13:10:16Z thomas.diesler at jboss.com $
-
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-/**
- * A service that accesses the MicrocontainerService
- *
- * @author thomas.diesler at jboss.com
- * @since 24-Apr-2009
- */
+//$Id: SomeService.java 93025 2009-08-31 13:10:16Z thomas.diesler at jboss.com $
+
public class SomeService
{
- // Provide logging
- private static Logger log = LoggerFactory.getLogger(SomeService.class);
-
+ private BundleContext context;
+
public SomeService(BundleContext context)
{
+ this.context = context;
+ }
+
+ public String callSomeBean(String msg)
+ {
+ MicrocontainerService mcService = getMicrocontainerService();
+ SomeBean bean = (SomeBean)mcService.getRegisteredBean("SomeBean");
+ return bean.echo(msg);
+ }
+
+ private MicrocontainerService getMicrocontainerService()
+ {
ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
- MicrocontainerService service = (MicrocontainerService)context.getService(sref);
+ if (sref == null)
+ throw new IllegalStateException("No MicrocontainerService");
- SomeBean bean = (SomeBean)service.getRegisteredBean("SomeBean");
- if (bean == null)
- throw new IllegalStateException("No MC bean");
-
- log.info("MC bean available");
+ return (MicrocontainerService)context.getService(sref);
}
}
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-bundleA.jar src/test/resources/simple/simple-bundleA.bnd
+
+Bundle-SymbolicName: simple-bundleA
+Bundle-Activator: org.jboss.test.osgi.microcontainer.simple.SimpleActivator
+Export-Package: org.jboss.test.osgi.microcontainer.simple
+Import-Package: org.slf4j, javax.management, org.jboss.osgi.spi.management, org.jboss.osgi.spi.service, org.osgi.framework
+Include-Resource: META-INF/simple-jboss-beans.xml=simple-jboss-beans.xml
+-removeheaders: Include-Resource
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,9 @@
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd" xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="SomeBean" class="org.jboss.test.osgi.microcontainer.simple.SomeBean">
+ <property name="bundleContext"><inject bean="jboss.osgi:service=BundleContext"/></property>
+ <property name="mbeanServer"><inject bean="jboss.osgi:service=MBeanServer"/></property>
+ </bean>
+
+</deployment>
+
More information about the jboss-osgi-commits
mailing list