felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1128515 - in /felix/trunk/framework/src: main/java/org/apache/felix/framework/ main/java/org/apache/felix/framework/util/ test/java/org/apache/felix/framework/util/
Date Fri, 27 May 2011 23:17:52 GMT
Author: rickhall
Date: Fri May 27 23:17:52 2011
New Revision: 1128515

URL: http://svn.apache.org/viewvc?rev=1128515&view=rev
Log:
Modify framework wiring and framework start level object to registry
the package admin and start level services directly, rather than using
an activator. (FELIX-2969, FELIX-2975)

Removed:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/PackageAdminActivator.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/StartLevelActivator.java
Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
    felix/trunk/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1128515&r1=1128514&r2=1128515&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Fri May 27 23:17:52
2011
@@ -159,11 +159,11 @@ public class Felix extends BundleImpl im
     private long m_nextId = 1L;
     private final Object m_nextIdLock = new Object[0];
 
-    // List of event listeners.
-    private EventDispatcher m_dispatcher = null;
-
     // Service registry.
-    private ServiceRegistry m_registry = null;
+    private final ServiceRegistry m_registry;
+
+    // List of event listeners.
+    private final EventDispatcher m_dispatcher;
 
     // Reusable bundle URL stream handler.
     private final URLStreamHandler m_bundleStreamHandler;
@@ -391,10 +391,21 @@ public class Felix extends BundleImpl im
             throw new RuntimeException(ex.getMessage());
         }
 
+        // Create service registry.
+        m_registry = new ServiceRegistry(m_logger, new ServiceRegistryCallbacks() {
+            public void serviceChanged(ServiceEvent event, Dictionary oldProps)
+            {
+                fireServiceEvent(event, oldProps);
+            }
+        });
+
+        // Create event dispatcher.
+        m_dispatcher = new EventDispatcher(m_logger, m_registry);
+
         // Create framework wiring object.
-        m_fwkWiring = new FrameworkWiringImpl(this);
+        m_fwkWiring = new FrameworkWiringImpl(this, m_registry);
         // Create framework start level object.
-        m_fwkStartLevel = new FrameworkStartLevelImpl(this);
+        m_fwkStartLevel = new FrameworkStartLevelImpl(this, m_registry);
     }
 
     Logger getLogger()
@@ -616,16 +627,8 @@ public class Felix extends BundleImpl im
                 m_activatorList = (List) m_configMutableMap.get(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP);
                 m_activatorList = (m_activatorList == null) ? new ArrayList() : new ArrayList(m_activatorList);
 
-                // Create service registry.
-                m_registry = new ServiceRegistry(m_logger, new ServiceRegistryCallbacks()
{
-                    public void serviceChanged(ServiceEvent event, Dictionary oldProps)
-                    {
-                        fireServiceEvent(event, oldProps);
-                    }
-                });
-
                 // Initialize event dispatcher.
-                m_dispatcher = EventDispatcher.start(m_logger, m_registry);
+                m_dispatcher.startDispatching();
 
                 // Create the bundle cache, if necessary, so that we can reload any
                 // installed bundles.
@@ -777,7 +780,7 @@ public class Felix extends BundleImpl im
                 }
                 catch (Throwable ex)
                 {
-                    EventDispatcher.shutdown();
+                    m_dispatcher.stopDispatching();
                     m_logger.log(Logger.LOG_ERROR, "Unable to start system bundle.", ex);
                     throw new RuntimeException("Unable to start system bundle.");
                 }
