cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject [4/5] cxf-dosgi git commit: Update ServiceTrackers to use generics and @Override annotations
Date Fri, 29 Jan 2016 16:15:07 GMT
Update ServiceTrackers to use generics and @Override annotations


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

Branch: refs/heads/master
Commit: 2f2bb26af80833404a17a47d1582705a45b740d7
Parents: 3d2022a
Author: Amichai Rothman <amichai@apache.org>
Authored: Fri Jan 29 17:42:22 2016 +0200
Committer: Amichai Rothman <amichai@apache.org>
Committed: Fri Jan 29 17:42:22 2016 +0200

----------------------------------------------------------------------
 .../subscribe/EndpointListenerTracker.java      |  3 ++
 .../zookeeper/server/config/Activator.java      | 31 +++++++++-----------
 .../local/internal/LocalDiscovery.java          |  6 ++--
 .../util/SimpleServiceTracker.java              |  2 +-
 .../samples/discovery/consumer/Activator.java   | 21 +++++++------
 .../dosgi/samples/ds/consumer/Activator.java    |  4 +--
 .../dosgi/samples/greeter/client/Activator.java | 12 ++++----
 .../samples/greeter/client/rest/Activator.java  | 24 +++++++--------
 .../common/test1/MyServiceTracker.java          | 19 ++++++------
 .../test2/client/Test2ServiceTracker.java       | 24 +++++++--------
 10 files changed, 68 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/EndpointListenerTracker.java
----------------------------------------------------------------------
diff --git a/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/EndpointListenerTracker.java
b/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/EndpointListenerTracker.java
index 59e8c66..4d0a25f 100644
--- a/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/EndpointListenerTracker.java
+++ b/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/subscribe/EndpointListenerTracker.java
@@ -35,17 +35,20 @@ public class EndpointListenerTracker extends ServiceTracker<EndpointListener,
En
         this.imManager = imManager;
     }
 
+    @Override
     public EndpointListener addingService(ServiceReference<EndpointListener> endpointListener)
{
         imManager.addInterest(endpointListener);
         return null;
     }
 
+    @Override
     public void modifiedService(ServiceReference<EndpointListener> endpointListener,
EndpointListener service) {
         // called when an EndpointListener updates its service properties,
         // e.g. when its interest scope is expanded/reduced
         imManager.addInterest(endpointListener);
     }
 
