Repository: aries-rsa Updated Branches: refs/heads/master 886a8289e -> ba7a6a047
[ARIES-1763] Change zookeeper discovery to EndpointEventListener Project: http://git-wip-us.apache.org/repos/asf/aries-rsa/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-rsa/commit/835b8d7a Tree: http://git-wip-us.apache.org/repos/asf/aries-rsa/tree/835b8d7a Diff: http://git-wip-us.apache.org/repos/asf/aries-rsa/diff/835b8d7a Branch: refs/heads/master Commit: 835b8d7a082b2cfa9b53b6337bbc0afb928d61fa Parents: 886a828 Author: Christian Schneider <[email protected]> Authored: Thu Feb 1 17:48:48 2018 +0100 Committer: Christian Schneider <[email protected]> Committed: Thu Feb 1 17:48:48 2018 +0100 ---------------------------------------------------------------------- discovery/zookeeper/pom.xml | 2 -- .../publish/PublishingEndpointListener.java | 26 +++++++++++++++++--- .../PublishingEndpointListenerFactory.java | 6 ++--- .../PublishingEndpointListenerFactoryTest.java | 14 +++++------ .../publish/PublishingEndpointListenerTest.java | 13 +++++----- 5 files changed, 38 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/835b8d7a/discovery/zookeeper/pom.xml ---------------------------------------------------------------------- diff --git a/discovery/zookeeper/pom.xml b/discovery/zookeeper/pom.xml index d739c25..655b86a 100644 --- a/discovery/zookeeper/pom.xml +++ b/discovery/zookeeper/pom.xml @@ -76,13 +76,11 @@ </exclusion> </exclusions> </dependency> - <dependency> <groupId>org.apache.aries.rsa.discovery</groupId> <artifactId>org.apache.aries.rsa.discovery.local</artifactId> <version>${project.version}</version> </dependency> - </dependencies> </project> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/835b8d7a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java ---------------------------------------------------------------------- diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java index 188c08f..82387ba 100644 --- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java +++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListener.java @@ -40,7 +40,8 @@ import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooKeeper; import org.osgi.framework.BundleContext; import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.EndpointListener; +import org.osgi.service.remoteserviceadmin.EndpointEvent; +import org.osgi.service.remoteserviceadmin.EndpointEventListener; import org.osgi.util.tracker.ServiceTracker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory; /** * Listens for local Endpoints and publishes them to ZooKeeper. */ -public class PublishingEndpointListener implements EndpointListener { +public class PublishingEndpointListener implements EndpointEventListener { private static final Logger LOG = LoggerFactory.getLogger(PublishingEndpointListener.class); @@ -67,7 +68,24 @@ public class PublishingEndpointListener implements EndpointListener { endpointDescriptionParser = new EndpointDescriptionParser(); } - public void endpointAdded(EndpointDescription endpoint, String matchedFilter) { + @Override + public void endpointChanged(EndpointEvent event, String filter) { + EndpointDescription endpoint = event.getEndpoint(); + switch (event.getType()) { + case EndpointEvent.ADDED: + endpointAdded(endpoint, filter); + break; + case EndpointEvent.REMOVED: + endpointRemoved(endpoint, filter); + break; + case EndpointEvent.MODIFIED: + endpointRemoved(endpoint, filter); + endpointAdded(endpoint, filter); + break; + } + } + + private void endpointAdded(EndpointDescription endpoint, String matchedFilter) { synchronized (endpoints) { if (closed) { return; @@ -135,7 +153,7 @@ public class PublishingEndpointListener implements EndpointListener { } } - public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) { + private void endpointRemoved(EndpointDescription endpoint, String matchedFilter) { LOG.info("Local EndpointDescription removed: {}", endpoint); synchronized (endpoints) { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/835b8d7a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java ---------------------------------------------------------------------- diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java index e4ce7b6..8a40b92 100644 --- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java +++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactory.java @@ -30,7 +30,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; import org.osgi.framework.ServiceFactory; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.remoteserviceadmin.EndpointListener; +import org.osgi.service.remoteserviceadmin.EndpointEventListener; import org.osgi.service.remoteserviceadmin.RemoteConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,11 +74,11 @@ public class PublishingEndpointListenerFactory implements ServiceFactory<Publish public synchronized void start() { Dictionary<String, String> props = new Hashtable<String, String>(); String uuid = bctx.getProperty(Constants.FRAMEWORK_UUID); - props.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, + props.put(EndpointEventListener.ENDPOINT_LISTENER_SCOPE, String.format("(&(%s=*)(%s=%s))", Constants.OBJECTCLASS, RemoteConstants.ENDPOINT_FRAMEWORK_UUID, uuid)); props.put(ZooKeeperDiscovery.DISCOVERY_ZOOKEEPER_ID, "true"); - serviceRegistration = bctx.registerService(EndpointListener.class.getName(), this, props); + serviceRegistration = bctx.registerService(EndpointEventListener.class.getName(), this, props); } public synchronized void stop() { http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/835b8d7a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactoryTest.java ---------------------------------------------------------------------- diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactoryTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactoryTest.java index 0cbe7ca..777c11c 100644 --- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactoryTest.java +++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerFactoryTest.java @@ -21,16 +21,14 @@ package org.apache.aries.rsa.discovery.zookeeper.publish; import java.util.Dictionary; import java.util.List; -import junit.framework.TestCase; - -import org.apache.aries.rsa.discovery.zookeeper.publish.PublishingEndpointListener; -import org.apache.aries.rsa.discovery.zookeeper.publish.PublishingEndpointListenerFactory; import org.apache.zookeeper.ZooKeeper; import org.easymock.EasyMock; import org.easymock.IMocksControl; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; -import org.osgi.service.remoteserviceadmin.EndpointListener; +import org.osgi.service.remoteserviceadmin.EndpointEventListener; + +import junit.framework.TestCase; public class PublishingEndpointListenerFactoryTest extends TestCase { @@ -45,7 +43,7 @@ public class PublishingEndpointListenerFactoryTest extends TestCase { PublishingEndpointListenerFactory eplf = new PublishingEndpointListenerFactory(zk, ctx); - EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointListener.class.getName()), EasyMock.eq(eplf), + EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointEventListener.class.getName()), EasyMock.eq(eplf), (Dictionary<String, String>)EasyMock.anyObject())).andReturn(sreg).once(); EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID").anyTimes(); @@ -67,7 +65,7 @@ public class PublishingEndpointListenerFactoryTest extends TestCase { PublishingEndpointListenerFactory eplf = new PublishingEndpointListenerFactory(zk, ctx); - EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointListener.class.getName()), EasyMock.eq(eplf), + EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointEventListener.class.getName()), EasyMock.eq(eplf), (Dictionary<String, String>)EasyMock.anyObject())).andReturn(sreg).once(); EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID").anyTimes(); @@ -81,7 +79,7 @@ public class PublishingEndpointListenerFactoryTest extends TestCase { PublishingEndpointListener service = eplf.getService(null, null); assertNotNull(service); - assertTrue(service instanceof EndpointListener); + assertTrue(service instanceof EndpointEventListener); List<PublishingEndpointListener> listeners = eplf.getListeners(); assertEquals(1, listeners.size()); http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/835b8d7a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java ---------------------------------------------------------------------- diff --git a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java index 919a74d..fcdc9f7 100644 --- a/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java +++ b/discovery/zookeeper/src/test/java/org/apache/aries/rsa/discovery/zookeeper/publish/PublishingEndpointListenerTest.java @@ -42,6 +42,7 @@ import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.service.remoteserviceadmin.EndpointDescription; +import org.osgi.service.remoteserviceadmin.EndpointEvent; import org.osgi.service.remoteserviceadmin.RemoteConstants; import junit.framework.TestCase; @@ -64,10 +65,10 @@ public class PublishingEndpointListenerTest extends TestCase { PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx); EndpointDescription endpoint = createEndpoint(); - eli.endpointAdded(endpoint, null); - eli.endpointAdded(endpoint, null); // should do nothing - eli.endpointRemoved(endpoint, null); - eli.endpointRemoved(endpoint, null); // should do nothing + eli.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint), null); + eli.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint), null); // should do nothing + eli.endpointChanged(new EndpointEvent(EndpointEvent.REMOVED, endpoint), null); + eli.endpointChanged(new EndpointEvent(EndpointEvent.REMOVED, endpoint), null); // should do nothing c.verify(); } @@ -106,7 +107,7 @@ public class PublishingEndpointListenerTest extends TestCase { List<EndpointDescription> endpoints = getEndpoints(eli); assertEquals("Precondition", 0, endpoints.size()); - eli.endpointAdded(endpoint, null); + eli.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint), null); assertEquals(1, endpoints.size()); //TODO enable @@ -126,7 +127,7 @@ public class PublishingEndpointListenerTest extends TestCase { PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx); EndpointDescription endpoint = createEndpoint(); - eli.endpointAdded(endpoint, null); + eli.endpointChanged(new EndpointEvent(EndpointEvent.ADDED, endpoint), null); eli.close(); // should result in zk.delete(...) c.verify();
