[jboss-cvs] JBossAS SVN: r92876 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk: src/main/java/org/jboss/osgi/plugins/facade/api and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 27 11:53:11 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-27 11:53:11 -0400 (Thu, 27 Aug 2009)
New Revision: 92876
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
[JBOSGI-140] Invalid delivery of framework events
All event handling is delegated to the FrameworkEventsPlugin.
More work to be done.
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk
___________________________________________________________________
Name: svn:mergeinfo
-
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java (from rev 92874, projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -0,0 +1,84 @@
+/*
+ * 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.plugins.facade.api;
+
+//$Id: SystemPackagesPlugin.java 92761 2009-08-24 22:10:03Z thomas.diesler at jboss.com $
+
+import java.security.AccessControlContext;
+import java.security.AccessController;
+
+import org.jboss.osgi.plugins.facade.bundle.OSGiServiceState;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceListener;
+
+/**
+ * A plugin that handles the various OSGi event types.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-Aug-2009
+ */
+public interface FrameworkEventsPlugin extends AbstractPlugin
+{
+ void addBundleListener(BundleListener listener);
+
+ void removeBundleListener(BundleListener listener);
+
+ void fireBundleEvent(Bundle bundle, int type);
+
+ void fireFrameworkEvent(Bundle bundle, int type, Throwable throwable);
+
+ void addFrameworkListener(FrameworkListener listener);
+
+ void removeFrameworkListener(FrameworkListener listener);
+
+ // [TODO] remove dependecy on propriatary API
+ void fireServiceEvent(Bundle bundle, int type, OSGiServiceState service);
+
+ void addServiceListener(ServiceListener listener, Filter filter);
+
+ void removeServiceListener(ServiceListener listener);
+
+ static class ServiceListenerRegistration
+ {
+ // Any filter
+ public Filter filter;
+
+ // Any access control context
+ public AccessControlContext accessControlContext;
+
+ /**
+ * Create a new ServiceListenerRegistration.
+ *
+ * @param filter the filter
+ */
+ public ServiceListenerRegistration(Filter filter)
+ {
+ this.filter = filter;
+
+ if (System.getSecurityManager() != null)
+ accessControlContext = AccessController.getContext();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -25,8 +25,6 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
import java.security.Permission;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@@ -42,6 +40,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
+import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
import org.jboss.osgi.plugins.filter.NoFilter;
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -55,11 +54,9 @@
import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -109,7 +106,7 @@
private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
/** The service listeners */
- private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
+ private Map<ServiceListener, FrameworkEventsPlugin.ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, FrameworkEventsPlugin.ServiceListenerRegistration>();
/**
* Create a new BundleState for the system bundle.
@@ -304,7 +301,9 @@
filter = NoFilter.INSTANCE;
checkValidBundleContext();
- serviceListeners.put(listener, new ServiceListenerRegistration(filter));
+ serviceListeners.put(listener, new FrameworkEventsPlugin.ServiceListenerRegistration(filter));
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.addServiceListener(listener, filter);
}
public void removeServiceListener(ServiceListener listener)
@@ -315,6 +314,8 @@
checkValidBundleContext();
serviceListeners.remove(listener);
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.removeServiceListener(listener);
}
/**
@@ -507,6 +508,9 @@
return;
bundleListeners.add(listener);
+
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.addBundleListener(listener);
}
public void removeBundleListener(BundleListener listener)
@@ -520,6 +524,9 @@
checkAdminPermission(AdminPermission.LISTENER);
bundleListeners.remove(listener);
+
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.removeBundleListener(listener);
}
public void start() throws BundleException
@@ -577,6 +584,9 @@
return;
frameworkListeners.add(listener);
+
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.addFrameworkListener(listener);
}
public void removeFrameworkListener(FrameworkListener listener)
@@ -587,6 +597,9 @@
checkValidBundleContext();
frameworkListeners.remove(listener);
+
+ FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.removeFrameworkListener(listener);
}
public Bundle installBundle(String location, InputStream input) throws BundleException
@@ -670,9 +683,8 @@
{
if (bundleManager != null && this.bundleManager != null)
throw new IllegalStateException("Bundle " + this + " is already installed");
+
this.bundleManager = bundleManager;
- if (bundleManager == null)
- changeState(Bundle.UNINSTALLED);
}
/**
@@ -738,131 +750,15 @@
}
this.state.set(state);
log.debug(this + " change state=" + ConstantsHelper.bundleState(state));
- BundleEvent event = new BundleEvent(type, getBundleInternal());
- fireBundleEvent(event);
- }
-
- /**
- * Fire a bundle event
- *
- * @param event the event
- */
- void fireBundleEvent(BundleEvent event)
- {
- // Nobody is interested
- if (bundleListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Synchronous listeners first
- for (BundleListener listener : bundleListeners)
+
+ if (bundleManager.isActive())
{
- try
- {
- if (listener instanceof SynchronousBundleListener)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
+ FrameworkEventsPlugin plugin = bundleManager.getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireBundleEvent(this, type);
}
- // Normal listeners after, if required
- int type = event.getType();
- if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
- {
- for (BundleListener listener : bundleListeners)
- {
- try
- {
- if (listener instanceof SynchronousBundleListener == false)
- listener.bundleChanged(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
- }
- }
- }
}
/**
- * Fire a framework event
- *
- * @param type the type of event
- * @param throwable any throwable
- */
- void fireFrameworkEvent(int type, Throwable throwable)
- {
- // Nobody is interested
- if (frameworkListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- // Call the listeners
- FrameworkEvent event = new FrameworkEvent(type, getBundleInternal(), throwable);
- for (FrameworkListener listener : frameworkListeners)
- {
- try
- {
- listener.frameworkEvent(event);
- }
- catch (Throwable t)
- {
- log.warn("Error while firing framework event: " + event.getType() + " for bundle " + getCanonicalName(), t);
- }
- }
- }
-
- /**
- * Fire a service event
- *
- * @param type the type
- * @param service the service
- */
- void fireServiceEvent(int type, OSGiServiceState service)
- {
- if (service == null)
- throw new IllegalArgumentException("No serviceReference");
-
- // Nobody is interested
- if (serviceListeners.isEmpty())
- return;
-
- // Are we active?
- if (getBundleManager().isActive() == false)
- return;
-
- ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
-
- // Call the listeners
- for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
- {
- ServiceListener listener = entry.getKey();
- ServiceListenerRegistration registration = entry.getValue();
- try
- {
- if (registration.filter.match(service))
- {
- AccessControlContext accessControlContext = registration.accessControlContext;
- if (accessControlContext == null || service.hasPermission(accessControlContext))
- listener.serviceChanged(event);
- }
- }
- catch (Throwable t)
- {
- log.warn("Error while firing service event: " + type + " for service " + service, t);
- }
- }
- }
-
- /**
* Check the bundle is installed
*
* @throws IllegalStateException when the bundle is not installed
@@ -918,29 +814,4 @@
return true;
}
}
-
- /**
- * ServiceListenerRegistration.
- */
- private static class ServiceListenerRegistration
- {
- // Any filter
- Filter filter;
-
- // Any access control context
- AccessControlContext accessControlContext;
-
- /**
- * Create a new ServiceListenerRegistration.
- *
- * @param filter the filter
- */
- public ServiceListenerRegistration(Filter filter)
- {
- this.filter = filter;
-
- if (System.getSecurityManager() != null)
- accessControlContext = AccessController.getContext();
- }
- }
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -50,6 +50,7 @@
import org.jboss.osgi.plugins.facade.api.AbstractPlugin;
import org.jboss.osgi.plugins.facade.api.AutoInstallPlugin;
import org.jboss.osgi.plugins.facade.api.BundleStoragePlugin;
+import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
import org.jboss.osgi.plugins.filter.NoFilter;
import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -171,20 +172,17 @@
executor = Executors.newFixedThreadPool(10);
this.executor = executor;
-
- // Create the system bundle
- createSystemBundle();
}
- private void createSystemBundle()
+ public void start()
{
+ // createSystemBundle
Manifest manifest = new Manifest();
Attributes attributes = manifest.getMainAttributes();
attributes.put(new Name(Constants.BUNDLE_NAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
attributes.put(new Name(Constants.BUNDLE_SYMBOLICNAME), Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
OSGiMetaData systemMetaData = new AbstractOSGiMetaData(manifest);
- this.systemBundle = new OSGiSystemState(systemMetaData);
- addBundle(systemBundle);
+ addBundle(systemBundle = new OSGiSystemState(this, systemMetaData));
}
/**
@@ -512,6 +510,7 @@
}
bundleState.setBundleManager(this);
+ bundleState.changeState(Bundle.INSTALLED);
bundlesById.put(bundleState.getBundleId(), bundleState);
log.debug("Added " + bundleState.getCanonicalName() + " id=" + bundleState.getBundleId());
}
@@ -760,7 +759,8 @@
OSGiServiceState result = new OSGiServiceState(bundleState, clazzes, service, properties);
result.internalRegister();
registeredServices.add(result);
- bundleState.fireServiceEvent(ServiceEvent.REGISTERED, result);
+ FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireServiceEvent(bundleState, ServiceEvent.REGISTERED, result);
log.debug("Registered service : " + result.toLongString());
return result;
}
@@ -773,7 +773,8 @@
void unregisterService(OSGiServiceState serviceState)
{
log.debug("Unregistering service: " + serviceState.toLongString());
- serviceState.getBundleState().fireServiceEvent(ServiceEvent.UNREGISTERING, serviceState);
+ FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireServiceEvent(serviceState.getBundleState(), ServiceEvent.UNREGISTERING, serviceState);
registeredServices.remove(serviceState);
serviceState.internalUnregister();
}
@@ -884,7 +885,8 @@
systemBundle.changeState(Bundle.ACTIVE);
// A framework event of type STARTED is fired
- systemBundle.fireFrameworkEvent(FrameworkEvent.STARTED, null);
+ FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.STARTED, null);
}
/**
@@ -897,18 +899,18 @@
return;
systemBundle.changeState(Bundle.STOPPING);
- for (AbstractBundleState bundle : getBundles())
+ for (AbstractBundleState bundleState : getBundles())
{
- if (bundle != systemBundle)
+ if (bundleState != systemBundle)
{
try
{
// [TODO] don't change the persistent state
- bundle.stop();
+ bundleState.stop();
}
catch (Throwable t)
{
- fireWarning(bundle, "stopping bundle", t);
+ fireWarning(bundleState, "stopping bundle", t);
}
}
}
@@ -924,26 +926,26 @@
if (systemBundle.getState() != Bundle.ACTIVE)
return;
- for (AbstractBundleState bundle : getBundles())
+ for (AbstractBundleState bundleState : getBundles())
{
- if (bundle != systemBundle && bundle.getState() == Bundle.ACTIVE)
+ if (bundleState != systemBundle && bundleState.getState() == Bundle.ACTIVE)
{
try
{
// [TODO] don't change the persistent state
- bundle.stop();
+ bundleState.stop();
}
catch (Throwable t)
{
- fireWarning(bundle, "stopping bundle", t);
+ fireWarning(bundleState, "stopping bundle", t);
}
try
{
- bundle.start();
+ bundleState.start();
}
catch (Throwable t)
{
- fireError(bundle, "starting bundle", t);
+ fireError(bundleState, "starting bundle", t);
}
}
}
@@ -954,15 +956,15 @@
*
* @param t the throwable
*/
- void fireError(AbstractBundleState bundleState, String context, Throwable t)
+ void fireError(Bundle bundle, String context, Throwable t)
{
- OSGiSystemState systemBundle = getSystemBundle();
+ FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
if (t instanceof BundleException)
- systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, t);
- else if (bundleState != null)
- systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+ plugin.fireFrameworkEvent(bundle, FrameworkEvent.ERROR, t);
+ else if (bundle != null)
+ plugin.fireFrameworkEvent(bundle, FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundle, t));
else
- systemBundle.fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error " + context, t));
+ plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.ERROR, new BundleException("Error " + context, t));
}
/**
@@ -970,15 +972,15 @@
*
* @param t the throwable
*/
- void fireWarning(AbstractBundleState bundleState, String context, Throwable t)
+ void fireWarning(Bundle bundle, String context, Throwable t)
{
- OSGiSystemState systemBundle = getSystemBundle();
+ FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
if (t instanceof BundleException)
- systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, t);
- else if (bundleState != null)
- systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+ plugin.fireFrameworkEvent(bundle, FrameworkEvent.WARNING, t);
+ else if (bundle != null)
+ plugin.fireFrameworkEvent(bundle, FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundle, t));
else
- systemBundle.fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error " + context, t));
+ plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.WARNING, new BundleException("Error " + context, t));
}
/**
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -78,7 +78,6 @@
this.unit = unit;
this.bundleId = bundleIDGenerator.incrementAndGet();
unit.getMutableMetaData().addMetaData(unit, DeploymentUnit.class);
- changeState(Bundle.INSTALLED);
}
public long getBundleId()
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -31,6 +31,7 @@
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
import org.jboss.osgi.plugins.util.CaseInsensitiveDictionary;
import org.jboss.util.collection.ConcurrentSet;
import org.osgi.framework.Bundle;
@@ -184,7 +185,8 @@
catch (Throwable t)
{
log.error("Error from getService for " + this, t);
- getBundleState().fireFrameworkEvent(FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
return null;
}
}
@@ -267,7 +269,9 @@
this.properties = null;
else
this.properties = new CaseInsensitiveDictionary(properties);
- bundleState.fireServiceEvent(ServiceEvent.MODIFIED, this);
+
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireServiceEvent(bundleState, ServiceEvent.MODIFIED, this);
}
/**
@@ -526,7 +530,8 @@
catch (Throwable t)
{
log.warn("Error from ungetService for " + this, t);
- getBundleState().fireFrameworkEvent(FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
}
finally
{
@@ -654,7 +659,7 @@
* @param accessControlContext
* @return true when the caller has permission
*/
- boolean hasPermission(AccessControlContext accessControlContext)
+ public boolean hasPermission(AccessControlContext accessControlContext)
{
try
{
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiSystemState.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -28,7 +28,6 @@
import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -43,13 +42,12 @@
{
/**
* Create a new OSGiSystemBundle.
- *
+ * @param bundleManager the bundle manager associated with the system bundle
* @param osgiMetaData the metadata for the system bundle
*/
- public OSGiSystemState(OSGiMetaData osgiMetaData)
+ public OSGiSystemState(OSGiBundleManager bundleManager, OSGiMetaData osgiMetaData)
{
super(osgiMetaData);
- changeState(Bundle.INSTALLED);
}
public long getBundleId()
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -35,7 +35,6 @@
import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
-import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiSystemState;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java (from rev 92874, projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -0,0 +1,227 @@
+/*
+ * 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.plugins.facade.plugins;
+
+//$Id: SystemPackagesPluginImpl.java 92858 2009-08-27 10:58:32Z thomas.diesler at jboss.com $
+
+import java.security.AccessControlContext;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
+import org.jboss.osgi.plugins.facade.bundle.OSGiServiceState;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.SynchronousBundleListener;
+
+/**
+ * A plugin that installs/starts bundles on framework startup.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 18-Aug-2009
+ */
+public class FrameworkEventsPluginImpl extends AbstractPluginImpl implements FrameworkEventsPlugin
+{
+ // Provide logging
+ final Logger log = Logger.getLogger(FrameworkEventsPluginImpl.class);
+
+ /** The bundle listeners */
+ private List<BundleListener> bundleListeners = new CopyOnWriteArrayList<BundleListener>();
+
+ /** The framework listeners */
+ private List<FrameworkListener> frameworkListeners = new CopyOnWriteArrayList<FrameworkListener>();
+
+ /** The service listeners */
+ private Map<ServiceListener, ServiceListenerRegistration> serviceListeners = new ConcurrentHashMap<ServiceListener, ServiceListenerRegistration>();
+
+ public FrameworkEventsPluginImpl(OSGiBundleManager bundleManager)
+ {
+ super(bundleManager);
+ }
+
+ @Override
+ public void addBundleListener(BundleListener listener)
+ {
+ bundleListeners.add(listener);
+ }
+
+ @Override
+ public void removeBundleListener(BundleListener listener)
+ {
+ bundleListeners.remove(listener);
+ }
+
+ @Override
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ frameworkListeners.add(listener);
+ }
+
+ @Override
+ public void removeFrameworkListener(FrameworkListener listener)
+ {
+ frameworkListeners.remove(listener);
+ }
+
+ @Override
+ public void addServiceListener(ServiceListener listener, Filter filter)
+ {
+ serviceListeners.put(listener, new ServiceListenerRegistration(filter));
+ }
+
+ @Override
+ public void removeServiceListener(ServiceListener listener)
+ {
+ serviceListeners.remove(listener);
+ }
+
+ @Override
+ public void fireBundleEvent(Bundle bundle, int type)
+ {
+ // Nobody is interested
+ if (bundleListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Expose the wrapper not the state itself
+ if (bundle instanceof AbstractBundleState)
+ bundle = ((AbstractBundleState)bundle).getBundleInternal();
+
+ BundleEvent event = new BundleEvent(type, bundle);
+
+ // Synchronous listeners first
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + bundle, t);
+ }
+ }
+
+ // Normal listeners after, if required
+ if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
+ {
+ for (BundleListener listener : bundleListeners)
+ {
+ try
+ {
+ if (listener instanceof SynchronousBundleListener == false)
+ listener.bundleChanged(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing bundle event: " + event.getType() + " for bundle " + this, t);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void fireFrameworkEvent(Bundle bundle, int type, Throwable throwable)
+ {
+ // Nobody is interested
+ if (frameworkListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Expose the wrapper not the state itself
+ if (bundle instanceof AbstractBundleState)
+ bundle = ((AbstractBundleState)bundle).getBundleInternal();
+
+ // Call the listeners
+ FrameworkEvent event = new FrameworkEvent(type, bundle, throwable);
+ for (FrameworkListener listener : frameworkListeners)
+ {
+ try
+ {
+ listener.frameworkEvent(event);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing framework event: " + event.getType() + " for bundle " + bundle, t);
+ }
+ }
+ }
+
+ @Override
+ public void fireServiceEvent(Bundle bundle, int type, OSGiServiceState service)
+ {
+ if (service == null)
+ throw new IllegalArgumentException("No serviceReference");
+
+ // Nobody is interested
+ if (serviceListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ // Expose the wrapper not the state itself
+ if (bundle instanceof AbstractBundleState)
+ bundle = ((AbstractBundleState)bundle).getBundleInternal();
+
+ ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
+
+ // Call the listeners
+ for (Map.Entry<ServiceListener, ServiceListenerRegistration> entry : serviceListeners.entrySet())
+ {
+ ServiceListener listener = entry.getKey();
+ ServiceListenerRegistration registration = entry.getValue();
+ try
+ {
+ if (registration.filter.match(service))
+ {
+ AccessControlContext accessControlContext = registration.accessControlContext;
+ if (accessControlContext == null || service.hasPermission(accessControlContext))
+ listener.serviceChanged(event);
+ }
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error while firing service event: " + type + " for service " + service, t);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/plugins/SystemPackagesPluginImpl.java 2009-08-27 15:53:11 UTC (rev 92876)
@@ -64,11 +64,35 @@
{
// The default system packages
allPackages.add("javax.management");
+ allPackages.add("javax.management.remote");
+ allPackages.add("javax.naming");
+ allPackages.add("javax.naming.spi");
+
+ allPackages.add("javax.xml.datatype");
+ allPackages.add("javax.xml.namespace");
+ allPackages.add("javax.xml.parsers");
+ allPackages.add("javax.xml.validation");
+ allPackages.add("javax.xml.transform");
+ allPackages.add("javax.xml.transform.dom");
+ allPackages.add("javax.xml.transform.sax");
+ allPackages.add("javax.xml.transform.stream");
+
+ allPackages.add("org.w3c.dom");
+ allPackages.add("org.w3c.dom.ls");
+ allPackages.add("org.w3c.dom.events");
+ allPackages.add("org.w3c.dom.ranges");
+ allPackages.add("org.w3c.dom.views");
+ allPackages.add("org.w3c.dom.traversal");
+ allPackages.add("org.xml.sax");
+ allPackages.add("org.xml.sax.ext");
+ allPackages.add("org.xml.sax.helpers");
+
allPackages.add("org.osgi.framework");
allPackages.add("org.osgi.service.startlevel");
allPackages.add("org.osgi.service.packageadmin");
allPackages.add("org.osgi.util.tracker");
+
String asString = packagesAsString(allPackages);
bundleManager.setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, asString);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 15:51:08 UTC (rev 92875)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-08-27 15:53:11 UTC (rev 92876)
@@ -16,9 +16,11 @@
<entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
<entry><key>org.osgi.framework.system.packages.extra</key><value>
org.jboss.logging;version=2.0,
+ org.jboss.osgi.spi.capability;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.util;version=1.0
</value></entry>
</map>
@@ -27,12 +29,15 @@
<uncallback method="removePlugin" />
</bean>
- <bean name="OSGiSystemPackages" class="org.jboss.osgi.plugins.facade.plugins.SystemPackagesPluginImpl">
+ <bean name="OSGiFrameworkEventsPlugin" class="org.jboss.osgi.plugins.facade.plugins.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
<bean name="OSGiStoragePlugin" class="org.jboss.osgi.plugins.facade.plugins.BundleStoragePluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
</bean>
+ <bean name="OSGiSystemPackages" class="org.jboss.osgi.plugins.facade.plugins.SystemPackagesPluginImpl">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
More information about the jboss-cvs-commits
mailing list