cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1182545 - in /cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus: extension/Extension.java osgi/OSGiAutomaticWorkQueue.java osgi/OSGiExtensionLocator.java
Date Wed, 12 Oct 2011 19:28:39 GMT
Author: dkulp
Date: Wed Oct 12 19:28:39 2011
New Revision: 1182545

URL: http://svn.apache.org/viewvc?rev=1182545&view=rev
Log:
More updates to allow better dynamic config of workqueues

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiAutomaticWorkQueue.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java?rev=1182545&r1=1182544&r2=1182545&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/extension/Extension.java Wed Oct 12
19:28:39 2011
@@ -35,6 +35,7 @@ public class Extension {
     protected String interfaceName;
     protected boolean deferred;
     protected Collection<String> namespaces = new ArrayList<String>();
+    protected Object args[];
     protected Object obj;
     
     public Extension() {
@@ -62,6 +63,7 @@ public class Extension {
         clazz = ext.clazz;
         intf = ext.intf;
         classloader = ext.classloader;
+        args = ext.args;
     }
     
     public String getName() {
@@ -130,8 +132,6 @@ public class Extension {
     }
     
     
-    
-    
     public Class<?> getClassObject(ClassLoader cl) {
         if (clazz == null) {
             if (classloader != null) {
@@ -160,10 +160,29 @@ public class Extension {
             Class<?> cls = getClassObject(cl);
             try {
                 //if there is a Bus constructor, use it.
-                if (b != null) {
+                if (b != null && args == null) {
                     Constructor con = cls.getConstructor(Bus.class);
                     obj = con.newInstance(b);
                     return obj;
+                } else if (b != null && args != null) {
+                    Constructor con;
+                    boolean noBus = false;
+                    try {
+                        con = cls.getConstructor(Bus.class, Object[].class);
+                    } catch (Exception ex) {
+                        con = cls.getConstructor(Object[].class);
+                        noBus = true;
+                    }
+                    if (noBus) {
+                        obj = con.newInstance(args);
+                    } else {
+                        obj = con.newInstance(b, args);
+                    }
+                    return obj;                    
+                } else if (args != null) {
+                    Constructor con = cls.getConstructor(Object[].class);
+                    obj = con.newInstance(args);
+                    return obj;                    
                 }
             } catch (Exception ex) {
                 //ignore
@@ -174,7 +193,6 @@ public class Extension {
         } catch (InstantiationException ex) {
             throw new ExtensionException(ex);
         }
-        
         return obj;
     }
     

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiAutomaticWorkQueue.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiAutomaticWorkQueue.java?rev=1182545&r1=1182544&r2=1182545&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiAutomaticWorkQueue.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiAutomaticWorkQueue.java Wed
Oct 12 19:28:39 2011
@@ -23,12 +23,11 @@ import java.util.Dictionary;
 
 import org.apache.cxf.workqueue.AutomaticWorkQueueImpl;
 import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
 
 /**
  * 
  */
-public class OSGiAutomaticWorkQueue extends AutomaticWorkQueueImpl implements ManagedService
{
+public class OSGiAutomaticWorkQueue extends AutomaticWorkQueueImpl {
     
     public OSGiAutomaticWorkQueue(String name) {
         super(name);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java?rev=1182545&r1=1182544&r2=1182545&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/OSGiExtensionLocator.java Wed
Oct 12 19:28:39 2011
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -52,6 +53,7 @@ import org.osgi.framework.SynchronousBun
 import org.osgi.framework.Version;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 
 /**
@@ -64,8 +66,27 @@ public class OSGiExtensionLocator implem
     private long id;
     private Extension listener;
 
-    static class WorkQueueList {
-        List<AutomaticWorkQueueImpl> list = new CopyOnWriteArrayList<AutomaticWorkQueueImpl>();
+    static class WorkQueueList implements ManagedService {
+        Map<String, OSGiAutomaticWorkQueue> queues 
+            = new ConcurrentHashMap<String, OSGiAutomaticWorkQueue>();
+
+        public void updated(Dictionary d) throws ConfigurationException {
+            String s = (String)d.get("org.apache.cxf.workqueue.names");
+            if (s != null) {
+                String s2[] = s.split(",");
+                for (String name : s2) {
+                    name = name.trim();
+                    if (queues.containsKey(name)) {
+                        queues.get(name).updated(d);
+                    } else {
+                        OSGiAutomaticWorkQueue wq = new OSGiAutomaticWorkQueue(name);
+                        wq.updated(d);
+                        wq.setShared(true);
+                        queues.put(name, wq);
+                    }
+                }
+            }
+        }
     };
     private WorkQueueList workQueues = new WorkQueueList();
     
@@ -97,7 +118,8 @@ public class OSGiExtensionLocator implem
             }
         }
         ServiceReference configAdminServiceRef =  
-            context.getServiceReference(ConfigurationAdmin.class.getName());  
+            context.getServiceReference(ConfigurationAdmin.class.getName());
+        
               
         if (configAdminServiceRef != null) {  
             ConfigurationAdmin configAdmin = (ConfigurationAdmin)  
@@ -105,33 +127,25 @@ public class OSGiExtensionLocator implem
               
             Configuration config = configAdmin.getConfiguration("org.apache.cxf.workqueues");
             Dictionary d = config.getProperties();
+            
+            Properties props = new Properties();
+            props.put(Constants.SERVICE_PID, "org.apache.cxf.workqueues");  
+            context.registerService(ManagedService.class.getName(),  
+                                    workQueues, props); 
+
+            
             if (d != null) {
-                Properties props = new Properties();
-                props.put(Constants.SERVICE_PID, "org.apache.cxf.workqueues");  
-                String s = (String)d.get("org.apache.cxf.workqueue.names");
-                String s2[] = s.split(",");
-                for (String name : s2) {
-                    name = name.trim();
-                    OSGiAutomaticWorkQueue wq = new OSGiAutomaticWorkQueue(name);
-                    wq.updated(d);
-                    wq.setShared(true);
-                    workQueues.list.add(wq);
-                    
-                    context.registerService(ManagedService.class.getName(),  
-                                            wq, props); 
-                }
-            }
-            if (!workQueues.list.isEmpty()) {
-                Extension ext = new Extension(WorkQueueList.class) {
-                    public Object getLoadedObject() {
-                        return workQueues;
-                    }
-                    public Extension cloneNoObject() {
-                        return this;
-                    }
-                };
-                ExtensionRegistry.addExtensions(Collections.singletonList(ext));
+                workQueues.updated(d);
             }
+            Extension ext = new Extension(WorkQueueList.class) {
+                public Object getLoadedObject() {
+                    return workQueues;
+                }
+                public Extension cloneNoObject() {
+                    return this;
+                }
+            };
+            ExtensionRegistry.addExtensions(Collections.singletonList(ext));
         }
     }
 
@@ -142,11 +156,11 @@ public class OSGiExtensionLocator implem
         while (!extensions.isEmpty()) {
             unregister(extensions.keySet().iterator().next());
         }
-        for (AutomaticWorkQueueImpl wq : workQueues.list) {
+        for (AutomaticWorkQueueImpl wq : workQueues.queues.values()) {
             wq.setShared(false);
             wq.shutdown(true);
         }
-        workQueues.list.clear();
+        workQueues.queues.clear();
     }
     private void registerBusListener() {
         listener = new Extension(OSGIBusListener.class);
@@ -211,7 +225,7 @@ public class OSGiExtensionLocator implem
             WorkQueueManager m = bus.getExtension(WorkQueueManager.class);
             WorkQueueList l = bus.getExtension(WorkQueueList.class);
             if (l != null && m != null) {
-                for (AutomaticWorkQueueImpl wq : l.list) {
+                for (AutomaticWorkQueueImpl wq : l.queues.values()) {
                     if (m.getNamedWorkQueue(wq.getName()) == null) {
                         m.addNamedWorkQueue(wq.getName(), wq);
                     }



Mime
View raw message