cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] cxf-dosgi git commit: [DOSGI-245] Fix intents not found when published interface is not Object
Date Tue, 12 Jul 2016 14:06:23 GMT
Repository: cxf-dosgi
Updated Branches:
  refs/heads/master ba53d0495 -> a19974dad


[DOSGI-245] Fix intents not found when published interface is not Object


Project: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/commit/04cf85ba
Tree: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/tree/04cf85ba
Diff: http://git-wip-us.apache.org/repos/asf/cxf-dosgi/diff/04cf85ba

Branch: refs/heads/master
Commit: 04cf85ba928d253c7e96601e302dd2be8a6ffd7d
Parents: ba53d04
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Jul 12 16:05:43 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Jul 12 16:05:43 2016 +0200

----------------------------------------------------------------------
 .../common/intent/impl/IntentManagerImpl.java   | 69 +++++++++++++-------
 .../customintent/CustomIntentActivator.java     |  2 +-
 .../rest/provider/RsProviderCustomTest.java     | 10 +--
 .../handlers/rest/simple/RsProviderTest.java    |  2 +-
 4 files changed, 51 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/04cf85ba/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
index 7c0f6c8..d40fcd4 100644
--- a/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
+++ b/common/src/main/java/org/apache/cxf/dosgi/common/intent/impl/IntentManagerImpl.java
@@ -18,8 +18,6 @@
  */
 package org.apache.cxf.dosgi.common.intent.impl;
 
