[jboss-cvs] JBossAS SVN: r92868 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade: plugins and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 27 10:04:57 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-27 10:04:57 -0400 (Thu, 27 Aug 2009)
New Revision: 92868
Added:
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/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
Log:
WIP
Added: 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/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/api/FrameworkEventsPlugin.java 2009-08-27 14:04:57 UTC (rev 92868)
@@ -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
Added: 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/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java 2009-08-27 14:04:57 UTC (rev 92868)
@@ -0,0 +1,220 @@
+/*
+ * 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.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)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void addFrameworkListener(FrameworkListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void addServiceListener(ServiceListener listener, Filter filter)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void fireBundleEvent(Bundle bundle, int type)
+ {
+ // Nobody is interested
+ if (bundleListeners.isEmpty())
+ return;
+
+ // Are we active?
+ if (getBundleManager().isActive() == false)
+ return;
+
+ 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;
+
+ // 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;
+
+ 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);
+ }
+ }
+ }
+
+ @Override
+ public void removeBundleListener(BundleListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeFrameworkListener(FrameworkListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void removeServiceListener(ServiceListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list