+    @Override
     public void removedService(ServiceReference<EndpointListener> endpointListener,
EndpointListener service) {
         imManager.removeInterest(endpointListener);
     }

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
----------------------------------------------------------------------
diff --git a/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
b/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
index cbe0e79..a00c7b0 100644
--- a/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
+++ b/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
@@ -38,7 +38,7 @@ public class Activator implements BundleActivator {
     private static final Logger LOG = LoggerFactory.getLogger(Activator.class);
     private static final String ZOOKEEPER_PORT = "org.apache.cxf.dosgi.discovery.zookeeper.port";
     private static final String PID = "org.apache.cxf.dosgi.discovery.zookeeper.server";
-    private ServiceTracker st;
+    private ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> st;
 
     public void start(BundleContext context) throws Exception {
         synchronized (Activator.class) {
@@ -50,24 +50,21 @@ public class Activator implements BundleActivator {
             }
         }
 
-        st = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null) {
+        st = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>(context, ConfigurationAdmin.class,
null) {
             @Override
-            public Object addingService(ServiceReference reference) {
-                Object svc = super.addingService(reference);
-                if (svc instanceof ConfigurationAdmin) {
-                    try {
-                        ConfigurationAdmin cadmin = (ConfigurationAdmin) svc;
-                        Configuration cfg = cadmin.getConfiguration(PID, null);
-                        Dictionary<String, Object> props = new Hashtable<String,
Object>();
-                        String zp = System.getProperty(ZOOKEEPER_PORT);
-                        props.put("clientPort", zp);
-                        cfg.update(props);
-                        LOG.debug("Set ZooKeeper client port to {}", zp);
-                    } catch (IOException e) {
-                        LOG.error("Failed to configure ZooKeeper server!", e);
-                    }
+            public ConfigurationAdmin addingService(ServiceReference<ConfigurationAdmin>
reference) {
+                ConfigurationAdmin service = super.addingService(reference);
+                try {
+                    Configuration cfg = service.getConfiguration(PID, null);
+                    Dictionary<String, Object> props = new Hashtable<String, Object>();
+                    String zp = System.getProperty(ZOOKEEPER_PORT);
+                    props.put("clientPort", zp);
+                    cfg.update(props);
+                    LOG.debug("Set ZooKeeper client port to {}", zp);
+                } catch (IOException e) {
+                    LOG.error("Failed to configure ZooKeeper server!", e);
                 }
-                return svc;
+                return service;
             }
         };
         st.open();

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
----------------------------------------------------------------------
diff --git a/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
b/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
index ebfaefe..2761cf3 100644
--- a/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
+++ b/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
@@ -62,9 +62,9 @@ public class LocalDiscovery implements BundleListener {
 
             @Override
             public EndpointListener addingService(ServiceReference<EndpointListener>
reference) {
-                EndpointListener svc = super.addingService(reference);
-                addListener(reference, svc);
-                return svc;
+                EndpointListener service = super.addingService(reference);
+                addListener(reference, service);
+                return service;
             }
 
             @Override

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTracker.java
----------------------------------------------------------------------
diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTracker.java
b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTracker.java
index 29238aa..fc5b35e 100644
--- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTracker.java
+++ b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/util/SimpleServiceTracker.java
@@ -92,7 +92,7 @@ public class SimpleServiceTracker<T> extends ServiceTracker<T,
T> {
 
     @Override
     public T addingService(ServiceReference<T> reference) {
-        T service = (T) super.addingService(reference);
+        T service = super.addingService(reference);
         services.put(reference, service);
         for (SimpleServiceTrackerListener<T> listener : listeners) {
             listener.added(reference, service);

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/samples/discovery/client/src/main/java/org/apache/cxf/dosgi/samples/discovery/consumer/Activator.java
----------------------------------------------------------------------
diff --git a/samples/discovery/client/src/main/java/org/apache/cxf/dosgi/samples/discovery/consumer/Activator.java
b/samples/discovery/client/src/main/java/org/apache/cxf/dosgi/samples/discovery/consumer/Activator.java
index 9a6c1d4..cdeb360 100644
--- a/samples/discovery/client/src/main/java/org/apache/cxf/dosgi/samples/discovery/consumer/Activator.java
+++ b/samples/discovery/client/src/main/java/org/apache/cxf/dosgi/samples/discovery/consumer/Activator.java
@@ -34,25 +34,24 @@ import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
 
-    private ServiceTracker tracker;
+    private ServiceTracker<DisplayService, DisplayService> tracker;
     private Map<DisplayService, String> displays = new ConcurrentHashMap<DisplayService,
String>();
     private ScheduledExecutorService scheduler;
     private ScheduledFuture<?> handle;
 
     public void start(BundleContext bc) throws Exception {
-        tracker = new ServiceTracker(bc, DisplayService.class.getName(), null) {
+        tracker = new ServiceTracker<DisplayService, DisplayService>(bc, DisplayService.class,
null) {
 
-            public Object addingService(ServiceReference reference) {
-                Object svc = super.addingService(reference);
-                if (svc instanceof DisplayService) {
-                    DisplayService d = (DisplayService) svc;
-                    System.out.println("Adding display: " + d.getID() + " (" + d + ")");
-                    displays.put(d, d.getID());
-                }
-                return svc;
+            @Override
+            public DisplayService addingService(ServiceReference<DisplayService> reference)
{
+                DisplayService service = super.addingService(reference);
+                System.out.println("Adding display: " + service.getID() + " (" + service
+ ")");
+                displays.put(service, service.getID());
+                return service;
             }
 
-            public void removedService(ServiceReference reference, Object service) {
+            @Override
+            public void removedService(ServiceReference<DisplayService> reference,
DisplayService service) {
                 String value = displays.remove(service);
                 System.out.println("Removed display: " + value);
                 super.removedService(reference, service);

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/samples/ds/client/src/main/java/org/apache/cxf/dosgi/samples/ds/consumer/Activator.java
----------------------------------------------------------------------
diff --git a/samples/ds/client/src/main/java/org/apache/cxf/dosgi/samples/ds/consumer/Activator.java
b/samples/ds/client/src/main/java/org/apache/cxf/dosgi/samples/ds/consumer/Activator.java
index 304493d..ac059ad 100644
--- a/samples/ds/client/src/main/java/org/apache/cxf/dosgi/samples/ds/consumer/Activator.java
+++ b/samples/ds/client/src/main/java/org/apache/cxf/dosgi/samples/ds/consumer/Activator.java
@@ -32,10 +32,10 @@ import org.osgi.util.tracker.ServiceTracker;
  */
 public class Activator implements BundleActivator {
 
-    private ServiceTracker tracker;
+    private ServiceTracker<AdderService, AdderService> tracker;
 
     public void start(BundleContext context) throws Exception {
-        tracker = new ServiceTracker(context, AdderService.class.getName(), null);
+        tracker = new ServiceTracker<AdderService, AdderService>(context, AdderService.class,
null);
         tracker.open();
     }
 

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
----------------------------------------------------------------------
diff --git a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
index 6f46760..78b9fe1 100644
--- a/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
+++ b/samples/greeter/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/Activator.java
@@ -31,16 +31,14 @@ import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
 
-    private ServiceTracker tracker;
+    private ServiceTracker<GreeterService, GreeterService> tracker;
 
     public void start(final BundleContext bc) {
-        tracker = new ServiceTracker(bc, GreeterService.class.getName(), null) {
+        tracker = new ServiceTracker<GreeterService, GreeterService>(bc, GreeterService.class,
null) {
             @Override
-            public Object addingService(ServiceReference reference) {
-                Object service = super.addingService(reference);
-                if (service instanceof GreeterService) {
-                    useService((GreeterService) service);
-                }
+            public GreeterService addingService(ServiceReference<GreeterService> reference)
{
+                GreeterService service = super.addingService(reference);
+                useService(service);
                 return service;
             }
         };

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
----------------------------------------------------------------------
diff --git a/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
b/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
index 2d5cfd1..0fc7802 100644
--- a/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
+++ b/samples/greeter_rest/client/src/main/java/org/apache/cxf/dosgi/samples/greeter/client/rest/Activator.java
@@ -32,29 +32,25 @@ import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
 
-    private ServiceTracker tracker;
-    private ServiceTracker tracker2;
+    private ServiceTracker<GreeterService, GreeterService> tracker;
+    private ServiceTracker<GreeterService2, GreeterService2> tracker2;
 
     public void start(final BundleContext bc) {
-        tracker = new ServiceTracker(bc, GreeterService.class.getName(), null) {
+        tracker = new ServiceTracker<GreeterService, GreeterService>(bc, GreeterService.class,
null) {
             @Override
-            public Object addingService(ServiceReference reference) {
-                Object service = super.addingService(reference);
-                if (service instanceof GreeterService) {
-                    useGreeterService((GreeterService) service);
-                }
+            public GreeterService addingService(ServiceReference<GreeterService> reference)
{
+                GreeterService service = super.addingService(reference);
+                useGreeterService(service);
                 return service;
             }
         };
         tracker.open();
 
-        tracker2 = new ServiceTracker(bc, GreeterService2.class.getName(), null) {
+        tracker2 = new ServiceTracker<GreeterService2, GreeterService2>(bc, GreeterService2.class,
null) {
             @Override
-            public Object addingService(ServiceReference reference) {
-                Object service = super.addingService(reference);
-                if (service instanceof GreeterService2) {
-                    useGreeterService2((GreeterService2) service);
-                }
+            public GreeterService2 addingService(ServiceReference<GreeterService2>
reference) {
+                GreeterService2 service = super.addingService(reference);
+                useGreeterService2(service);
                 return service;
             }
         };

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test1/MyServiceTracker.java
----------------------------------------------------------------------
diff --git a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test1/MyServiceTracker.java
b/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test1/MyServiceTracker.java
index 8cc1e42..2886ce8 100644
--- a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test1/MyServiceTracker.java
+++ b/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test1/MyServiceTracker.java
@@ -29,21 +29,20 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class MyServiceTracker extends ServiceTracker {
+public class MyServiceTracker extends ServiceTracker<GreeterService, GreeterService>
{
 
     private static StringBuffer invocationResult = new StringBuffer();
 
     public MyServiceTracker(BundleContext context) {
-        super(context, GreeterService.class.getName(), null);
+        super(context, GreeterService.class, null);
     }
 
-    public Object addingService(ServiceReference reference) {
-        Object svc = super.addingService(reference);
-        if (svc instanceof GreeterService) {
-            System.out.println("[client] Got a GreeterService...");
-            invokeGreeter((GreeterService) svc);
-        }
-        return svc;
+    @Override
+    public GreeterService addingService(ServiceReference<GreeterService> reference)
{
+        GreeterService service = super.addingService(reference);
+        System.out.println("[client] Got a GreeterService...");
+        invokeGreeter(service);
+        return service;
     }
 
     public static String getResult() {
@@ -74,4 +73,4 @@ public class MyServiceTracker extends ServiceTracker {
             x.printStackTrace(System.err);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cxf-dosgi/blob/2f2bb26a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test2/client/Test2ServiceTracker.java
----------------------------------------------------------------------
diff --git a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test2/client/Test2ServiceTracker.java
b/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test2/client/Test2ServiceTracker.java
index 5933e21..9996eb4 100644
--- a/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test2/client/Test2ServiceTracker.java
+++ b/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/test2/client/Test2ServiceTracker.java
@@ -28,7 +28,7 @@ import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class Test2ServiceTracker extends ServiceTracker {
+public class Test2ServiceTracker extends ServiceTracker<Test2Service, Test2Service>
{
 
     public Test2ServiceTracker(BundleContext context) {
         super(context, getFilter(context), null);
@@ -48,21 +48,19 @@ public class Test2ServiceTracker extends ServiceTracker {
     }
 
     @Override
-    public Object addingService(ServiceReference reference) {
-        Object svc = super.addingService(reference);
-        if (svc instanceof Test2Service) {
-            System.out.println("*** Ref: " + reference);
-            for (String key : reference.getPropertyKeys()) {
-                System.out.println("  " + key + "-" + reference.getProperty(key));
-            }
-
-            invokeRemoteTestService(context, (Test2Service) svc);
+    public Test2Service addingService(ServiceReference<Test2Service> reference) {
+        Test2Service service = super.addingService(reference);
+        System.out.println("*** Ref: " + reference);
+        for (String key : reference.getPropertyKeys()) {
+            System.out.println("  " + key + "-" + reference.getProperty(key));
         }
-        return svc;
+
+        invokeRemoteTestService(context, service);
+        return service;
     }
 
-    private void invokeRemoteTestService(BundleContext bc, Test2Service svc) {
-        String res = svc.getRemoteStackTrace();
+    private void invokeRemoteTestService(BundleContext bc, Test2Service service) {
+        String res = service.getRemoteStackTrace();
 
         Dictionary<String, Object> props = new Hashtable<String, Object>();
         props.put("result", res);


Mime
View raw message