cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1518100 - in /cxf/dosgi/trunk: discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/ discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/ discovery/local/src/test/java/org/apache/cxf/dosgi/discove...
Date Wed, 28 Aug 2013 08:23:41 GMT
Author: cschneider
Date: Wed Aug 28 08:23:41 2013
New Revision: 1518100

URL: http://svn.apache.org/r1518100
Log:
Fxi warnings about generics

Modified:
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
    cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
    cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscoveryTest.java
    cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java

Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java?rev=1518100&r1=1518099&r2=1518100&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
(original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscovery.java
Wed Aug 28 08:23:41 2013
@@ -51,36 +51,37 @@ public class LocalDiscovery implements B
     final BundleContext bundleContext;
 
     EndpointDescriptionBundleParser bundleParser;
-    ServiceTracker listenerTracker;
+    ServiceTracker<EndpointListener, EndpointListener> listenerTracker;
 
     public LocalDiscovery(BundleContext bc) {
         this.bundleParser = new EndpointDescriptionBundleParser();
         bundleContext = bc;
 
-        listenerTracker = new ServiceTracker(bundleContext, EndpointListener.class.getName(),
null) {
+        listenerTracker = new ServiceTracker<EndpointListener, EndpointListener>(bundleContext,

+            EndpointListener.class, null) {
 
             @Override
-            public Object addingService(ServiceReference reference) {
-                Object svc = super.addingService(reference);
-                registerTracker(reference, svc);
+            public EndpointListener addingService(ServiceReference<EndpointListener>
reference) {
+                EndpointListener svc = super.addingService(reference);
+                addListener(reference, svc);
                 return svc;
             }
 
             @Override
-            public void modifiedService(ServiceReference reference, Object service) {
+            public void modifiedService(ServiceReference<EndpointListener> reference,
EndpointListener service) {
                 super.modifiedService(reference, service);
-                clearTracker(service);
+                removeListener(service);
 
                 // This may cause duplicate registrations of remote services,
                 // but that's fine and should be filtered out on another level.
-                // See Remove Service Admin spec section 122.6.3
-                registerTracker(reference, service);
+                // See Remote Service Admin spec section 122.6.3
+                addListener(reference, service);
             }
 
             @Override
-            public void removedService(ServiceReference reference, Object service) {
+            public void removedService(ServiceReference<EndpointListener> reference,
EndpointListener service) {
                 super.removedService(reference, service);
-                clearTracker(service);
+                removeListener(service);
             }
         };
         listenerTracker.open();
@@ -102,29 +103,11 @@ public class LocalDiscovery implements B
         }
     }
 
-    void registerTracker(ServiceReference reference, Object svc) {
-        if (svc instanceof EndpointListener) {
-            EndpointListener endpointListener = (EndpointListener) svc;
-            Collection<String> filters = addListener(reference, endpointListener);
-            triggerCallbacks(filters, endpointListener);
-        }
-    }
-
-    void clearTracker(Object svc) {
-        if (svc instanceof EndpointListener) {
-            EndpointListener endpointListener = (EndpointListener) svc;
-            removeListener(endpointListener);
-            // If the tracker was removed or the scope was changed this doesn't require
-            // additional callbacks on the tracker. Its the responsibility of the tracker
-            // itself to clean up any orphans. See Remote Service Admin spec 122.6.3
-        }
-    }
-
-    private Collection<String> addListener(ServiceReference endpointListenerRef, EndpointListener
endpointListener) {
+    void addListener(ServiceReference<EndpointListener> endpointListenerRef, EndpointListener
endpointListener) {
         List<String> filters = Utils.getStringPlusProperty(endpointListenerRef,
                 EndpointListener.ENDPOINT_LISTENER_SCOPE);
         if (filters.isEmpty()) {
-            return filters;
+            return;
         }
 
         listenerToFilters.put(endpointListener, filters);
@@ -138,11 +121,16 @@ public class LocalDiscovery implements B
                 filterToListeners.put(filter, list);
             }
         }
-
-        return filters;
+        triggerCallbacks(filters, endpointListener);
     }
 
-    private void removeListener(EndpointListener endpointListener) {
+    /**
+     * If the tracker was removed or the scope was changed this doesn't require
+     * additional callbacks on the tracker. Its the responsibility of the tracker
+     * itself to clean up any orphans. See Remote Service Admin spec 122.6.3
+     * @param endpointListener
+     */
+    void removeListener(EndpointListener endpointListener) {
         Collection<String> filters = listenerToFilters.remove(endpointListener);
         if (filters == null) {
             return;

Modified: cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java?rev=1518100&r1=1518099&r2=1518100&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
(original)
+++ cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/discovery/local/util/Utils.java
Wed Aug 28 08:23:41 2013
@@ -49,7 +49,7 @@ public final class Utils {
         // prevent instantiation
     }
 
-    public static List<String> getStringPlusProperty(ServiceReference sr, String key)
{
+    public static List<String> getStringPlusProperty(ServiceReference<?> sr,
String key) {
         Object value = sr.getProperty(key);
         if (value == null) {
             return Collections.emptyList();

Modified: cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscoveryTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscoveryTest.java?rev=1518100&r1=1518099&r2=1518100&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscoveryTest.java
(original)
+++ cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/internal/LocalDiscoveryTest.java
Wed Aug 28 08:23:41 2013
@@ -156,7 +156,8 @@ public class LocalDiscoveryTest extends 
         // Create an EndpointListener
         final Map<String, Object> props = new Hashtable<String, Object>();
         props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(objectClass=*)");
-        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<EndpointListener> sr = EasyMock.createMock(ServiceReference.class);
         EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String[]
{})).anyTimes();
         EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
             public Object answer() throws Throwable {
@@ -169,7 +170,7 @@ public class LocalDiscoveryTest extends 
         endpointListener.endpointAdded((EndpointDescription) EasyMock.anyObject(), EasyMock.eq("(objectClass=*)"));
         EasyMock.expectLastCall();
         EasyMock.replay(endpointListener);
-        ld.registerTracker(sr, endpointListener);
+        ld.addListener(sr, endpointListener);
 
         // Start the bundle
         BundleEvent be = new BundleEvent(BundleEvent.STARTED, bundle);
@@ -213,7 +214,8 @@ public class LocalDiscoveryTest extends 
 
         final Map<String, Object> props = new Hashtable<String, Object>();
         props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, new String[] {"(objectClass=org.example.ClassA)"});
-        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<EndpointListener> sr = EasyMock.createMock(ServiceReference.class);
         EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String[]
{})).anyTimes();
         EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
             public Object answer() throws Throwable {
@@ -296,7 +298,8 @@ public class LocalDiscoveryTest extends 
 
         final Map<String, Object> props = new Hashtable<String, Object>();
         props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, "(objectClass=Aaaa)");
-        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<EndpointListener> sr = EasyMock.createMock(ServiceReference.class);
         EasyMock.expect(sr.getPropertyKeys()).andReturn(props.keySet().toArray(new String[]
{})).anyTimes();
         EasyMock.expect(sr.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
             public Object answer() throws Throwable {
@@ -310,7 +313,7 @@ public class LocalDiscoveryTest extends 
 
         assertEquals("Precondition failed", 0, ld.listenerToFilters.size());
         assertEquals("Precondition failed", 0, ld.filterToListeners.size());
-        ld.registerTracker(sr, endpointListener);
+        ld.addListener(sr, endpointListener);
 
         assertEquals(1, ld.listenerToFilters.size());
         assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(endpointListener));
@@ -318,7 +321,8 @@ public class LocalDiscoveryTest extends 
         assertEquals(Collections.singletonList(endpointListener), ld.filterToListeners.get("(objectClass=Aaaa)"));
 
         // Add another one with the same scope filter
-        ServiceReference sr2 = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<EndpointListener> sr2 = EasyMock.createMock(ServiceReference.class);
         EasyMock.expect(sr2.getPropertyKeys()).andReturn(props.keySet().toArray(new String[]
{})).anyTimes();
         EasyMock.expect(sr2.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
             public Object answer() throws Throwable {
@@ -329,7 +333,7 @@ public class LocalDiscoveryTest extends 
 
         EndpointListener endpointListener2 = EasyMock.createMock(EndpointListener.class);
         EasyMock.replay(endpointListener2);
-        ld.registerTracker(sr2, endpointListener2);
+        ld.addListener(sr2, endpointListener2);
 
         assertEquals(2, ld.listenerToFilters.size());
         assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(endpointListener));
@@ -342,7 +346,8 @@ public class LocalDiscoveryTest extends 
         // Add another listener with a multi-value scope
         final Map<String, Object> props2 = new Hashtable<String, Object>();
         props2.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, Arrays.asList("(objectClass=X)",
"(objectClass=Y)"));
-        ServiceReference sr3 = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<EndpointListener> sr3 = EasyMock.createMock(ServiceReference.class);
         EasyMock.expect(sr3.getPropertyKeys()).andReturn(props2.keySet().toArray(new String[]
{})).anyTimes();
         EasyMock.expect(sr3.getProperty((String) EasyMock.anyObject())).andAnswer(new IAnswer<Object>()
{
             public Object answer() throws Throwable {
@@ -353,7 +358,7 @@ public class LocalDiscoveryTest extends 
 
         EndpointListener endpointListener3 = EasyMock.createMock(EndpointListener.class);
         EasyMock.replay(endpointListener3);
-        ld.registerTracker(sr3, endpointListener3);
+        ld.addListener(sr3, endpointListener3);
 
         assertEquals(3, ld.listenerToFilters.size());
         assertEquals(Collections.singletonList("(objectClass=Aaaa)"), ld.listenerToFilters.get(endpointListener));
@@ -376,16 +381,14 @@ public class LocalDiscoveryTest extends 
         ld.filterToListeners.put("(objectClass=foo.bar.Bheuaark)",
                 new ArrayList<EndpointListener>(Arrays.asList(endpointListener)));
 
-        ld.clearTracker("foobar"); // should not barf
-
         assertEquals(1, ld.listenerToFilters.size());
         assertEquals(2, ld.filterToListeners.size());
         assertEquals(1, ld.filterToListeners.values().iterator().next().size());
-        ld.clearTracker(EasyMock.createMock(EndpointListener.class));
+        ld.removeListener(EasyMock.createMock(EndpointListener.class));
         assertEquals(1, ld.listenerToFilters.size());
         assertEquals(2, ld.filterToListeners.size());
         assertEquals(1, ld.filterToListeners.values().iterator().next().size());
-        ld.clearTracker(endpointListener);
+        ld.removeListener(endpointListener);
         assertEquals(0, ld.listenerToFilters.size());
         assertEquals(2, ld.filterToListeners.size());
         assertEquals(0, ld.filterToListeners.values().iterator().next().size());

Modified: cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java?rev=1518100&r1=1518099&r2=1518100&view=diff
==============================================================================
--- cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java
(original)
+++ cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/AbstractDosgiTest.java
Wed Aug 28 08:23:41 2013
@@ -61,6 +61,9 @@ public class AbstractDosgiTest {
         Thread.sleep(interval);
     }
 
+    @SuppressWarnings({
+        "rawtypes", "unchecked"
+    })
     protected ServiceReference waitService(BundleContext bc, Class cls, String filter, int
timeout)
         throws Exception {
         System.out.println("Waiting for service: " + cls + " " + filter);



Mime
View raw message