[jboss-osgi-commits] JBoss-OSGI SVN: r89534 - in projects/jboss-osgi/trunk: bundles/common/src/main/java/org/jboss/osgi/common/internal and 6 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Fri May 29 12:40:24 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-05-29 12:40:23 -0400 (Fri, 29 May 2009)
New Revision: 89534
Added:
projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java
projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/SimpleDeployerService.java
projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerServiceTracker.java
Removed:
projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java
Modified:
projects/jboss-osgi/trunk/bundles/common/pom.xml
projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/CommonServicesActivator.java
projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java
projects/jboss-osgi/trunk/bundles/hotdeploy/pom.xml
projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
projects/jboss-osgi/trunk/husky/testsuite/src/test/resources/jboss-osgi-felix.properties
projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java
Log:
Register DeployerService as part of common services
Modified: projects/jboss-osgi/trunk/bundles/common/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/pom.xml 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/common/pom.xml 2009-05-29 16:40:23 UTC (rev 89534)
@@ -18,6 +18,11 @@
<!-- Dependencies -->
<dependencies>
<dependency>
+ <groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-spi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-spi</artifactId>
<scope>provided</scope>
@@ -54,7 +59,9 @@
org.jboss.osgi.common.internal
</Private-Package>
<Import-Package>
+ javax.management,
org.jboss.logging,
+ org.jboss.osgi.spi.management;version="1.0",
org.osgi.framework;version=1.4,
org.osgi.service.log;version=1.3,
org.osgi.util.tracker
Modified: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/CommonServicesActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/CommonServicesActivator.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/CommonServicesActivator.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -23,10 +23,18 @@
//$Id$
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.StandardMBean;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.DeployerServiceTracker;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
/**
@@ -37,8 +45,12 @@
*/
public class CommonServicesActivator implements BundleActivator
{
+ private LogService log;
+
public void start(BundleContext context)
{
+ log = new LogServiceTracker(context);
+
// Track LogReaderService and add/remove LogListener
ServiceTracker logTracker = new ServiceTracker(context, LogReaderService.class.getName(), null)
{
@@ -51,6 +63,49 @@
}
};
logTracker.open();
+
+ // Track the DeployerService
+ final DeployerServiceTracker serviceTracker = new DeployerServiceTracker(context);
+ serviceTracker.open();
+
+ // Track the MBeanServer and register the DeployerServiceTracker
+ ServiceTracker jmxTracker = new ServiceTracker(context, MBeanServer.class.getName(), null)
+ {
+ @Override
+ public Object addingService(ServiceReference reference)
+ {
+ MBeanServer mbeanServer = (MBeanServer)super.addingService(reference);
+ try
+ {
+ DeployerServiceDelegate delegate = new DeployerServiceDelegate(serviceTracker);
+ StandardMBean mbean = new StandardMBean(delegate, DeployerService.class);
+ mbeanServer.registerMBean(mbean, DeployerService.MBEAN_DEPLOYER_SERVICE);
+ }
+ catch (JMException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot register DeployerService MBean", ex);
+ }
+ return mbeanServer;
+ }
+
+ @Override
+ public void removedService(ServiceReference reference, Object service)
+ {
+ MBeanServer mbeanServer = (MBeanServer)service;
+ try
+ {
+ if (mbeanServer.isRegistered(DeployerService.MBEAN_DEPLOYER_SERVICE))
+ mbeanServer.unregisterMBean(DeployerService.MBEAN_DEPLOYER_SERVICE);
+ }
+ catch (JMException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot unregister DeployerService MBean", ex);
+ }
+
+ super.removedService(reference, service);
+ }
+ };
+ jmxTracker.open();
}
public void stop(BundleContext context)
Added: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.common.internal;
+
+//$Id$
+
+import java.net.URL;
+
+import org.jboss.osgi.common.service.BundleInfo;
+import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.DeployerServiceTracker;
+
+/**
+ * A {@link DeployerService} that delegates to the service that is tracked
+ * by the given {@link DeployerServiceTracker}
+ *
+ * This delegate is registered as an MBean
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeployerServiceDelegate implements DeployerService
+{
+ private DeployerServiceTracker tracker;
+
+ public DeployerServiceDelegate(DeployerServiceTracker tracker)
+ {
+ this.tracker = tracker;
+ }
+
+ public void deploy(BundleInfo[] bundles) throws Exception
+ {
+ tracker.getService().deploy(bundles);
+ }
+
+ public void deploy(URL url) throws Exception
+ {
+ tracker.getService().deploy(url);
+ }
+
+ public void undeploy(BundleInfo[] bundles) throws Exception
+ {
+ tracker.getService().undeploy(bundles);
+ }
+
+ public void undeploy(URL url) throws Exception
+ {
+ tracker.getService().undeploy(url);
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/SimpleDeployerService.java (from rev 89533, projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java)
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/SimpleDeployerService.java (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/internal/SimpleDeployerService.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -0,0 +1,131 @@
+/*
+ * 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.common.internal;
+
+//$Id$
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.jboss.osgi.common.service.BundleInfo;
+import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.DeployerServiceTracker;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.service.log.LogService;
+
+/**
+ * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class SimpleDeployerService implements DeployerService
+{
+ private LogServiceTracker log;
+ private BundleContext context;
+
+ private Map<URI, Bundle> urlDeployments = new HashMap<URI, Bundle>();
+
+ public SimpleDeployerService(BundleContext context)
+ {
+ this.log = new LogServiceTracker(context);
+ this.context = context;
+ }
+
+ public void deploy(BundleInfo[] bundleInfos) throws BundleException
+ {
+ // Install the NEW bundles
+ List<Bundle> bundles = new ArrayList<Bundle>();
+ for (BundleInfo info : bundleInfos)
+ {
+ try
+ {
+ log.log(LogService.LOG_DEBUG, "Install: " + info.getSymbolicName());
+ Bundle bundle = context.installBundle(info.getLocation().toExternalForm());
+ bundles.add(bundle);
+ }
+ catch (BundleException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot install bundle: " + info.getSymbolicName(), ex);
+ }
+ }
+
+ // Start the installed bundles
+ for (Bundle bundle : bundles)
+ {
+ try
+ {
+ log.log(LogService.LOG_DEBUG, "Start: " + bundle.getSymbolicName());
+ bundle.start();
+ }
+ catch (BundleException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle.getSymbolicName(), ex);
+ }
+ }
+ }
+
+ public void undeploy(BundleInfo[] bundleInfos) throws BundleException
+ {
+ for (BundleInfo info : bundleInfos)
+ {
+ Bundle bundle = DeployerServiceTracker.getInstalledBundle(context, info);
+ if (bundle != null)
+ {
+ try
+ {
+ log.log(LogService.LOG_DEBUG, "Uninstall: " + info.getSymbolicName());
+ bundle.uninstall();
+ }
+ catch (BundleException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot uninstall bundle", ex);
+ }
+ }
+ }
+ }
+
+ public void deploy(URL url) throws Exception
+ {
+ log.log(LogService.LOG_DEBUG, "Install: " + url);
+ Bundle bundle = context.installBundle(url.toExternalForm());
+ urlDeployments.put(url.toURI(), bundle);
+ bundle.start();
+ }
+
+ public void undeploy(URL url) throws Exception
+ {
+ Bundle bundle = urlDeployments.remove(url.toURI());
+ if (bundle != null)
+ {
+ log.log(LogService.LOG_DEBUG, "Uninstall: " + bundle.getSymbolicName());
+ bundle.uninstall();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerService.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -23,18 +23,27 @@
import java.net.URL;
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
//$Id$
/**
- * A Service that deploys bundles through the deployers that
- * are registered with the {@link MicrocontainerService}
+ * A Service that can be used to deploy bundles or archives
+ * to the runtime.
*
* @author thomas.diesler at jboss.com
* @since 23-Jan-2009
*/
public interface DeployerService
{
+ /**
+ * The object name under which this is registered: 'jboss.osgi:service=DeployerService'
+ */
+ ObjectName MBEAN_DEPLOYER_SERVICE = ObjectNameFactory.create("jboss.osgi:service=DeployerService");
+
/**
* Deploy an array of bundles
*/
Added: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerServiceTracker.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerServiceTracker.java (rev 0)
+++ projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerServiceTracker.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -0,0 +1,95 @@
+/*
+ * 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.common.service;
+
+//$Id$
+
+import org.jboss.osgi.common.internal.SimpleDeployerService;
+import org.jboss.osgi.common.log.LogServiceTracker;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * A {@link ServiceTracker} that tracks the {@link DeployerService}.
+ * In case there is not such service registered, it returns an instance
+ * of {@link SimpleDeployerService}
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeployerServiceTracker extends ServiceTracker
+{
+ private LogServiceTracker log;
+ private BundleContext context;
+
+ public DeployerServiceTracker(BundleContext context)
+ {
+ super(context, DeployerService.class.getName(), null);
+ this.log = new LogServiceTracker(context);
+ this.context = context;
+ }
+
+ @Override
+ public Object addingService(ServiceReference reference)
+ {
+ DeployerService service = (DeployerService)super.addingService(reference);
+ log.log(LogService.LOG_INFO, "Adding DeployerService: " + service.getClass().getName());
+ return service;
+ }
+
+ @Override
+ public void removedService(ServiceReference reference, Object service)
+ {
+ log.log(LogService.LOG_INFO, "Removing DeployerService: " + service.getClass().getName());
+ super.removedService(reference, service);
+ }
+
+ @Override
+ public DeployerService getService()
+ {
+ DeployerService service = (DeployerService)super.getService();
+ if (service == null)
+ service = new SimpleDeployerService(context);
+
+ return service;
+ }
+
+ public static Bundle getInstalledBundle(BundleContext context, BundleInfo bundleInfo)
+ {
+ Bundle bundle = null;
+
+ for (Bundle aux : context.getBundles())
+ {
+ String symbolicName = aux.getSymbolicName();
+ if (symbolicName.equals(bundleInfo.getSymbolicName()))
+ {
+ bundle = aux;
+ break;
+ }
+ }
+
+ return bundle;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/bundles/common/src/main/java/org/jboss/osgi/common/service/DeployerServiceTracker.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/pom.xml 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/pom.xml 2009-05-29 16:40:23 UTC (rev 89534)
@@ -52,6 +52,7 @@
<Bundle-Activator>org.jboss.osgi.service.hotdeploy.internal.DeploymentScannerActivator</Bundle-Activator>
<Private-Package>org.jboss.osgi.service.hotdeploy.internal</Private-Package>
<Import-Package>
+ javax.management,
org.jboss.osgi.common.log;version="1.0",
org.jboss.osgi.common.service;version="1.0",
org.osgi.framework,
Modified: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -38,15 +38,13 @@
import org.jboss.osgi.common.log.LogServiceTracker;
import org.jboss.osgi.common.service.BundleInfo;
-import org.jboss.osgi.common.service.DeployerService;
+import org.jboss.osgi.common.service.DeployerServiceTracker;
import org.jboss.osgi.common.service.DeploymentScannerService;
import org.jboss.osgi.common.service.BundleInfo.State;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
/**
* The DeploymentScanner service
@@ -63,8 +61,8 @@
private File scanLocation;
private long scanCount;
+ private DeployerServiceTracker serviceTracker;
private ScannerThread scannerThread;
- private DeployerService deployerService;
private List<BundleInfo> lastScan = new ArrayList<BundleInfo>();
private boolean traceBundles = false;
@@ -73,25 +71,9 @@
this.log = new LogServiceTracker(context);
this.context = context;
- // Init and track the DeployerService
- deployerService = new SimpleDeployerService(context);
- ServiceTracker tracker = new ServiceTracker(context, DeployerService.class.getName(), null)
- {
- @Override
- public Object addingService(ServiceReference reference)
- {
- deployerService = (DeployerService)super.addingService(reference);
- return deployerService;
- }
+ serviceTracker = new DeployerServiceTracker(context);
+ serviceTracker.open();
- @Override
- public void removedService(ServiceReference reference, Object service)
- {
- deployerService = new SimpleDeployerService(context);
- }
- };
- tracker.open();
-
initScanner(context);
}
@@ -154,7 +136,7 @@
try
{
BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]);
- deployerService.undeploy(infoArr);
+ serviceTracker.getService().undeploy(infoArr);
}
catch (Exception ex)
{
@@ -180,7 +162,7 @@
try
{
BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]);
- deployerService.deploy(infoArr);
+ serviceTracker.getService().deploy(infoArr);
}
catch (Exception ex)
{
@@ -194,7 +176,7 @@
for (File file : scanLocation.listFiles())
{
BundleInfo info = getBundleInfo(file);
- Bundle bundle = SimpleDeployerService.getInstalledBundle(context, info);
+ Bundle bundle = DeployerServiceTracker.getInstalledBundle(context, info);
bundles.add(new BundleInfoImpl(toURL(file), info.getSymbolicName(), bundle));
}
BundleInfo[] arr = new BundleInfoImpl[bundles.size()];
Deleted: projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java
===================================================================
--- projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/bundles/hotdeploy/src/main/java/org/jboss/osgi/service/hotdeploy/internal/SimpleDeployerService.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -1,147 +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.service.hotdeploy.internal;
-
-//$Id$
-
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.osgi.common.log.LogServiceTracker;
-import org.jboss.osgi.common.service.BundleInfo;
-import org.jboss.osgi.common.service.DeployerService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.service.log.LogService;
-
-/**
- * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
- *
- * @author thomas.diesler at jboss.com
- * @since 27-May-2009
- */
-public class SimpleDeployerService implements DeployerService
-{
- private LogServiceTracker log;
- private BundleContext context;
-
- private Map<URI, Bundle> urlDeployments = new HashMap<URI, Bundle>();
-
- public SimpleDeployerService(BundleContext context)
- {
- this.log = new LogServiceTracker(context);
- this.context = context;
- }
-
- public void deploy(BundleInfo[] bundleInfos) throws BundleException
- {
- // Install the NEW bundles
- List<Bundle> bundles = new ArrayList<Bundle>();
- for (BundleInfo info : bundleInfos)
- {
- try
- {
- log.log(LogService.LOG_DEBUG, "Install: " + info.getSymbolicName());
- Bundle bundle = context.installBundle(info.getLocation().toExternalForm());
- bundles.add(bundle);
- }
- catch (BundleException ex)
- {
- log.log(LogService.LOG_ERROR, "Cannot install bundle: " + info.getSymbolicName(), ex);
- }
- }
-
- // Start the installed bundles
- for (Bundle bundle : bundles)
- {
- try
- {
- log.log(LogService.LOG_DEBUG, "Start: " + bundle.getSymbolicName());
- bundle.start();
- }
- catch (BundleException ex)
- {
- log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle.getSymbolicName(), ex);
- }
- }
- }
-
- public void undeploy(BundleInfo[] bundleInfos) throws BundleException
- {
- for (BundleInfo info : bundleInfos)
- {
- Bundle bundle = getInstalledBundle(context, info);
- if (bundle != null)
- {
- try
- {
- log.log(LogService.LOG_DEBUG, "Uninstall: " + info.getSymbolicName());
- bundle.uninstall();
- }
- catch (BundleException ex)
- {
- log.log(LogService.LOG_ERROR, "Cannot uninstall bundle", ex);
- }
- }
- }
- }
-
- public void deploy(URL url) throws Exception
- {
- log.log(LogService.LOG_DEBUG, "Install: " + url);
- Bundle bundle = context.installBundle(url.toExternalForm());
- urlDeployments.put(url.toURI(), bundle);
- bundle.start();
- }
-
- public void undeploy(URL url) throws Exception
- {
- Bundle bundle = urlDeployments.remove(url.toURI());
- if (bundle != null)
- {
- log.log(LogService.LOG_DEBUG, "Uninstall: " + bundle.getSymbolicName());
- bundle.uninstall();
- }
- }
-
- public static Bundle getInstalledBundle(BundleContext context, BundleInfo bundleInfo)
- {
- Bundle bundle = null;
-
- for (Bundle aux : context.getBundles())
- {
- String symbolicName = aux.getSymbolicName();
- if (symbolicName.equals(bundleInfo.getSymbolicName()))
- {
- bundle = aux;
- break;
- }
- }
-
- return bundle;
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/husky/testsuite/src/test/resources/jboss-osgi-felix.properties
===================================================================
--- projects/jboss-osgi/trunk/husky/testsuite/src/test/resources/jboss-osgi-felix.properties 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/husky/testsuite/src/test/resources/jboss-osgi-felix.properties 2009-05-29 16:40:23 UTC (rev 89534)
@@ -22,6 +22,7 @@
org.osgi.framework.system.packages.extra=\
org.jboss.logging, \
org.jboss.osgi.spi;version=1.0, \
+ org.jboss.osgi.spi.management;version=1.0, \
org.jboss.osgi.spi.testing;version=1.0, \
org.jboss.osgi.spi.testing.capability;version=1.0, \
org.osgi.framework;version=1.4
Modified: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/testing/internal/OSGiRuntimeImpl.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -161,18 +161,18 @@
public void deploy(String location) throws Exception
{
URL archiveURL = getTestHelper().getTestArchiveURL(location);
- invokeMainDeployer("deploy", archiveURL);
+ invokeDeployerService("deploy", archiveURL);
}
public void undeploy(String location) throws Exception
{
URL archiveURL = getTestHelper().getTestArchiveURL(location);
- invokeMainDeployer("undeploy", archiveURL);
+ invokeDeployerService("undeploy", archiveURL);
}
- private void invokeMainDeployer(String method, URL archiveURL) throws Exception
+ private void invokeDeployerService(String method, URL archiveURL) throws Exception
{
- ObjectName oname = new ObjectName("jboss.osgi:service=MicrocontainerService");
+ ObjectName oname = new ObjectName("jboss.osgi:service=DeployerService");
getMBeanServer().invoke(oname, method, new Object[] { archiveURL }, new String[] { "java.net.URL" });
}
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java 2009-05-29 14:50:22 UTC (rev 89533)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java 2009-05-29 16:40:23 UTC (rev 89534)
@@ -23,6 +23,7 @@
//$Id$
+import static org.jboss.osgi.common.service.DeployerService.MBEAN_DEPLOYER_SERVICE;
import static org.jboss.osgi.common.service.MicrocontainerService.BEAN_KERNEL;
import static org.jboss.osgi.common.service.MicrocontainerService.BEAN_MBEAN_SERVER;
import static org.jboss.osgi.common.service.MicrocontainerService.BEAN_SYSTEM_BUNDLE_CONTEXT;
@@ -36,6 +37,7 @@
import javax.management.ObjectName;
+import org.jboss.osgi.common.service.DeployerService;
import org.jboss.osgi.microcontainer.MicrocontainerServiceMBean;
import org.jboss.osgi.spi.management.MBeanProxy;
import org.jboss.osgi.spi.management.ManagedFrameworkMBean;
@@ -64,7 +66,6 @@
{
runtime = new OSGiTestHelper().getDefaultRuntime();
runtime.addCapability(new JNDICapability());
- runtime.addCapability(new JMXCapability());
runtime.addCapability(new MicrocontainerCapability());
}
@@ -90,21 +91,23 @@
@Test
public void testBundleDeployment() throws Exception
{
- MicrocontainerServiceMBean mcService = MBeanProxy.get(MicrocontainerServiceMBean.class, MBEAN_MICROCONTAINER_SERVICE, runtime.getMBeanServer());
- mcService.deploy(getTestArchiveURL("example-mcservice-bundleA.jar"));
+ DeployerService deployer = MBeanProxy.get(DeployerService.class, MBEAN_DEPLOYER_SERVICE, runtime.getMBeanServer());
+ deployer.deploy(getTestArchiveURL("example-mcservice-bundleA.jar"));
ManagedFrameworkMBean frameworkMBean = MBeanProxy.get(ManagedFrameworkMBean.class, MBEAN_MANAGED_FRAMEWORK, runtime.getMBeanServer());
Set<ObjectName> bundles = frameworkMBean.getBundles();
assertTrue("Managed bundle registered", bundles.toString().indexOf("jboss.osgi:bundle=example-mcservice-bundleA") > 0);
- mcService.undeploy(getTestArchiveURL("example-mcservice-bundleA.jar"));
+ deployer.undeploy(getTestArchiveURL("example-mcservice-bundleA.jar"));
}
@Test
public void testBeansDeployment() throws Exception
{
MicrocontainerServiceMBean mcService = MBeanProxy.get(MicrocontainerServiceMBean.class, MBEAN_MICROCONTAINER_SERVICE, runtime.getMBeanServer());
- mcService.deploy(getTestArchiveURL("example-mcservice-bundleB.jar"));
+ DeployerService deployer = MBeanProxy.get(DeployerService.class, MBEAN_DEPLOYER_SERVICE, runtime.getMBeanServer());
+
+ deployer.deploy(getTestArchiveURL("example-mcservice-bundleB.jar"));
ManagedFrameworkMBean frameworkMBean = MBeanProxy.get(ManagedFrameworkMBean.class, MBEAN_MANAGED_FRAMEWORK, runtime.getMBeanServer());
Set<ObjectName> bundles = frameworkMBean.getBundles();
@@ -114,7 +117,7 @@
List<String> registeredBeans = mcService.getRegisteredBeans();
assertTrue("SomeBean registered", registeredBeans.contains("SomeBean"));
- mcService.undeploy(getTestArchiveURL("example-mcservice-bundleB.jar"));
+ deployer.undeploy(getTestArchiveURL("example-mcservice-bundleB.jar"));
// Check whether the bean is unregistered
registeredBeans = mcService.getRegisteredBeans();
More information about the jboss-osgi-commits
mailing list