cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r901721 - in /cxf/dosgi/trunk/discovery/distributed: cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ zookeeper-server-config/src/main/java/org/apach...
Date Thu, 21 Jan 2010 14:30:52 GMT
Author: davidb
Date: Thu Jan 21 14:30:51 2010
New Revision: 901721

URL: http://svn.apache.org/viewvc?rev=901721&view=rev
Log:
Changed the default behaviour of the Zookeeper Discovery client back to what it was in CXF-DOSGi
1.1.
The zookeeper discovery client is dormant until configured. It can be configured through the
OSGi Configuration Admin service. 
To enable it, at least the following value needs to be provided for its PID: org.apache.cxf.dosgi.discovery.zookeeper
  zookeeper.host=...
Also fixed the updated() method on the Activator (ManagedService) to update the service registration
properties of the ManagedService once a configuration update is made.

Additionally, changed the zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
which is used in the CT to set the zookeeper.host to 127.0.0.1 for the test runs.

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
    cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java?rev=901721&r1=901720&r2=901721&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/Activator.java
Thu Jan 21 14:30:51 2010
@@ -35,9 +35,9 @@
     private static final Logger LOG = Logger.getLogger(Activator.class.getName());
 
     private ZooKeeperDiscovery zkd;
-    private ServiceRegistration cmReg;
     private Dictionary zkProperties;
     private BundleContext bctx;
+    ServiceRegistration cmReg;
 
     public synchronized void start(BundleContext bc) throws Exception {
         bctx = bc;
@@ -45,17 +45,6 @@
         zkd = createZooKeeperDiscovery();
 
         cmReg = bc.registerService(ManagedService.class.getName(), this, zkProperties);
-        
-        LOG.info("Starting Zookeeper Discovery client with default configuration");
-        // Catch connection failures so that the bundle startup ist successful and other
configuration can be
-        // received via ConfigurationAdmin
-        try {
-            zkd.start();
-        } catch (IOException e) {
-            LOG.warning("Startup with default configuration failed: " + e.getLocalizedMessage());
-        } catch (ConfigurationException e) {
-            LOG.warning("Startup with default configuration failed: " + e.getLocalizedMessage());
-        }
     }
 
     public synchronized void stop(BundleContext bc) throws Exception {
@@ -64,7 +53,7 @@
     }
 
     public synchronized void updated(Dictionary configuration) throws ConfigurationException
{
-
+        LOG.info("Received configuration update for Zookeeper Discovery: " + configuration);
         if (configuration == null)
             return;
 
@@ -84,6 +73,7 @@
         }
 
         zkProperties = effective;
+        cmReg.setProperties(zkProperties);
 
         synchronized (this) {
             zkd.stop();
@@ -103,7 +93,6 @@
         Dictionary props = new Hashtable();
         props.put("zookeeper.timeout", "3000");
         props.put("zookeeper.port", "2181");
-        props.put("zookeeper.host", "localhost");
         props.put(Constants.SERVICE_PID, "org.apache.cxf.dosgi.discovery.zookeeper");
         return props;
     }

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java?rev=901721&r1=901720&r2=901721&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/test/java/org/apache/cxf/dosgi/discovery/zookeeper/ActivatorTest.java
Thu Jan 21 14:30:51 2010
@@ -18,24 +18,19 @@
  */
 package org.apache.cxf.dosgi.discovery.zookeeper;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
-import java.io.IOException;
 import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Iterator;
 import java.util.Properties;
 
 import org.easymock.IAnswer;
 import org.easymock.IMocksControl;
 import org.easymock.classextension.EasyMock;
+import org.junit.Test;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 
-import org.junit.Test;
-
 public class ActivatorTest {
 
     @Test
@@ -44,10 +39,6 @@
         IMocksControl c = EasyMock.createNiceControl();
         final ZooKeeperDiscovery z = c.createMock(ZooKeeperDiscovery.class);
 
-        z.start();
-
-        EasyMock.expectLastCall().once();
-
         z.stop();
 
         EasyMock.expectLastCall().once();
@@ -104,7 +95,7 @@
         c.replay();
 
         a.start(bc);
-
+        
         a.updated(null);
 
         c.verify();
@@ -117,7 +108,17 @@
         EasyMock.expectLastCall().once();
         z.start();
         EasyMock.expectLastCall().once();
-        
+
+        ServiceRegistration cmReg = c.createMock(ServiceRegistration.class);        
+        cmReg.setProperties((Dictionary) EasyMock.anyObject());
+        EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+            public Object answer() throws Throwable {
+                Dictionary d = (Dictionary) EasyMock.getCurrentArguments()[0];
+                assertEquals("value", d.get("test"));
+                return null;
+            }
+        }).once();        
+        a.cmReg = cmReg;
         
         c.replay();
         a.updated(d);

Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java?rev=901721&r1=901720&r2=901721&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
Thu Jan 21 14:30:51 2010
@@ -25,6 +25,7 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.cm.ManagedService;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
@@ -38,7 +39,8 @@
                 Object svc = super.addingService(reference);
                 if (svc instanceof ConfigurationAdmin) {
                     try {
-                        Configuration cfg = ((ConfigurationAdmin) svc).getConfiguration(PID,
null);
+                        ConfigurationAdmin cadmin = (ConfigurationAdmin) svc;
+                        Configuration cfg = cadmin.getConfiguration(PID, null);
                         Hashtable<String, Object> props = new Hashtable<String,
Object>();
                         props.put("clientPort", 2181);
                         cfg.update(props);
@@ -51,6 +53,19 @@
             }            
         };
         st.open();
+        
+        // The following section is done synchronously otherwise it doesn't happen in time
for the CT
+        ServiceReference[] refs = context.getServiceReferences(ManagedService.class.getName(),

+                "(service.pid=org.apache.cxf.dosgi.discovery.zookeeper)");
+        if (refs == null || refs.length == 0) {
+            throw new RuntimeException("This bundle must be started after the bundle with
the Zookeeper Discovery Managed Service was started.");
+        }
+        Object svc = context.getService(refs[0]);
+        ManagedService ms = (ManagedService) svc;
+        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        props.put("zookeeper.host", "127.0.0.1");
+        ms.updated(props);
+        System.out.println("Set the zookeeper.host on the Zookeeper Client managed service.");
 	}
     
 	public void stop(BundleContext context) throws Exception {



Mime
View raw message