@Test public void testRemoveChangeListener() throws Exception { ServerSet.ChangeListener listener1 = mock(ServerSet.ChangeListener.class); ServerSet.ChangeListener listener2 = mock(ServerSet.ChangeListener.class); ServerSet.ChangeListener listener3 = mock(ServerSet.ChangeListener.class); ServerSet.ChangeListener listener4 = mock(ServerSet.ChangeListener.class); ZookeeperServerSet set = new ZookeeperServerSet(mockChildrenCacheFactory, zkClient, serviceReader, "foo", true); ZookeeperServerSet hostSet = new ZookeeperServerSet(mockChildrenCacheFactory, zkClient, hostReader, "foo", true); CuratorFramework mockZk = mock(CuratorFramework.class); set.addChangeListener(listener1); set.addChangeListener(listener2); hostSet.addChangeListener(listener3); hostSet.addChangeListener(listener4); InetSocketAddress server = new InetSocketAddress("192.168.1.1", 256); set.childEvent(mockZk, childAddedEvent("/services/foo/node-1", data(server))); set.removeChangeListener(listener1); set.childEvent(mockZk, childRemovedEvent("/services/foo/node-1", data(server))); hostSet.childEvent(mockZk, childAddedEvent("/hosts/node-1", data(getHostConfig("node-1", server)))); hostSet.removeChangeListener(listener3); hostSet.childEvent(mockZk, childRemovedEvent("/hosts/node-1", data(getHostConfig("node-1", server)))); verify(listener1).onServerAdded(server); verify(listener3).onServerAdded(server); verify(listener2).onServerAdded(server); verify(listener4).onServerAdded(server); verify(listener2).onServerRemoved(server); verify(listener4).onServerRemoved(server); verifyNoMoreInteractions(listener1, listener2, listener3, listener4); set.close(); hostSet.close(); }
@Override public synchronized void removeChangeListener(ChangeListener listener) { listeners.remove(listener); }
ZookeeperServerSet implements ServerSet, PathChildrenCacheListener { @Override public synchronized void removeChangeListener(ChangeListener listener) { listeners.remove(listener); } }
ZookeeperServerSet implements ServerSet, PathChildrenCacheListener { @Override public synchronized void removeChangeListener(ChangeListener listener) { listeners.remove(listener); } @AssistedInject  ZookeeperServerSet(@ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                            CuratorFramework zkClient,
                            @ServiceReader ZookeeperServerReader reader,
                            @Assisted("serviceName") String serviceName,
                            @Assisted boolean subscribeToUpdates); }
ZookeeperServerSet implements ServerSet, PathChildrenCacheListener { @Override public synchronized void removeChangeListener(ChangeListener listener) { listeners.remove(listener); } @AssistedInject  ZookeeperServerSet(@ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                            CuratorFramework zkClient,
                            @ServiceReader ZookeeperServerReader reader,
                            @Assisted("serviceName") String serviceName,
                            @Assisted boolean subscribeToUpdates); @Override synchronized void addChangeListener(ChangeListener listener); @Override synchronized void removeChangeListener(ChangeListener listener); @Override void close(); @Override synchronized void childEvent(CuratorFramework client, PathChildrenCacheEvent event); @Override String toString(); @Override Set<InetSocketAddress> getServers(); }
ZookeeperServerSet implements ServerSet, PathChildrenCacheListener { @Override public synchronized void removeChangeListener(ChangeListener listener) { listeners.remove(listener); } @AssistedInject  ZookeeperServerSet(@ServicePathCacheFactory PathChildrenCacheFactory childrenCacheFactory,
                            CuratorFramework zkClient,
                            @ServiceReader ZookeeperServerReader reader,
                            @Assisted("serviceName") String serviceName,
                            @Assisted boolean subscribeToUpdates); @Override synchronized void addChangeListener(ChangeListener listener); @Override synchronized void removeChangeListener(ChangeListener listener); @Override void close(); @Override synchronized void childEvent(CuratorFramework client, PathChildrenCacheEvent event); @Override String toString(); @Override Set<InetSocketAddress> getServers();  }