cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1412453 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src: main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
Date Thu, 22 Nov 2012 08:53:28 GMT
Author: cschneider
Date: Thu Nov 22 08:53:27 2012
New Revision: 1412453

URL: http://svn.apache.org/viewvc?rev=1412453&view=rev
Log:
DOSGI-146 Allow to define intents using services

Modified:
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java?rev=1412453&r1=1412452&r2=1412453&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImpl.java
Thu Nov 22 08:53:27 2012
@@ -31,6 +31,9 @@ import org.apache.cxf.binding.BindingCon
 import org.apache.cxf.endpoint.AbstractEndpointFactory;
 import org.apache.cxf.feature.Feature;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,18 +41,43 @@ import org.slf4j.LoggerFactory;
 public class IntentManagerImpl implements IntentManager {
     private static final String PROVIDED_INTENT_VALUE = "PROVIDED";
     private static final Logger LOG = LoggerFactory.getLogger(IntentManagerImpl.class);
+    private static final String INTENT_NAME_PROP = "org.apache.cxf.dosgi.IntentName";
 
-    private IntentMap intentMap;
-    private ServiceTracker intentTracker;
+    private final IntentMap intentMap;
+    private final ServiceTracker intentTracker;
     
     public IntentManagerImpl(IntentMap intentMap) {
         this.intentMap = intentMap;
         this.intentTracker = null;
     }
     
-    public IntentManagerImpl(BundleContext bc, IntentMap intentMap) {
+    public IntentManagerImpl(final BundleContext bc, final IntentMap intentMap) {
         this.intentMap = intentMap;
-        this.intentTracker = new ServiceTracker(bc, "", null);
+        Filter filter;
+        try {
+            filter = bc.createFilter("(" + INTENT_NAME_PROP + "=*)");
+        } catch (InvalidSyntaxException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+        this.intentTracker = new ServiceTracker(bc, filter, null) {
+
+            @Override
+            public Object addingService(ServiceReference reference) {
+                String intentName = (String) reference.getProperty(INTENT_NAME_PROP);
+                Object intent = bc.getService(reference);
+                LOG.info("Adding custom intent " + intentName + " defined in bundle " + reference.getBundle().getSymbolicName());
+                intentMap.put(intentName, intent);
+                return super.addingService(reference);
+            }
+
+            @Override
+            public void removedService(ServiceReference reference, Object service) {
+                String intentName = (String) reference.getProperty(INTENT_NAME_PROP);
+                intentMap.remove(intentName);
+                super.removedService(reference, service);
+            }
+            
+        };
         this.intentTracker.open();
     }
     

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java?rev=1412453&r1=1412452&r2=1412453&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/IntentMap.java
Thu Nov 22 08:53:27 2012
@@ -20,6 +20,7 @@ package org.apache.cxf.dosgi.dsw.qos;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Maps intent names to intent objects
@@ -27,12 +28,12 @@ import java.util.Map;
  * 
  * Also supports a default intent map. Custom intents can override the defaults 
  */
-public class IntentMap extends HashMap<String, Object> {
+public class IntentMap extends ConcurrentHashMap<String, Object> {
     private static final long serialVersionUID = 2606460607920520767L;
     private Map<String, Object> defaultMap;
     
     public IntentMap() {
-        super(new HashMap<String, Object>());
+        this(new HashMap<String, Object>());
     }
     
     public IntentMap(Map<String, Object> defaultMap) {

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java?rev=1412453&r1=1412452&r2=1412453&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/ActivatorTest.java
Thu Nov 22 08:53:27 2012
@@ -27,6 +27,7 @@ import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
 
@@ -45,8 +46,11 @@ public class ActivatorTest extends TestC
     public void testCreateAndShutdownRemoteServiceAdminService() throws Exception {
         IMocksControl control = EasyMock.createNiceControl();
         BundleContext bc = getMockBundleContext(control);
+        Filter filter = control.createMock(Filter.class);
+        EasyMock.expect(bc.createFilter(EasyMock.<String>anyObject())).andReturn(filter
);
+        EasyMock.expectLastCall().atLeastOnce();
         ServiceRegistration sr = control.createMock(ServiceRegistration.class);
-        EasyMock.expect(bc.registerService(EasyMock.eq(RemoteServiceAdmin.class.getName()),EasyMock.anyObject(),
(Dictionary)EasyMock.anyObject())).andReturn(sr).atLeastOnce();
+        EasyMock.expect(bc.registerService(EasyMock.eq(RemoteServiceAdmin.class.getName()),EasyMock.anyObject(),
(Dictionary<?,?>)EasyMock.anyObject())).andReturn(sr).atLeastOnce();
         
         control.replay();
         Activator a = new Activator();



Mime
View raw message