cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r767564 - in /cxf/dosgi/trunk: discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ dsw/cxf-dsw/src/main/java...
Date Wed, 22 Apr 2009 15:19:39 GMT
Author: davidb
Date: Wed Apr 22 15:19:37 2009
New Revision: 767564

URL: http://svn.apache.org/viewvc?rev=767564&view=rev
Log:
[Discovery] Support for modifiedService and removedService callbacks on the ServicePublication
service.
Unit tests included.

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizer.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizerTest.java
    cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizer.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizer.java?rev=767564&r1=767563&r2=767564&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizer.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizer.java
Wed Apr 22 15:19:37 2009
@@ -54,8 +54,7 @@
         try {
             Object obj = bundleContext.getService(sr);
             Collection<String> interfaces = Util.getMultiValueProperty(sr.getProperty("service.interface"));
-            String endpoint = sr.getProperty("osgi.remote.endpoint.location").toString();
-            String endpointKey = getKey(endpoint);
+            String endpointKey = getKey(sr.getProperty("osgi.remote.endpoint.location").toString());
 
             for (String name : interfaces) {
                 String path = Util.getZooKeeperPath(name);
@@ -68,26 +67,30 @@
             }
             return obj;
         } catch (Exception ex) {
-            LOG.log(Level.SEVERE, "Exception while processing a ServicePublication.", ex);
+            LOG.log(Level.SEVERE, "Exception while processing the addition of a ServicePublication.",
ex);
             return null;
         }
     }
     
     public void modifiedService(ServiceReference sr, Object obj) {
-        // TODO Auto-generated method stub
-
+        removedService(sr, obj);
+        addingService(sr);
     }
 
     public void removedService(ServiceReference sr, Object obj) {
-//        Collection<String> interfaces = Util.getMultiValueProperty(sr.getProperty("service.interface"));
-//        String endpoint = sr.getProperty("osgi.remote.endpoint.location").toString();
-//        String endpointKey = getKey(endpoint);
-//        
-//        for (String name : interfaces) {
-//            
-//        }
-//        zookeeper.delete(fullPath, -1);
-
+        try {
+            Collection<String> interfaces = Util.getMultiValueProperty(sr.getProperty("service.interface"));
+            String endpointKey = getKey(sr.getProperty("osgi.remote.endpoint.location").toString());
+            
+            for (String name : interfaces) {
+                String path = Util.getZooKeeperPath(name);
+                String fullPath = path + '/' + endpointKey;
+                LOG.info("Removing ZooKeeper node: " + fullPath);
+                zookeeper.delete(fullPath, -1);                                
+            }
+        } catch (Exception ex) {
+            LOG.log(Level.SEVERE, "Exception while processing the removal of a ServicePublication.",
ex);
+        }
     }
 
     void ensurePath(String path) throws KeeperException, InterruptedException {

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizerTest.java?rev=767564&r1=767563&r2=767564&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizerTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/PublishToZooKeeperCustomizerTest.java
Wed Apr 22 15:19:37 2009
@@ -21,6 +21,9 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.net.InetAddress;
+import java.net.URISyntaxException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -32,6 +35,7 @@
 import junit.framework.TestCase;
 
 import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.data.ACL;
@@ -40,6 +44,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.discovery.ServicePublication;
+import org.springframework.osgi.service.importer.support.ServiceReferenceEditor;
 
 public class PublishToZooKeeperCustomizerTest extends TestCase {
     public void testAddingService() throws Exception {
@@ -113,6 +118,57 @@
         EasyMock.verify(zk);
     }
     
+    public void testRemovedService() throws Exception {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        String endpoint = "http://localhost:2991/123";
+        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        EasyMock.expect(sr.getProperty("service.interface")).andReturn(Runnable.class.getName());
+        EasyMock.expect(sr.getProperty("osgi.remote.endpoint.location")).andReturn(endpoint);
       
+        EasyMock.replay(sr);
+        
+        ZooKeeper zk = EasyMock.createMock(ZooKeeper.class);
+        zk.delete(Util.getZooKeeperPath(Runnable.class.getName()) + "/" +
+                PublishToZooKeeperCustomizer.getKey(endpoint), -1);
+        EasyMock.replay(zk);
+        
+        PublishToZooKeeperCustomizer pc = new PublishToZooKeeperCustomizer(null, zk);
+        pc.removedService(sr, null);
+        
+        EasyMock.verify(bc);
+        EasyMock.verify(sr);
+        EasyMock.verify(zk);
+    }
+    
+    public void testModifiedService() {
+        final List<Object> actual = new ArrayList<Object>();
+        PublishToZooKeeperCustomizer pc = new PublishToZooKeeperCustomizer(null, null) {
+            @Override
+            public Object addingService(ServiceReference sr) {
+                actual.add("add");
+                actual.add(sr);
+                return null;
+            }
+
+            @Override
+            public void removedService(ServiceReference sr, Object obj) {
+                actual.add("remove");
+                actual.add(sr);
+                actual.add(obj);
+            }            
+        };
+
+        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        Object obj = new Object();
+        
+        assertEquals("Precondition failed", 0, actual.size());
+        pc.modifiedService(sr, obj);
+        
+        List<Object> expected = Arrays.asList("remove", sr, obj, "add", sr);
+        assertEquals(expected, actual);
+    }
+    
     public void testEnsurePath() throws Exception {
         ZooKeeper zk = EasyMock.createStrictMock(ZooKeeper.class);
         EasyMock.expect(zk.exists((String) EasyMock.anyObject(), EasyMock.anyBoolean())).andReturn(null);

Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java?rev=767564&r1=767563&r2=767564&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/hooks/AbstractClientHook.java
Wed Apr 22 15:19:37 2009
@@ -75,7 +75,7 @@
         ServiceEndpointDescription sd = 
             notification.getServiceEndpointDescription();
         if (sd.getProperty(Constants.REMOTE_INTERFACES_PROPERTY) == null) {
-            LOG.info("not proxifying service, enabling property unset: " 
+            LOG.info("not proxifying service, enabling property not set: " 
                      + Constants.REMOTE_INTERFACES_PROPERTY);
             return;
         }



Mime
View raw message