[jboss-cvs] JBossAS SVN: r87916 - in projects/jboss-osgi/trunk: bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Apr 27 23:47:49 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-04-27 23:47:49 -0400 (Mon, 27 Apr 2009)
New Revision: 87916

Added:
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/MCServiceTestCase.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/SomeService.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/mcservice-jboss-beans.xml
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/mcservice-bundle.bnd
Removed:
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/MicrocontainerTestService.java
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/microcontainer-test.bnd
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/microcontainer/
Modified:
   projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/ServiceActivator.java
   projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerService.java
   projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerServiceMBean.java
   projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java
   projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
   projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/ServiceActivator.java
   projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-example-jars.xml
   projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
Log:
More work on MCService - ready to deploy beans.xml

Modified: projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/blueprint/scripts/antrun-test-jars.xml	2009-04-28 03:47:49 UTC (rev 87916)
@@ -46,8 +46,17 @@
     <!-- jmx-test -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jmx-test.jar" files="${tests.resources.dir}/jmx/jmx-test.bnd" />
 
-    <!-- microcontainer-test -->
-    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/microcontainer-test.jar" files="${tests.resources.dir}/microcontainer/microcontainer-test.bnd" />
+    <!-- mcservice-test -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/mcservice-bundle.jar" files="${tests.resources.dir}/mcservice/mcservice-bundle.bnd" />
+    <jar jarfile="${tests.output.dir}/test-libs/mcservice-beans.jar">
+      <fileset dir="${tests.classes.dir}">
+        <include name="org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.class" />
+        <include name="org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.class" />
+      </fileset>
+      <fileset dir="${tests.resources.dir}/mcservice">
+        <include name="META-INF/mcservice-jboss-beans.xml" />
+      </fileset>
+    </jar>
 
     <!-- Please add alphabetically -->
 