-import static org.osgi.service.component.annotations.ReferenceCardinality.MULTIPLE;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -34,10 +32,15 @@ import org.apache.cxf.dosgi.common.intent.IntentHandler;
 import org.apache.cxf.dosgi.common.intent.IntentManager;
 import org.apache.cxf.dosgi.common.intent.IntentProvider;
 import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -47,28 +50,41 @@ public class IntentManagerImpl implements IntentManager {
     static final Logger LOG = LoggerFactory.getLogger(IntentManagerImpl.class);
     private static final int DEFAULT_INTENT_TIMEOUT = 30000;
 
-    private final Map<String, Object> intentMap;
+    private final Map<String, Object> intentMap = new HashMap<String, Object>();
     private final long maxIntentWaitTime = DEFAULT_INTENT_TIMEOUT;
-
-    public IntentManagerImpl() {
-        this.intentMap = new HashMap<String, Object>();
+    private ServiceTracker<Object, Object> tracker;
+
+    @Activate
+    public void activate(BundleContext context) throws InvalidSyntaxException {
+        Filter filter = FrameworkUtil.createFilter("(" + IntentManager.INTENT_NAME_PROP +
"=*)");
+        tracker = new ServiceTracker<Object, Object>(context, filter, null) {
+            @Override
+            public Object addingService(ServiceReference<Object> reference) {
+                Object intent = super.addingService(reference);
+                addIntent(intent, (String)reference.getProperty(INTENT_NAME_PROP));
+                return intent;
+            }
+            
+            @Override
+            public void removedService(ServiceReference<Object> reference, Object intent)
{
+                removeIntent(intent, (String)reference.getProperty(INTENT_NAME_PROP));
+                super.removedService(reference, intent);
+            }
+        };
+        tracker.open();
+    }
+    
+    @Deactivate
+    public void deactivate() {
+        tracker.close();
     }
 
-    @Reference //
-    (//
-        cardinality = MULTIPLE, //
-        policy = ReferencePolicy.DYNAMIC, //
-        target = "(" + IntentManager.INTENT_NAME_PROP + "=*)", //
-        policyOption = ReferencePolicyOption.GREEDY
-    )
-    public synchronized void addIntent(Object intent, Map<String, ?> props) {
-        String intentName = (String)props.get(INTENT_NAME_PROP);
+    public synchronized void addIntent(Object intent, String intentName) {
         LOG.info("Adding custom intent " + intentName);
         intentMap.put(intentName, intent);
     }
 
-    public synchronized void removeIntent(Object intent, Map<String, ?> props) {
-        String intentName = (String)props.get(INTENT_NAME_PROP);
+    public synchronized void removeIntent(Object intent, String intentName) {
         intentMap.remove(intentName);
     }
 
@@ -118,12 +134,21 @@ public class IntentManagerImpl implements IntentManager {
     public synchronized String[] assertAllIntentsSupported(Set<String> requiredIntents)
{
         long endTime = System.currentTimeMillis() + maxIntentWaitTime;
         Set<String> unsupportedIntents;
+        boolean first = true;
         do {
             unsupportedIntents = getMissingIntents(requiredIntents);
             long remainingSeconds = (endTime - System.currentTimeMillis()) / 1000;
             if (!unsupportedIntents.isEmpty() && remainingSeconds > 0) {
-                LOG.info("Waiting for custom intents " + Arrays.toString(unsupportedIntents.toArray())
+ " timeout in "
-                          + remainingSeconds);
+                String msg = "Waiting for custom intents {} timeout in {} seconds";
+                if (first) {
+                    LOG.info(msg, Arrays.toString(unsupportedIntents.toArray()), remainingSeconds);
+                    first = false;
+                } else {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug(msg, Arrays.toString(unsupportedIntents.toArray()), remainingSeconds);
+                    }
+                }
+                
                 try {
                     wait(1000);
                 } catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/04cf85ba/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
----------------------------------------------------------------------
diff --git a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
index ca4efda..a69c6f3 100644
--- a/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
+++ b/itests/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/customintent/CustomIntentActivator.java
@@ -29,7 +29,7 @@ public class CustomIntentActivator implements BundleActivator {
     public void start(BundleContext context) throws Exception {
         Dictionary<String, String> props = new Hashtable<String, String>();
         props.put("org.apache.cxf.dosgi.IntentName", "myIntent");
-        context.registerService(Object.class.getName(), new CustomFeature(), props);
+        context.registerService(CustomFeature.class.getName(), new CustomFeature(), props);
     }
 
     public void stop(BundleContext context) throws Exception {

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/04cf85ba/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/provider/RsProviderCustomTest.java
----------------------------------------------------------------------
diff --git a/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/provider/RsProviderCustomTest.java
b/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/provider/RsProviderCustomTest.java
index 19689c1..e28e108 100644
--- a/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/provider/RsProviderCustomTest.java
+++ b/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/provider/RsProviderCustomTest.java
@@ -28,7 +28,6 @@ import java.util.Map;
 
 import org.apache.aries.rsa.spi.Endpoint;
 import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
-import org.apache.cxf.dosgi.common.intent.IntentManager;
 import org.apache.cxf.dosgi.common.intent.IntentProvider;
 import org.apache.cxf.dosgi.common.intent.impl.IntentManagerImpl;
 import org.apache.cxf.dosgi.dsw.handlers.rest.RsConstants;
@@ -58,7 +57,7 @@ public class RsProviderCustomTest {
         
         Map<String, Object> props = new HashMap<>();
         props.put(Constants.OBJECTCLASS, new String[]{TaskService.class.getName()});
-        String serviceAddress = "http://localhost:8181/";
+        String serviceAddress = "http://localhost:9181/";
         props.put(RsConstants.RS_ADDRESS_PROPERTY, serviceAddress);
         props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "my");
         Class<?>[] ifaces = new Class[]{TaskService.class};
@@ -82,7 +81,7 @@ public class RsProviderCustomTest {
 
     private void addIntent(IntentManagerImpl intentManager, String name, Object ... intents)
{
         IntentProvider provider = intentProvider(intents);
-        intentManager.addIntent(provider, intentProps(name));
+        intentManager.addIntent(provider, name);
     }
 
     private IntentProvider intentProvider(final Object ... intents) {
@@ -95,9 +94,4 @@ public class RsProviderCustomTest {
         };
     }
 
-    private Map<String, String> intentProps(String name) {
-        Map<String, String> props = new HashMap<>();
-        props.put(IntentManager.INTENT_NAME_PROP, name);
-        return props;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/04cf85ba/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/simple/RsProviderTest.java
----------------------------------------------------------------------
diff --git a/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/simple/RsProviderTest.java
b/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/simple/RsProviderTest.java
index 16a49a9..d082242 100644
--- a/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/simple/RsProviderTest.java
+++ b/provider-rs/src/test/java/org/apache/cxf/dosgi/dsw/handlers/rest/simple/RsProviderTest.java
@@ -52,7 +52,7 @@ public class RsProviderTest {
         
         Map<String, Object> props = new HashMap<>();
         props.put(Constants.OBJECTCLASS, new String[]{TaskService.class.getName()});
-        String serviceAddress = "http://localhost:8181/";
+        String serviceAddress = "http://localhost:9181/";
         props.put(RsConstants.RS_ADDRESS_PROPERTY, serviceAddress);
         Class<?>[] ifaces = new Class[]{TaskService.class};
         Endpoint endpoint = rsProvider.exportService(taskService,


Mime
View raw message