[jboss-osgi-commits] JBoss-OSGI SVN: r92501 - in projects/jboss-osgi/projects: runtime/felix/trunk/src/main/java/org/jboss/osgi/felix and 1 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Tue Aug 18 04:51:46 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-18 04:51:46 -0400 (Tue, 18 Aug 2009)
New Revision: 92501
Added:
projects/jboss-osgi/projects/runtime/equinox/trunk/src/main/java/org/jboss/osgi/equinox/EquinoxIntegration.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/FrameworkIntegration.java
Modified:
projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java
Log:
Add EqunioxIntegration
Added: projects/jboss-osgi/projects/runtime/equinox/trunk/src/main/java/org/jboss/osgi/equinox/EquinoxIntegration.java
===================================================================
--- projects/jboss-osgi/projects/runtime/equinox/trunk/src/main/java/org/jboss/osgi/equinox/EquinoxIntegration.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/equinox/trunk/src/main/java/org/jboss/osgi/equinox/EquinoxIntegration.java 2009-08-18 08:51:46 UTC (rev 92501)
@@ -0,0 +1,51 @@
+/*
+ * 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.equinox;
+
+//$Id: FelixIntegration.java 91762 2009-07-29 12:14:37Z thomas.diesler at jboss.com $
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.framework.FrameworkIntegration;
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * Equinox specific OSGi Framework integration.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class EquinoxIntegration extends FrameworkIntegration
+{
+ // Provide logging
+ final Logger log = Logger.getLogger(EquinoxIntegration.class);
+
+ public void create()
+ {
+ String implVersion = getClass().getPackage().getImplementationVersion();
+ log.info("OSGi Integration Equinox - " + implVersion);
+
+ // Load the framework instance
+ FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+ framework = factory.newFramework(properties);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java 2009-08-18 08:51:31 UTC (rev 92500)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java 2009-08-18 08:51:46 UTC (rev 92501)
@@ -23,80 +23,23 @@
//$Id$
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.jboss.logging.Logger;
-import org.jboss.osgi.spi.FrameworkException;
-import org.jboss.osgi.spi.logging.ExportedPackageHelper;
+import org.jboss.osgi.spi.framework.FrameworkIntegration;
import org.jboss.osgi.spi.util.ServiceLoader;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
/**
- * An abstraction of an OSGi Framework
+ * Felix specific OSGi Framework integration.
*
* @author thomas.diesler at jboss.com
* @since 23-Jan-2009
*/
-public class FelixIntegration
+public class FelixIntegration extends FrameworkIntegration
{
// Provide logging
final Logger log = Logger.getLogger(FelixIntegration.class);
-
- private Map<String, Object> properties = new HashMap<String, Object>();
- private List<URL> autoInstall = new ArrayList<URL>();
- private List<URL> autoStart = new ArrayList<URL>();
-
- private Framework framework;
-
- public Map<String, Object> getProperties()
- {
- return properties;
- }
-
- public void setProperties(Map<String, Object> props)
- {
- this.properties = props;
- }
-
- public List<URL> getAutoInstall()
- {
- return autoInstall;
- }
-
- public void setAutoInstall(List<URL> autoInstall)
- {
- this.autoInstall = autoInstall;
- }
-
- public List<URL> getAutoStart()
- {
- return autoStart;
- }
-
- public void setAutoStart(List<URL> autoStart)
- {
- this.autoStart = autoStart;
- }
-
- public Bundle getBundle()
- {
- assertFrameworkStart();
- return framework;
- }
-
- public BundleContext getBundleContext()
- {
- return getBundle().getBundleContext();
- }
-
+
public void create()
{
String implVersion = getClass().getPackage().getImplementationVersion();
@@ -114,76 +57,6 @@
framework = factory.newFramework(properties);
}
- public void start()
- {
- // Create the Felix instance
- assertFrameworkCreate();
-
- // Start the System Bundle
- try
- {
- framework.start();
- }
- catch (BundleException ex)
- {
- throw new FrameworkException("Cannot start system bundle", ex);
- }
-
- // Get system bundle context
- BundleContext context = framework.getBundleContext();
- if (context == null)
- throw new FrameworkException("Cannot obtain system context");
-
- // Log the the framework packages
- ExportedPackageHelper packageHelper = new ExportedPackageHelper(context);
- packageHelper.logExportedPackages(getBundle());
-
- Map<URL, Bundle> autoBundles = new HashMap<URL, Bundle>();
-
- // Add the autoStart bundles to autoInstall
- for (URL bundleURL : autoStart)
- {
- autoInstall.add(bundleURL);
- }
-
- // Install autoInstall bundles
- for (URL bundleURL : autoInstall)
- {
- try
- {
- Bundle bundle = context.installBundle(bundleURL.toString());
- long bundleId = bundle.getBundleId();
- log.info("Installed bundle [" + bundleId + "]: " + bundle.getSymbolicName());
- autoBundles.put(bundleURL, bundle);
- }
- catch (BundleException ex)
- {
- stop();
- throw new IllegalStateException("Cannot install bundle: " + bundleURL, ex);
- }
- }
-
- // Start autoStart bundles
- for (URL bundleURL : autoStart)
- {
- try
- {
- Bundle bundle = autoBundles.get(bundleURL);
- if (bundle != null)
- {
- bundle.start();
- packageHelper.logExportedPackages(bundle);
- log.info("Started bundle: " + bundle.getSymbolicName());
- }
- }
- catch (BundleException ex)
- {
- stop();
- throw new IllegalStateException("Cannot start bundle: " + bundleURL, ex);
- }
- }
- }
-
public void stop()
{
if (framework != null)
@@ -237,17 +110,4 @@
thread.interrupt();
}
}
-
- private void assertFrameworkCreate()
- {
- if (framework == null)
- create();
- }
-
- private void assertFrameworkStart()
- {
- assertFrameworkCreate();
- if ((framework.getState() & Bundle.ACTIVE) == 0)
- start();
- }
}
\ No newline at end of file
Copied: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/FrameworkIntegration.java (from rev 92485, projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java)
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/FrameworkIntegration.java (rev 0)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/FrameworkIntegration.java 2009-08-18 08:51:46 UTC (rev 92501)
@@ -0,0 +1,211 @@
+/*
+ * 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.framework;
+
+//$Id$
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.FrameworkException;
+import org.jboss.osgi.spi.logging.ExportedPackageHelper;
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * An abstraction of an OSGi Framework
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class FrameworkIntegration
+{
+ // Provide logging
+ final Logger log = Logger.getLogger(FrameworkIntegration.class);
+
+ protected Map<String, Object> properties = new HashMap<String, Object>();
+ protected List<URL> autoInstall = new ArrayList<URL>();
+ protected List<URL> autoStart = new ArrayList<URL>();
+
+ protected Framework framework;
+
+ public Map<String, Object> getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> props)
+ {
+ this.properties = props;
+ }
+
+ public List<URL> getAutoInstall()
+ {
+ return autoInstall;
+ }
+
+ public void setAutoInstall(List<URL> autoInstall)
+ {
+ this.autoInstall = autoInstall;
+ }
+
+ public List<URL> getAutoStart()
+ {
+ return autoStart;
+ }
+
+ public void setAutoStart(List<URL> autoStart)
+ {
+ this.autoStart = autoStart;
+ }
+
+ public Bundle getBundle()
+ {
+ assertFrameworkStart();
+ return framework;
+ }
+
+ public BundleContext getBundleContext()
+ {
+ return getBundle().getBundleContext();
+ }
+
+ public void create()
+ {
+ // Load the framework instance
+ FrameworkFactory factory = ServiceLoader.loadService(FrameworkFactory.class);
+ framework = factory.newFramework(properties);
+ }
+
+ public void start()
+ {
+ // Create the Framework instance
+ assertFrameworkCreate();
+
+ // Start the System Bundle
+ try
+ {
+ framework.start();
+ }
+ catch (BundleException ex)
+ {
+ throw new FrameworkException("Cannot start system bundle", ex);
+ }
+
+ // Get system bundle context
+ BundleContext context = framework.getBundleContext();
+ if (context == null)
+ throw new FrameworkException("Cannot obtain system context");
+
+ // Log the the framework packages
+ ExportedPackageHelper packageHelper = new ExportedPackageHelper(context);
+ packageHelper.logExportedPackages(getBundle());
+
+ Map<URL, Bundle> autoBundles = new HashMap<URL, Bundle>();
+
+ // Add the autoStart bundles to autoInstall
+ for (URL bundleURL : autoStart)
+ {
+ autoInstall.add(bundleURL);
+ }
+
+ // Install autoInstall bundles
+ for (URL bundleURL : autoInstall)
+ {
+ try
+ {
+ Bundle bundle = context.installBundle(bundleURL.toString());
+ long bundleId = bundle.getBundleId();
+ log.info("Installed bundle [" + bundleId + "]: " + bundle.getSymbolicName());
+ autoBundles.put(bundleURL, bundle);
+ }
+ catch (BundleException ex)
+ {
+ stop();
+ throw new IllegalStateException("Cannot install bundle: " + bundleURL, ex);
+ }
+ }
+
+ // Start autoStart bundles
+ for (URL bundleURL : autoStart)
+ {
+ try
+ {
+ Bundle bundle = autoBundles.get(bundleURL);
+ if (bundle != null)
+ {
+ bundle.start();
+ packageHelper.logExportedPackages(bundle);
+ log.info("Started bundle: " + bundle.getSymbolicName());
+ }
+ }
+ catch (BundleException ex)
+ {
+ stop();
+ throw new IllegalStateException("Cannot start bundle: " + bundleURL, ex);
+ }
+ }
+ }
+
+ public void stop()
+ {
+ if (framework != null)
+ {
+ try
+ {
+ framework.stop();
+ framework.waitForStop(5000);
+ framework = null;
+ log.debug("SystemBundle STOPPED");
+ }
+ catch (BundleException ex)
+ {
+ log.error("Cannot stop Framework", ex);
+ }
+ catch (InterruptedException ex)
+ {
+ log.error("Cannot stop Framework", ex);
+ }
+ }
+ }
+
+ private void assertFrameworkCreate()
+ {
+ if (framework == null)
+ create();
+ }
+
+ private void assertFrameworkStart()
+ {
+ assertFrameworkCreate();
+ if ((framework.getState() & Bundle.ACTIVE) == 0)
+ start();
+ }
+}
\ No newline at end of file
More information about the jboss-osgi-commits
mailing list