CloudnameService implements AutoCloseable { public void addServiceListener( final ServiceCoordinate coordinate, final ServiceListener listener) { if (coordinate == null) { throw new IllegalArgumentException("Coordinate can not be null"); } if (listener == null) { throw new IllegalArgumentException("Listener can not be null"); } final LeaseListener leaseListener = new LeaseListener() { @Override public void leaseCreated(final CloudnamePath path, final String data) { final InstanceCoordinate instanceCoordinate = new InstanceCoordinate(path); final ServiceData serviceData = ServiceData.fromJsonString(data); listener.onServiceCreated(instanceCoordinate, serviceData); } @Override public void leaseRemoved(final CloudnamePath path) { final InstanceCoordinate instanceCoordinate = new InstanceCoordinate(path); listener.onServiceRemoved(instanceCoordinate); } @Override public void dataChanged(final CloudnamePath path, final String data) { final InstanceCoordinate instanceCoordinate = new InstanceCoordinate(path); final ServiceData serviceData = ServiceData.fromJsonString(data); listener.onServiceDataChanged(instanceCoordinate, serviceData); } }; synchronized (syncObject) { temporaryListeners.add(leaseListener); } backend.addLeaseCollectionListener(coordinate.toCloudnamePath(), leaseListener); } CloudnameService(final CloudnameBackend backend); ServiceHandle registerService(
            final ServiceCoordinate serviceCoordinate, final ServiceData serviceData); void addServiceListener(
            final ServiceCoordinate coordinate, final ServiceListener listener); boolean createPermanentService(
            final ServiceCoordinate coordinate, final Endpoint endpoint); boolean updatePermanentService(
            final ServiceCoordinate coordinate, final Endpoint endpoint); boolean removePermanentService(final ServiceCoordinate coordinate); void addPermanentServiceListener(
            final ServiceCoordinate coordinate, final PermanentServiceListener listener); @Override void close();  }
@Test(expected = IllegalArgumentException.class) public void coordinateCanNotBeNullWhenAddingListener() { new CloudnameService(memoryBackend).addServiceListener(null, null); }
@Test(expected = IllegalArgumentException.class) public void listenerCanNotBeNullWhenAddingListener() { new CloudnameService(memoryBackend).addServiceListener(coordinate, null); }