[jboss-osgi-commits] JBoss-OSGI SVN: r89588 - in projects/jboss-osgi/branches/tdiesler: bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal and 11 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Mon Jun 1 03:50:26 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-06-01 03:50:26 -0400 (Mon, 01 Jun 2009)
New Revision: 89588
Added:
projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/
projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/
projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java
projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/MicrocontainerServiceBean.java
Removed:
projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/jbossas/integration/
projects/jboss-osgi/branches/tdiesler/spi/src/main/java/org/jboss/osgi/spi/service/AbstractMicrocontainerService.java
Modified:
projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/pom.xml
projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
projects/jboss-osgi/branches/tdiesler/distribution/runtime/conf/jboss-osgi-felix.properties
projects/jboss-osgi/branches/tdiesler/distribution/src/main/resources/installer/install-definition.xml
projects/jboss-osgi/branches/tdiesler/integration/jbossas/pom.xml
projects/jboss-osgi/branches/tdiesler/runtime/equinox/src/main/resources/osgi-deployers-jboss-beans.xml
projects/jboss-osgi/branches/tdiesler/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml
projects/jboss-osgi/branches/tdiesler/runtime/knopflerfish/src/main/resources/osgi-deployers-jboss-beans.xml
Log:
WIP
Modified: projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/pom.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/pom.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/pom.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -29,11 +29,15 @@
</dependency>
<dependency>
<groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-deployers</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.osgi</groupId>
- <artifactId>jboss-osgi-deployers</artifactId>
+ <artifactId>jboss-osgi-integration-jbossas</artifactId>
</dependency>
<!-- Bundle Dependencies -->
@@ -140,6 +144,7 @@
jboss-metatype;inline=false,
jboss-mdr;inline=false,
jboss-osgi-deployers;inline=false,
+ jboss-osgi-integration-jbossas;inline=false,
jboss-kernel;inline=false,
</Embed-Dependency>
<_exportcontents>
Modified: projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/bundles/microcontainer/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-06-01 07:50:26 UTC (rev 89588)
@@ -31,7 +31,7 @@
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.spi.service.AbstractMicrocontainerService;
+import org.jboss.osgi.integration.jbossas.AbstractMicrocontainerService;
import org.jboss.osgi.spi.service.DeployerService;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.jboss.osgi.spi.service.MicrocontainerServiceMBean;
Modified: projects/jboss-osgi/branches/tdiesler/distribution/runtime/conf/jboss-osgi-felix.properties
===================================================================
--- projects/jboss-osgi/branches/tdiesler/distribution/runtime/conf/jboss-osgi-felix.properties 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/distribution/runtime/conf/jboss-osgi-felix.properties 2009-06-01 07:50:26 UTC (rev 89588)
@@ -45,26 +45,15 @@
org.jboss.osgi.spi;version=1.0, \
org.jboss.osgi.spi.logging;version=1.0, \
org.jboss.osgi.spi.management;version=1.0, \
+ org.jboss.osgi.spi.service;version=1.0, \
org.jboss.osgi.spi.testing;version=1.0, \
org.jboss.osgi.spi.testing.capability;version=1.0, \
org.jboss.virtual, \
org.jboss.virtual.plugins.registry, \
org.jboss.virtual.plugins.context.jar, \
org.jboss.virtual.plugins.vfs.helpers, \
- org.jboss.virtual.protocol, \
- org.apache.log4j, \
- org.jboss.util, \
- org.jboss.util.id, \
- org.jboss.util.threadpool, \
- org.jboss.util.propertyeditor
+ org.jboss.virtual.protocol
-# These are needed by jboss-remoting
-# org.apache.log4j, \
-# org.jboss.util, \
-# org.jboss.util.id, \
-# org.jboss.util.threadpool, \
-# org.jboss.util.propertyeditor
-
# Bundles that need to be installed with the Framework automatically
org.jboss.osgi.spi.framework.autoInstall=\
file://${osgi.home}/server/minimal/bundles/org.osgi.compendium.jar
Modified: projects/jboss-osgi/branches/tdiesler/distribution/src/main/resources/installer/install-definition.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/distribution/src/main/resources/installer/install-definition.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/distribution/src/main/resources/installer/install-definition.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -272,7 +272,6 @@
<!-- deployers/osgi.deployer -->
<fileset dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer" override="true">
- <include name="jboss-osgi-common.jar" />
<include name="jboss-osgi-deployers.jar" />
<include name="jboss-osgi-integration-jbossas.jar" />
<include name="jboss-osgi-microcontainer.jar" />
@@ -281,6 +280,8 @@
<!-- deploy/osgi -->
<fileset dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
+ <include name="jboss-osgi-common.jar" />
+ <include name="jboss-osgi-webconsole.jar" />
<include name="org.apache.felix.configadmin.jar" />
<include name="org.apache.felix.http.jetty.jar" />
<include name="org.apache.felix.log.jar" />
@@ -292,13 +293,12 @@
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer" override="true">
<include name="jboss-osgi-runtime-felix.jar" />
<include name="org.apache.felix.framework.jar" />
- <include name="org.osgi.compendium.jar" />
</fileset>
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/resources/jboss-osgi-runtime-felix" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF" override="true">
<include name="osgi-deployers-jboss-beans.xml" />
</fileset>
<fileset condition="isFelix" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
- <include name="jboss-osgi-webconsole.jar" />
+ <include name="org.osgi.compendium.jar" />
</fileset>
<!-- Equinox Integration -->
@@ -307,28 +307,26 @@
<include name="jboss-osgi-runtime-equinox.jar" />
<include name="org.apache.equinox.framework.jar" />
<include name="org.eclipse.osgi.jar"/>
- <include name="org.eclipse.osgi.services.jar" />
</fileset>
<fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/resources/jboss-osgi-runtime-equinox" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF" override="true">
<include name="osgi-deployers-jboss-beans.xml" />
</fileset>
- <!-- does not work with compendium in system classpath
<fileset condition="isEquinox" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
+ <include name="org.eclipse.osgi.services.jar" />
<include name="jboss-osgi-webconsole.jar" />
- </fileset
- -->
+ </fileset>
<!-- Knopflerfish Integration -->
<fileset condition="isKnopflerfish" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer" override="true">
<include name="jboss-osgi-runtime-knopflerfish.jar" />
<include name="org.knopflerfish.framework.jar" />
- <include name="org.osgi.compendium.jar" />
</fileset>
<fileset condition="isKnopflerfish" dir="@{deploy.artifacts.dir}/resources/jboss-osgi-runtime-knopflerfish" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deployers/osgi.deployer/META-INF" override="true">
<include name="osgi-deployers-jboss-beans.xml" />
</fileset>
<fileset condition="isKnopflerfish" dir="@{deploy.artifacts.dir}/lib" targetdir="${jbossInstallPath}/server/${jbossTargetServer}/deploy/osgi" override="true">
+ <include name="org.osgi.compendium.jar" />
<include name="jboss-osgi-webconsole.jar" />
</fileset>
Modified: projects/jboss-osgi/branches/tdiesler/integration/jbossas/pom.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/integration/jbossas/pom.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/integration/jbossas/pom.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -22,14 +22,6 @@
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-spi</artifactId>
</dependency>
- <dependency>
- <groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-microcontainer</artifactId>
- </dependency>
<!-- OSGi Dependencies -->
<dependency>
Added: projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java (rev 0)
+++ projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java 2009-06-01 07:50:26 UTC (rev 89588)
@@ -0,0 +1,264 @@
+/*
+ * 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.integration.jbossas;
+
+//$Id$
+
+import static org.jboss.osgi.spi.service.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.StandardMBean;
+
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.dependency.plugins.AbstractControllerContext;
+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.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.osgi.spi.service.BundleInfo;
+import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.spi.service.MicrocontainerServiceMBean;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.BundleException;
+
+/**
+ * An OSGi Service the gives access to the Kernel.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public abstract class AbstractMicrocontainerService implements DeployerService, MicrocontainerService
+{
+ private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
+ private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
+
+ public abstract Kernel getKernel();
+
+ public abstract void logDebug(String message);
+
+ public abstract void logWarning(String message, Exception ex);
+
+ public void logWarning(String message)
+ {
+ logWarning(message, null);
+ }
+
+ public List<String> getRegisteredBeans()
+ {
+ List<String> names = new ArrayList<String>();
+
+ AbstractController controller = (AbstractController)getKernel().getController();
+ for (ControllerContext ctx : controller.getAllContexts())
+ {
+ if (ctx instanceof KernelControllerContext || ctx instanceof PreInstalledControllerContext)
+ names.add(ctx.getName().toString());
+ }
+
+ return names;
+ }
+
+ public Object getRegisteredBean(String beanName)
+ {
+ ControllerContext context = getKernel().getController().getInstalledContext(beanName);
+ return context != null ? context.getTarget() : null;
+ }
+
+ public void deploy(URL url) throws BundleException
+ {
+ deployInternal(new URL[] { url });
+ }
+
+ public boolean undeploy(URL url) throws BundleException
+ {
+ String deploymentName = contextMap.remove(url);
+ if (deploymentName == null)
+ {
+ logWarning("Package not deployed: " + url);
+ return false;
+ }
+
+ try
+ {
+ MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+ mainDeployer.removeDeployment(deploymentName);
+ mainDeployer.process();
+ return true;
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ logWarning("Cannot undeploy bundle", ex);
+ return false;
+ }
+ }
+
+ public void deploy(BundleInfo[] bundles) throws BundleException
+ {
+ URL[] urls = new URL[bundles.length];
+ for (int i = 0; i < bundles.length; i++)
+ urls[i] = bundles[i].getLocation();
+
+ deployInternal(urls);
+ }
+
+ private void deployInternal(URL[] urls) throws BundleException
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+ List<Deployment> deployments = new ArrayList<Deployment>();
+ MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+ for (URL location : urls)
+ {
+ VirtualFile file = VFS.createNewRoot(location);
+ VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+ mainDeployer.addDeployment(deployment);
+ deployments.add(deployment);
+ contextMap.put(location, deployment.getName());
+ }
+
+ // Process the deployments
+ mainDeployer.process();
+
+ // Check for completeness
+ Deployment[] depArr = deployments.toArray(new Deployment[deployments.size()]);
+ mainDeployer.checkComplete(depArr);
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new BundleException("Cannot deploy bundles", ex);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
+ }
+
+ public void undeploy(BundleInfo[] bundles) throws BundleException
+ {
+ try
+ {
+ MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+ for (BundleInfo bundle : bundles)
+ {
+ String deploymentName = contextMap.remove(bundle.getLocation());
+ if (deploymentName != null)
+ {
+ mainDeployer.removeDeployment(deploymentName);
+ }
+ else
+ {
+ logWarning("Package not deployed: " + bundle.getLocation());
+ }
+ }
+ mainDeployer.process();
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ logWarning("Cannot undeploy bundles", ex);
+ }
+ }
+
+ protected void installBean(KernelController controller, String beanName, Object beanImpl)
+ {
+ try
+ {
+ ControllerContextActions actions = new AbstractControllerContextActions(new HashMap<ControllerState, ControllerContextAction>());
+ controller.install(new PreInstalledControllerContext(beanName, actions, beanImpl));
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Throwable ex)
+ {
+ throw new IllegalStateException("Cannot register bean: " + beanName, ex);
+ }
+ }
+
+ protected void registerMicrocontainerServiceMBean(MBeanServer mbeanServer)
+ {
+ try
+ {
+ StandardMBean mbean = new StandardMBean((MicrocontainerServiceMBean)this, MicrocontainerServiceMBean.class);
+ mbeanServer.registerMBean(mbean, MBEAN_MICROCONTAINER_SERVICE);
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot register MicrocontainerServiceMBean", ex);
+ }
+ }
+
+ protected void unregisterMicrocontainerServiceMBean(MBeanServer mbeanServer)
+ {
+ if (mbeanServer.isRegistered(MBEAN_MICROCONTAINER_SERVICE))
+ {
+ try
+ {
+ logDebug("Unregister MicrocontainerServiceMBean");
+ mbeanServer.unregisterMBean(MBEAN_MICROCONTAINER_SERVICE);
+ }
+ catch (Exception ex)
+ {
+ logWarning("Cannot unregister MicrocontainerServiceMBean", ex);
+ }
+ }
+ }
+
+ static class PreInstalledControllerContext extends AbstractControllerContext
+ {
+ public PreInstalledControllerContext(Object name, ControllerContextActions actions, Object target)
+ {
+ super(name, actions, null, target);
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/MicrocontainerServiceBean.java (from rev 89587, projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/jbossas/integration/MicrocontainerServiceBean.java)
===================================================================
--- projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/MicrocontainerServiceBean.java (rev 0)
+++ projects/jboss-osgi/branches/tdiesler/integration/jbossas/src/main/java/org/jboss/osgi/integration/jbossas/MicrocontainerServiceBean.java 2009-06-01 07:50:26 UTC (rev 89588)
@@ -0,0 +1,139 @@
+/*
+ * 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.integration.jbossas;
+
+//$Id$
+
+import java.util.Properties;
+
+import javax.management.MBeanServer;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.spi.service.MicrocontainerServiceMBean;
+import org.osgi.framework.BundleContext;
+
+/**
+ * An implementation of the {@link DeployerService} and {@link MicrocontainerService}
+ * which is installed as MC bean in jbossas.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 05-May-2009
+ */
+public class MicrocontainerServiceBean extends AbstractMicrocontainerService implements MicrocontainerServiceMBean
+{
+ private static Logger log = Logger.getLogger(MicrocontainerServiceBean.class);
+
+ private BundleContext context;
+ private MBeanServer mbeanServer;
+ private Kernel kernel;
+
+ public void setSystemContext(BundleContext context)
+ {
+ this.context = context;
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public void setKernel(Kernel kernel)
+ {
+ this.kernel = kernel;
+ }
+
+ public Kernel getKernel()
+ {
+ return kernel;
+ }
+
+ @Override
+ public void logDebug(String message)
+ {
+ log.debug(message);
+ }
+
+ @Override
+ public void logWarning(String message, Exception ex)
+ {
+ log.warn(message, ex);
+ }
+
+ public void start()
+ {
+ Kernel kernel = getKernel();
+ KernelController controller = kernel.getController();
+
+ // Register the MBeanServer
+ context.registerService(MBeanServer.class.getName(), mbeanServer, null);
+ log.debug("MBeanServer registered");
+
+ // Register the InitialContext service
+ registerInitialContext();
+ log.debug("InitialContext registered");
+
+ // Preregister some beans
+ installBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT, context);
+ installBean(controller, BEAN_KERNEL, kernel);
+ installBean(controller, BEAN_KERNEL_CONTROLLER, controller);
+ installBean(controller, BEAN_MBEAN_SERVER, mbeanServer);
+
+ // Register the MicrocontainerService
+ log.debug("Register MicrocontainerService");
+ context.registerService(MicrocontainerService.class.getName(), this, null);
+ log.debug("MicrocontainerService registered");
+
+ // Register the DeployerService
+ Properties props = new Properties();
+ props.setProperty("provider", "microcontainer");
+ context.registerService(DeployerService.class.getName(), this, props);
+ log.debug("DeployerService registered");
+
+ // Register the MicrocontainerServiceMBean
+ registerMicrocontainerServiceMBean(mbeanServer);
+ log.debug("MicrocontainerServiceMBean registered");
+ }
+
+ void stop()
+ {
+ unregisterMicrocontainerServiceMBean(mbeanServer);
+ }
+
+ public void registerInitialContext()
+ {
+ try
+ {
+ InitialContext initialContext = new InitialContext();
+ context.registerService(InitialContext.class.getName(), initialContext, null);
+ }
+ catch (NamingException ex)
+ {
+ throw new IllegalStateException("Cannot register InitialContext", ex);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/branches/tdiesler/runtime/equinox/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/runtime/equinox/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/runtime/equinox/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -36,9 +36,15 @@
<entry><key>org.jboss.osgi.deferred.start</key><value>true</value></entry>
</map>
</property>
+ <property name="autoInstall">
+ <list elementClass="java.net.URL">
+ <value>${jboss.server.home.url}/deploy/osgi/org.osgi.compendium.jar</value>
+ </list>
+ </property>
<property name="autoStart">
<list elementClass="java.net.URL">
<value>${jboss.server.home.url}/deploy/osgi/org.apache.felix.log.jar</value>
+ <value>${jboss.server.home.url}/deploy/osgi/jboss-osgi-common.jar</value>
</list>
</property>
</bean>
@@ -57,30 +63,13 @@
********************************
-->
- <!-- Common Services -->
- <bean name="jboss.osgi:service=Common" class="org.jboss.osgi.jbossas.integration.CommonServicesBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!-- Microcontainer Service -->
- <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.jbossas.integration.MicrocontainerServiceBean">
+ <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.integration.jbossas.MicrocontainerServiceBean">
<property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
<property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
<property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
</bean>
- <!-- Naming Service -->
- <bean name="jboss.osgi:service=Naming" class="org.jboss.osgi.jbossas.integration.NamingServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- </bean>
-
- <!-- Management Service -->
- <bean name="jboss.osgi:service=Management" class="org.jboss.osgi.jbossas.integration.ManagementServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!--
********************************
* *
Modified: projects/jboss-osgi/branches/tdiesler/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/runtime/felix/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -66,9 +66,15 @@
<entry><key>org.jboss.osgi.husky.runtime.connector.port</key><value>5401</value></entry>
</map>
</property>
+ <property name="autoInstall">
+ <list elementClass="java.net.URL">
+ <value>${jboss.server.home.url}/deploy/osgi/org.osgi.compendium.jar</value>
+ </list>
+ </property>
<property name="autoStart">
<list elementClass="java.net.URL">
<value>${jboss.server.home.url}/deploy/osgi/org.apache.felix.log.jar</value>
+ <value>${jboss.server.home.url}/deploy/osgi/jboss-osgi-common.jar</value>
</list>
</property>
</bean>
@@ -87,30 +93,13 @@
********************************
-->
- <!-- Common Services -->
- <bean name="jboss.osgi:service=Common" class="org.jboss.osgi.jbossas.integration.CommonServicesBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!-- Microcontainer Service -->
- <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.jbossas.integration.MicrocontainerServiceBean">
+ <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.integration.jbossas.MicrocontainerServiceBean">
<property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
<property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
<property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
</bean>
- <!-- Naming Service -->
- <bean name="jboss.osgi:service=Naming" class="org.jboss.osgi.jbossas.integration.NamingServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- </bean>
-
- <!-- Management Service -->
- <bean name="jboss.osgi:service=Management" class="org.jboss.osgi.jbossas.integration.ManagementServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!--
********************************
* *
Modified: projects/jboss-osgi/branches/tdiesler/runtime/knopflerfish/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/branches/tdiesler/runtime/knopflerfish/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/runtime/knopflerfish/src/main/resources/osgi-deployers-jboss-beans.xml 2009-06-01 07:50:26 UTC (rev 89588)
@@ -61,9 +61,15 @@
<entry><key>org.jboss.osgi.deferred.start</key><value>true</value></entry>
</map>
</property>
+ <property name="autoInstall">
+ <list elementClass="java.net.URL">
+ <value>${jboss.server.home.url}/deploy/osgi/org.osgi.compendium.jar</value>
+ </list>
+ </property>
<property name="autoStart">
<list elementClass="java.net.URL">
<value>${jboss.server.home.url}/deploy/osgi/org.apache.felix.log.jar</value>
+ <value>${jboss.server.home.url}/deploy/osgi/jboss-osgi-common.jar</value>
</list>
</property>
</bean>
@@ -82,30 +88,13 @@
********************************
-->
- <!-- Common Services -->
- <bean name="jboss.osgi:service=Common" class="org.jboss.osgi.jbossas.integration.CommonServicesBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!-- Microcontainer Service -->
- <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.jbossas.integration.MicrocontainerServiceBean">
+ <bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.integration.jbossas.MicrocontainerServiceBean">
<property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
<property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
<property name="kernel"><inject bean="jboss.kernel:service=Kernel" /></property>
</bean>
- <!-- Naming Service -->
- <bean name="jboss.osgi:service=Naming" class="org.jboss.osgi.jbossas.integration.NamingServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- </bean>
-
- <!-- Management Service -->
- <bean name="jboss.osgi:service=Management" class="org.jboss.osgi.jbossas.integration.ManagementServiceBean">
- <property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="bundleContext"/></property>
- <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
- </bean>
-
<!--
********************************
* *
Deleted: projects/jboss-osgi/branches/tdiesler/spi/src/main/java/org/jboss/osgi/spi/service/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/branches/tdiesler/spi/src/main/java/org/jboss/osgi/spi/service/AbstractMicrocontainerService.java 2009-06-01 06:59:49 UTC (rev 89587)
+++ projects/jboss-osgi/branches/tdiesler/spi/src/main/java/org/jboss/osgi/spi/service/AbstractMicrocontainerService.java 2009-06-01 07:50:26 UTC (rev 89588)
@@ -1,261 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.service;
-
-//$Id$
-
-import static org.jboss.osgi.spi.service.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.management.StandardMBean;
-
-import org.jboss.dependency.plugins.AbstractController;
-import org.jboss.dependency.plugins.AbstractControllerContext;
-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.deployers.client.spi.Deployment;
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.BundleException;
-
-/**
- * An OSGi Service the gives access to the Kernel.
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Jan-2009
- */
-public abstract class AbstractMicrocontainerService implements DeployerService, MicrocontainerService
-{
- private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
- private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
-
- public abstract Kernel getKernel();
-
- public abstract void logDebug(String message);
-
- public abstract void logWarning(String message, Exception ex);
-
- public void logWarning(String message)
- {
- logWarning(message, null);
- }
-
- public List<String> getRegisteredBeans()
- {
- List<String> names = new ArrayList<String>();
-
- AbstractController controller = (AbstractController)getKernel().getController();
- for (ControllerContext ctx : controller.getAllContexts())
- {
- if (ctx instanceof KernelControllerContext || ctx instanceof PreInstalledControllerContext)
- names.add(ctx.getName().toString());
- }
-
- return names;
- }
-
- public Object getRegisteredBean(String beanName)
- {
- ControllerContext context = getKernel().getController().getInstalledContext(beanName);
- return context != null ? context.getTarget() : null;
- }
-
- public void deploy(URL url) throws BundleException
- {
- deployInternal(new URL[] { url });
- }
-
- public boolean undeploy(URL url) throws BundleException
- {
- String deploymentName = contextMap.remove(url);
- if (deploymentName == null)
- {
- logWarning("Package not deployed: " + url);
- return false;
- }
-
- try
- {
- MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- mainDeployer.removeDeployment(deploymentName);
- mainDeployer.process();
- return true;
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- logWarning("Cannot undeploy bundle", ex);
- return false;
- }
- }
-
- public void deploy(BundleInfo[] bundles) throws BundleException
- {
- URL[] urls = new URL[bundles.length];
- for (int i = 0; i < bundles.length; i++)
- urls[i] = bundles[i].getLocation();
-
- deployInternal(urls);
- }
-
- private void deployInternal(URL[] urls) throws BundleException
- {
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
- List<Deployment> deployments = new ArrayList<Deployment>();
- MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- for (URL location : urls)
- {
- VirtualFile file = VFS.createNewRoot(location);
- VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
- mainDeployer.addDeployment(deployment);
- deployments.add(deployment);
- contextMap.put(location, deployment.getName());
- }
-
- // Process the deployments
- mainDeployer.process();
-
- // Check for completeness
- Deployment[] depArr = deployments.toArray(new Deployment[deployments.size()]);
- mainDeployer.checkComplete(depArr);
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new BundleException("Cannot deploy bundles", ex);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
- }
-
- public void undeploy(BundleInfo[] bundles) throws BundleException
- {
- try
- {
- MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- for (BundleInfo bundle : bundles)
- {
- String deploymentName = contextMap.remove(bundle.getLocation());
- if (deploymentName != null)
- {
- mainDeployer.removeDeployment(deploymentName);
- }
- else
- {
- logWarning("Package not deployed: " + bundle.getLocation());
- }
- }
- mainDeployer.process();
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- logWarning("Cannot undeploy bundles", ex);
- }
- }
-
- protected void installBean(KernelController controller, String beanName, Object beanImpl)
- {
- try
- {
- ControllerContextActions actions = new AbstractControllerContextActions(new HashMap<ControllerState, ControllerContextAction>());
- controller.install(new PreInstalledControllerContext(beanName, actions, beanImpl));
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Throwable ex)
- {
- throw new IllegalStateException("Cannot register bean: " + beanName, ex);
- }
- }
-
- protected void registerMicrocontainerServiceMBean(MBeanServer mbeanServer)
- {
- try
- {
- logDebug("Register MicrocontainerServiceMBean");
- StandardMBean mbean = new StandardMBean((MicrocontainerServiceMBean)this, MicrocontainerServiceMBean.class);
- mbeanServer.registerMBean(mbean, MBEAN_MICROCONTAINER_SERVICE);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot register MicrocontainerServiceMBean", ex);
- }
- }
-
- protected void unregisterMicrocontainerServiceMBean(MBeanServer mbeanServer)
- {
- if (mbeanServer.isRegistered(MBEAN_MICROCONTAINER_SERVICE))
- {
- try
- {
- logDebug("Unregister MicrocontainerServiceMBean");
- mbeanServer.unregisterMBean(MBEAN_MICROCONTAINER_SERVICE);
- }
- catch (Exception ex)
- {
- logWarning("Cannot unregister MicrocontainerServiceMBean", ex);
- }
- }
- }
-
- static class PreInstalledControllerContext extends AbstractControllerContext
- {
- public PreInstalledControllerContext(Object name, ControllerContextActions actions, Object target)
- {
- super(name, actions, null, target);
- }
- }
-}
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list