Copied: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/MCServiceTestCase.java (from rev 87908, projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/MCServiceTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/MCServiceTestCase.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,75 @@
+/*
+ * 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.blueprint.mcservice;
+
+//$Id$
+
+import static org.jboss.osgi.microcontainer.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
+import static org.jboss.osgi.microcontainer.MicrocontainerService.BEAN_SYSTEM_BUNDLE_CONTEXT;
+import static org.jboss.osgi.microcontainer.MicrocontainerService.BEAN_MBEAN_SERVER;
+import static org.jboss.osgi.microcontainer.MicrocontainerService.BEAN_KERNEL;
+
+import java.util.List;
+
+import org.jboss.osgi.microcontainer.MicrocontainerServiceMBean;
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.test.osgi.blueprint.BlueprintTest;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A test that checks whether the MicrocontainerService can be accessed
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 12-Feb-2009
+ */
+public class MCServiceTestCase extends BlueprintTest
+{
+   public void testMCServiceAccess() throws Exception
+   {
+      OSGiFramework framework = getBootstrapProvider().getFramework();
+      try
+      {
+         BundleContext sysContext = framework.getSystemBundleContext();
+         
+         Bundle bundle = installBundle(sysContext, "mcservice-bundle.jar", true);
+         assertEquals("Test bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
+         
+         MicrocontainerServiceMBean mcService = MBeanProxy.get(MicrocontainerServiceMBean.class, MBEAN_MICROCONTAINER_SERVICE, getMBeanServer());
+         List<String> registeredBeans = mcService.getRegisteredBeans();
+         assertTrue("MicrocontainerService registered with MC", registeredBeans.contains(BEAN_SYSTEM_BUNDLE_CONTEXT));
+         assertTrue("MBeanServer registered with MC", registeredBeans.contains(BEAN_MBEAN_SERVER));
+         assertTrue("Kernel registered with MC", registeredBeans.contains(BEAN_KERNEL));
+      }
+      finally
+      {
+         framework.stop();
+      }
+   }
+   
+   public void testBeansDeployment() throws Exception
+   {
+      MicrocontainerServiceMBean mcService = MBeanProxy.get(MicrocontainerServiceMBean.class, MBEAN_MICROCONTAINER_SERVICE, getMBeanServer());
+      //mcService.deploy(getTestArchiveURL("mcservice-beans.jar"));
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,75 @@
+/*
+ * 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.blueprint.mcservice.beans;
+
+//$Id$
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.test.osgi.blueprint.mcservice.bundle.SomeService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * An MC bean that accesses some OSGi service
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class SomeBean implements SomeBeanMBean
+{
+   private BundleContext context;
+   private MBeanServer mbeanServer;
+
+   public void setBundleContext(BundleContext context)
+   {
+      this.context = context;
+   }
+
+   public void setMbeanServer(MBeanServer server)
+   {
+      this.mbeanServer = server;
+   }
+
+   public void create() throws Exception
+   {
+      mbeanServer.registerMBean(this, new ObjectName("jboss.osgi:service=SomeBean"));
+   }
+   
+   public void destroy() throws Exception
+   {
+      mbeanServer.unregisterMBean(new ObjectName("jboss.osgi:service=SomeBean"));
+   }
+   
+   public String callSomeService(String msg)
+   {
+      ServiceReference sref = context.getServiceReference(SomeService.class.getName());
+      SomeService service = (SomeService)context.getService(sref);
+      return service.echo(msg);
+   }
+   
+   public String echo(String msg)
+   {
+      return msg;
+   }
+}


Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,31 @@
+/*
+ * 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.blueprint.mcservice.beans;
+
+//$Id$
+
+public interface SomeBeanMBean
+{
+   String callSomeService(String msg);
+
+   String echo(String msg);
+}


Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/beans/SomeBeanMBean.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle (from rev 87908, projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/bundle)

Deleted: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/MicrocontainerTestService.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/bundle/MicrocontainerTestService.java	2009-04-27 23:05:19 UTC (rev 87908)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/MicrocontainerTestService.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -1,51 +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.blueprint.microcontainer.bundle;
-
-//$Id$
-
-import org.jboss.osgi.microcontainer.MicrocontainerService;
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * A service that accesses the MicrocontainerService
- * 
- * @author thomas.diesler at jboss.com
- * @since 24-Apr-2009
- */
-public class MicrocontainerTestService
-{
-   public MicrocontainerTestService(BundleContext context)
-   {
-      ServiceTracker tracker = new ServiceTracker(context, MicrocontainerService.class.getName(), null);
-      tracker.open();
-      
-      MicrocontainerService mcService = (MicrocontainerService)tracker.getService();
-      if (mcService == null)
-         throw new IllegalStateException("No MicrocontainerService");
-
-      Object sysContextBean = mcService.getRegisteredBean(MicrocontainerService.BEAN_SYSTEM_BUNDLE_CONTEXT);
-      if (sysContextBean == null)
-         throw new IllegalStateException("No OSGi System Context as MC Bean");
-   }
-}

Modified: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/bundle/ServiceActivator.java	2009-04-27 23:05:19 UTC (rev 87908)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/ServiceActivator.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -19,7 +19,7 @@
  * 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.blueprint.microcontainer.bundle;
+package org.jboss.test.osgi.blueprint.mcservice.bundle;
 
 //$Id$
 
@@ -36,8 +36,8 @@
 {
    public void start(BundleContext context)
    {
-      MicrocontainerTestService service = new MicrocontainerTestService(context);
-      context.registerService(MicrocontainerTestService.class.getName(), service, null);
+      SomeService service = new SomeService(context);
+      context.registerService(SomeService.class.getName(), service, null);
    }
 
    public void stop(BundleContext context)

Copied: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/SomeService.java (from rev 87908, projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/bundle/MicrocontainerTestService.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/SomeService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/mcservice/bundle/SomeService.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,73 @@
+/*
+ * 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.blueprint.mcservice.bundle;
+
+//$Id$
+
+import static org.jboss.osgi.microcontainer.MicrocontainerService.BEAN_SYSTEM_BUNDLE_CONTEXT;
+
+import org.jboss.osgi.microcontainer.MicrocontainerService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A service that accesses the MicrocontainerService
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 24-Apr-2009
+ */
+public class SomeService
+{
+   private BundleContext context;
+   
+   public SomeService(BundleContext context)
+   {
+      this.context = context;
+      
+      MicrocontainerService mcService = getMicrocontainerService();
+      BundleContext bundleContext = (BundleContext)mcService.getRegisteredBean(BEAN_SYSTEM_BUNDLE_CONTEXT);
+      if (bundleContext == null)
+         throw new IllegalStateException("No BundleContext as MC Bean");
+   }
+
+//   public String callSomeBean(String msg)
+//   {
+//      MicrocontainerService mcService = getMicrocontainerService();
+//      SomeBean bean = (SomeBean)mcService.getRegisteredBean(SomeBean.class.getName());
+//      return bean.echo(msg);
+//   }
+   
+   public String echo(String msg)
+   {
+      return msg;
+   }
+
+   private MicrocontainerService getMicrocontainerService()
+   {
+      ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
+      MicrocontainerService service = (MicrocontainerService)context.getService(sref);
+      if (service == null)
+         throw new IllegalStateException("No MicrocontainerService");
+      
+      return service;
+   }
+}

Copied: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice (from rev 87908, projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/microcontainer)

Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/mcservice-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/mcservice-jboss-beans.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/mcservice-jboss-beans.xml	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,7 @@
+<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.blueprint.mcservice.beans.SomeBean">
+  </bean>
+
+</deployment>
+


Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/META-INF/mcservice-jboss-beans.xml
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/mcservice-bundle.bnd (from rev 87908, projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/microcontainer/microcontainer-test.bnd)
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/mcservice-bundle.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/mcservice-bundle.bnd	2009-04-28 03:47:49 UTC (rev 87916)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/mcservice-bundle.jar src/test/resources/mcservice/mcservice-bundle.bnd
+
+Bundle-SymbolicName: mcservice-test
+Bundle-Activator: org.jboss.test.osgi.blueprint.mcservice.bundle.ServiceActivator
+Export-Package: org.jboss.test.osgi.blueprint.mcservice.bundle 
+Import-Package: org.jboss.osgi.microcontainer, org.osgi.framework
+
+#org.jboss.test.osgi.blueprint.mcservice.beans;resolution=optional 

Deleted: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/microcontainer-test.bnd
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/microcontainer/microcontainer-test.bnd	2009-04-27 23:05:19 UTC (rev 87908)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/mcservice/microcontainer-test.bnd	2009-04-28 03:47:49 UTC (rev 87916)
@@ -1,5 +0,0 @@
-# bnd build -classpath target/test-classes -output target/test-libs/microcontainer-test.jar src/test/resources/microcontainer/microcontainer-test.bnd
-
-Bundle-SymbolicName: microcontainer-test
-Bundle-Activator: org.jboss.test.osgi.blueprint.microcontainer.bundle.ServiceActivator
-Export-Package: org.jboss.test.osgi.blueprint.microcontainer.bundle 

Modified: projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerService.java	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerService.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import java.net.URL;
 import java.util.List;
 
 import org.jboss.kernel.Kernel;
@@ -36,10 +37,20 @@
 public interface MicrocontainerService
 {
    /** 
-    * The bean name under which the system bundle context is registered: 'jboss.osgi:service=SystemBundleContext' 
+    * The name under which the system bundle context is registered: 'jboss.osgi:service=SystemBundleContext' 
     */
    String BEAN_SYSTEM_BUNDLE_CONTEXT = "jboss.osgi:service=SystemBundleContext";
 
+   /** 
+    * The name under which the MBeanServer is registered: 'jboss.osgi:service=MBeanServer' 
+    */
+   String BEAN_MBEAN_SERVER = "jboss.osgi:service=SystemBundleContext";
+
+   /** 
+    * The name under which the Kernel is registered: 'jboss.osgi:service=Kernel' 
+    */
+   String BEAN_KERNEL = "jboss.osgi:service=Kernel";
+
    /**
     * Get the Microcontainer Kernel
     */
@@ -55,4 +66,14 @@
     * @return null if there is no bean registered under this name
     */
    Object getRegisteredBean(String beanName);
+
+   /** 
+    * Deploy MC beans from URL
+    */
+   void deploy(URL url);
+
+   /**
+    * Undeploy MC beans from URL
+    */
+   void undeploy(URL url);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerServiceMBean.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerServiceMBean.java	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/MicrocontainerServiceMBean.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import java.net.URL;
 import java.util.List;
 
 import javax.management.ObjectName;
@@ -46,4 +47,14 @@
     * Get the list of registered beans.
     */
    List<String> getRegisteredBeans();
+
+   /** 
+    * Deploy MC beans from URL
+    */
+   void deploy(URL url);
+
+   /**
+    * Undeploy MC beans from URL
+    */
+   void undeploy(URL url);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/EmbeddedBeansDeployer.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -47,7 +47,7 @@
       this.log = new LogServiceTracker(context);
       
       // Get or bootstrap the kernel
-      if (getKernel() == null)
+      if (kernel == null)
       {
          try
          {
@@ -62,8 +62,8 @@
       deployer = new BasicXMLDeployer(kernel);
    }
 
-   /*
-    * * Deploy MC beans from URL
+   /** 
+    * Deploy MC beans from URL
     */
    public void deploy(URL url)
    {
@@ -79,8 +79,8 @@
       }
    }
 
-   /*
-    * * Undeploy MC beans from URL
+   /**
+    * Undeploy MC beans from URL
     */
    public void undeploy(URL url)
    {

Modified: projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -23,6 +23,7 @@
 
 //$Id$
 
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -32,8 +33,10 @@
 import org.jboss.dependency.plugins.AbstractControllerContextActions;
 import org.jboss.dependency.plugins.action.ControllerContextAction;
 import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.osgi.microcontainer.MicrocontainerService;
 import org.jboss.osgi.microcontainer.MicrocontainerServiceMBean;
 import org.osgi.framework.BundleContext;
@@ -46,19 +49,20 @@
  */
 public class MicrocontainerServiceImpl implements MicrocontainerService, MicrocontainerServiceMBean
 {
-   private Kernel kernel;
+   private EmbeddedBeansDeployer deployer;
 
    public MicrocontainerServiceImpl(BundleContext context)
    {
-      EmbeddedBeansDeployer deployer = new EmbeddedBeansDeployer(context);
-      kernel = deployer.getKernel();
+      deployer = new EmbeddedBeansDeployer(context);
       
-      // Register the OSGi system context as an MC bean
+      // Preregister some beans
       try
       {
-         AbstractControllerContextActions actions = new AbstractControllerContextActions(new HashMap<ControllerState, ControllerContextAction>());
-         ControllerContext ctrlContext = new AbstractControllerContext(BEAN_SYSTEM_BUNDLE_CONTEXT, actions, null, context);
-         kernel.getController().install(ctrlContext);
+         Kernel kernel = getKernel();
+         KernelController controller = kernel.getController();
+         ControllerContextActions actions = new AbstractControllerContextActions(new HashMap<ControllerState, ControllerContextAction>());
+         controller.install(new AbstractControllerContext(BEAN_SYSTEM_BUNDLE_CONTEXT, actions, null, context));
+         controller.install(new AbstractControllerContext(BEAN_KERNEL, actions, null, kernel));
       }
       catch (RuntimeException rte)
       {
@@ -66,20 +70,20 @@
       }
       catch (Throwable ex)
       {
-         throw new IllegalStateException("Cannot register: " + BEAN_SYSTEM_BUNDLE_CONTEXT, ex);
+         throw new IllegalStateException("Cannot register MC bean", ex);
       }
    }
 
    public Kernel getKernel()
    {
-      return kernel;
+      return deployer.getKernel();
    }
 
    public List<String> getRegisteredBeans()
    {
       List<String> names = new ArrayList<String>();
       
-      AbstractController controller = (AbstractController)kernel.getController();
+      AbstractController controller = (AbstractController)getKernel().getController();
       for (ControllerContext ctx : controller.getAllContexts())
          names.add(ctx.getName().toString());
          
@@ -88,7 +92,35 @@
 
    public Object getRegisteredBean(String beanName)
    {
-      ControllerContext context = kernel.getController().getInstalledContext(beanName);
+      ControllerContext context = getKernel().getController().getInstalledContext(beanName);
       return context != null ? context.getTarget() : null;
    }
+
+   public void deploy(URL url)
+   {
+      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+         deployer.deploy(url);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(ctxLoader);
+      }
+   }
+
+   public void undeploy(URL url)
+   {
+      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+      try
+      {
+         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+         deployer.undeploy(url);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(ctxLoader);
+      }
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/ServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/ServiceActivator.java	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/ServiceActivator.java	2009-04-28 03:47:49 UTC (rev 87916)
@@ -23,9 +23,19 @@
 
 //$Id$
 
+import static org.jboss.osgi.microcontainer.MicrocontainerService.BEAN_MBEAN_SERVER;
+import static org.jboss.osgi.microcontainer.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
+
+import java.util.HashMap;
+
 import javax.management.MBeanServer;
 import javax.management.StandardMBean;
 
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.plugins.AbstractControllerContextActions;
+import org.jboss.dependency.plugins.action.ControllerContextAction;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.osgi.common.log.LogServiceTracker;
 import org.jboss.osgi.microcontainer.MicrocontainerService;
 import org.jboss.osgi.microcontainer.MicrocontainerServiceMBean;
@@ -53,20 +63,31 @@
       log = new LogServiceTracker(context);
 
       // Register the MicrocontainerService as OSGi service
-      MicrocontainerService mcService = registerOSGiService(context);
+      MicrocontainerServiceImpl mcService = registerOSGiService(context);
 
       // Track the MBeanServer to register the MicrocontainerServiceMBean
-      mbeanServerTracker = new MBeanServerTracker(context, (MicrocontainerServiceMBean)mcService);
+      mbeanServerTracker = new MBeanServerTracker(context, mcService);
       mbeanServerTracker.open();
    }
 
-   private MicrocontainerService registerOSGiService(BundleContext context)
+   public void stop(BundleContext context)
    {
+      if (registration != null)
+      {
+         log.log(LogService.LOG_DEBUG, "Unregister MicrocontainerService");
+         registration.unregister();
+         unregisterMBean(context);
+         registration = null;
+      }
+   }
+
+   private MicrocontainerServiceImpl registerOSGiService(BundleContext context)
+   {
       ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
       try
       {
          Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-         MicrocontainerService service = new MicrocontainerServiceImpl(context);
+         MicrocontainerServiceImpl service = new MicrocontainerServiceImpl(context);
 
          log.log(LogService.LOG_DEBUG, "Register MicrocontainerService");
          registration = context.registerService(MicrocontainerService.class.getName(), service, null);
@@ -81,12 +102,12 @@
    private void unregisterMBean(BundleContext context)
    {
       MBeanServer server = (MBeanServer)mbeanServerTracker.getService();
-      if (server != null)
+      if (server != null && server.isRegistered(MBEAN_MICROCONTAINER_SERVICE))
       {
          try
          {
             log.log(LogService.LOG_DEBUG, "Unregister MicrocontainerServiceMBean");
-            server.unregisterMBean(MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE);
+            server.unregisterMBean(MBEAN_MICROCONTAINER_SERVICE);
          }
          catch (Exception ex)
          {
@@ -95,22 +116,11 @@
       }
    }
 
-   public void stop(BundleContext context)
-   {
-      if (registration != null)
-      {
-         log.log(LogService.LOG_DEBUG, "Unregister MicrocontainerService");
-         registration.unregister();
-         unregisterMBean(context);
-         registration = null;
-      }
-   }
-
    class MBeanServerTracker extends ServiceTracker
    {
-      private MicrocontainerServiceMBean mcService;
+      private MicrocontainerServiceImpl mcService;
 
-      public MBeanServerTracker(BundleContext context, MicrocontainerServiceMBean mcService)
+      public MBeanServerTracker(BundleContext context, MicrocontainerServiceImpl mcService)
       {
          super(context, MBeanServer.class.getName(), null);
          this.mcService = mcService;
@@ -119,23 +129,53 @@
       public Object addingService(ServiceReference reference)
       {
          MBeanServer server = (MBeanServer)super.addingService(reference);
+         
+         // Register the MicrocontainerServiceMBean
          try
          {
             log.log(LogService.LOG_DEBUG, "Register MicrocontainerServiceMBean");
             StandardMBean mbean = new StandardMBean(mcService, MicrocontainerServiceMBean.class);
-            server.registerMBean(mbean, MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE);
+            server.registerMBean(mbean, MBEAN_MICROCONTAINER_SERVICE);
          }
          catch (Exception ex)
          {
             throw new IllegalStateException("Cannot register MicrocontainerServiceMBean", ex);
          }
+         
+         // Install the MBeanServer with the Kernel
+         try
+         {
+            ControllerContextActions actions = new AbstractControllerContextActions(new HashMap<ControllerState, ControllerContextAction>());
+            mcService.getKernel().getController().install(new AbstractControllerContext(BEAN_MBEAN_SERVER, actions, null, server));
+         }
+         catch (RuntimeException rte)
+         {
+            throw rte;
+         }
+         catch (Throwable ex)
+         {
+            throw new IllegalStateException("Cannot register MC bean", ex);
+         }
+         
          return server;
       }
 
       @Override
       public void removedService(ServiceReference reference, Object service)
       {
-         unregisterMBean(context);
+         // Uninstall the MBeanServer from the Kernel
+         try
+         {
+            mcService.getKernel().getController().uninstall(BEAN_MBEAN_SERVER);
+         }
+         catch (RuntimeException rte)
+         {
+            throw rte;
+         }
+         catch (Throwable ex)
+         {
+            throw new IllegalStateException("Cannot register MC bean", ex);
+         }
          super.removedService(reference, service);
       }
    }

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-example-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-example-jars.xml	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-example-jars.xml	2009-04-28 03:47:49 UTC (rev 87916)
@@ -42,12 +42,12 @@
 
     <!-- Please add alphabetically -->
 
+    <!-- example/http -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example/example-http.jar" files="${tests.resources.dir}/example/http/example-http.bnd" />
+
     <!-- example/log -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example/example-log.jar" files="${tests.resources.dir}/example/log/example-log.bnd" />
   	
-    <!-- example/http -->
-    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example/example-http.jar" files="${tests.resources.dir}/example/http/example-http.bnd" />
-
     <!-- example/microcontainer -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example/example-microcontainer.jar" files="${tests.resources.dir}/example/microcontainer/example-microcontainer.bnd" />
   	

Modified: projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2009-04-28 03:36:16 UTC (rev 87915)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml	2009-04-28 03:47:49 UTC (rev 87916)
@@ -78,7 +78,7 @@
     <!-- jbosgi41 -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi41-bundleA.jar" files="${tests.resources.dir}/jbosgi41/jbosgi41-bundleA.bnd" />
   	
-    <!-- startlevel-service -->
+    <!-- service-startlevel -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/service/service-startlevel.jar" files="${tests.resources.dir}/service/startlevel/service-startlevel.bnd" />
 
     <!-- Please add alphabetically -->




More information about the jboss-cvs-commits mailing list