@@ -4849,10 +4852,6 @@ public class Felix extends BundleImpl im
     {
         public void start(BundleContext context) throws Exception
         {
-            // Add the bundle activator for the package admin service.
-            m_activatorList.add(0, new PackageAdminActivator(Felix.this));
-            // Add the bundle activator for the start level service.
-            m_activatorList.add(0, new StartLevelActivator(m_logger, Felix.this));
             // Add the bundle activator for the url handler service.
             m_activatorList.add(0, new URLHandlersActivator(m_configMap, Felix.this));
 
@@ -4884,7 +4883,7 @@ public class Felix extends BundleImpl im
             m_fwkStartLevel.stop();
 
             // Shutdown event dispatching queue.
-            EventDispatcher.shutdown();
+            m_dispatcher.stopDispatching();
 
             // Since there may be updated and uninstalled bundles that
             // have not been refreshed, we will take care of refreshing

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java?rev=1128515&r1=1128514&r2=1128515&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkStartLevelImpl.java
Fri May 27 23:17:52 2011
@@ -22,9 +22,12 @@ import java.util.ArrayList;
 import java.util.List;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.startlevel.BundleStartLevel;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
+import org.osgi.service.startlevel.StartLevel;
 
 class FrameworkStartLevelImpl implements FrameworkStartLevel, Runnable
 {
@@ -37,11 +40,16 @@ class FrameworkStartLevelImpl implements
     private final List m_requests = new ArrayList();
     private final List<FrameworkListener[]> m_requestListeners
         = new ArrayList<FrameworkListener[]>();
+    private final ServiceRegistration<StartLevel> m_slReg;
     private Thread m_thread = null;
 
-    FrameworkStartLevelImpl(Felix felix)
+    FrameworkStartLevelImpl(Felix felix, ServiceRegistry registry)
     {
         m_felix = felix;
+        m_slReg = registry.registerService(felix,
+            new String[] { StartLevel.class.getName() },
+            new StartLevelImpl(felix),
+            null);
     }
 
     // Should only be called hold requestList lock.

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java?rev=1128515&r1=1128514&r2=1128515&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/FrameworkWiringImpl.java
Fri May 27 23:17:52 2011
@@ -20,14 +20,13 @@ package org.apache.felix.framework;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import org.osgi.framework.AdminPermission;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.wiring.FrameworkWiring;
+import org.osgi.service.packageadmin.PackageAdmin;
 
 class FrameworkWiringImpl implements FrameworkWiring, Runnable
 {
@@ -35,12 +34,17 @@ class FrameworkWiringImpl implements Fra
     private final List<Collection<Bundle>> m_requests = new ArrayList();
     private final List<FrameworkListener[]> m_requestListeners
         = new ArrayList<FrameworkListener[]>();
+    private final ServiceRegistration<PackageAdmin> m_paReg;
     private Thread m_thread = null;
 
 
-    public FrameworkWiringImpl(Felix felix)
+    public FrameworkWiringImpl(Felix felix, ServiceRegistry registry)
     {
         m_felix = felix;
+        m_paReg = registry.registerService(felix,
+            new String[] { PackageAdmin.class.getName() },
+            new PackageAdminImpl(felix),
+            null);
     }
 
     /**

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java?rev=1128515&r1=1128514&r2=1128515&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
Fri May 27 23:17:52 2011
@@ -80,16 +80,14 @@ public class EventDispatcher
     // Pooled requests to avoid memory allocation.
     private static final ArrayList m_requestPool = new ArrayList();
 
-    private EventDispatcher(Logger logger, ServiceRegistry registry)
+    public EventDispatcher(Logger logger, ServiceRegistry registry)
     {
         m_logger = logger;
         m_registry = registry;
     }
 
-    public static EventDispatcher start(Logger logger, ServiceRegistry registry)
+    public void startDispatching()
     {
-        EventDispatcher eventDispatcher = new EventDispatcher(logger, registry);
-
         synchronized (m_threadLock)
         {
             // Start event dispatching thread if necessary.
@@ -124,11 +122,9 @@ public class EventDispatcher
             // reference counting and flags
             m_references++;
         }
-
-        return eventDispatcher;
     }
 
-    public static void shutdown()
+    public void stopDispatching()
     {
         synchronized (m_threadLock)
         {

Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java?rev=1128515&r1=1128514&r2=1128515&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
(original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/util/EventDispatcherTest.java
Fri May 27 23:17:52 2011
@@ -83,8 +83,7 @@ public class EventDispatcherTest extends
         registry.registerService(null, new String [] {EventHook.class.getName()}, eh2, new
Hashtable());
 
         // -- Set up event dispatcher
-        EventDispatcher ed = EventDispatcher.start(logger, registry);
-        EventDispatcher.shutdown(); // stop the thread - would be nicer if we could create
one without a thread for testing
+        EventDispatcher ed = new EventDispatcher(logger, registry);
 
         // -- Register some listeners
         final List fired = Collections.synchronizedList(new ArrayList());



Mime
View raw message