@Test(expected = IllegalArgumentException.class) public void serviceCannotBeNullWhenRegister() { new CloudnameService(memoryBackend).registerService(null, null); }
public ServiceHandle registerService( final ServiceCoordinate serviceCoordinate, final ServiceData serviceData) { if (serviceCoordinate == null) { throw new IllegalArgumentException("Coordinate cannot be null"); } if (serviceData == null) { throw new IllegalArgumentException("Service Data cannot be null"); } int numRetries = 0; LeaseHandle leaseHandle = null; while (numRetries < MAX_COORDINATE_RETRIES && leaseHandle == null) { final CloudnamePath newCoordinate = new CloudnamePath( serviceCoordinate.toCloudnamePath(), Long.toHexString(random.nextLong())); leaseHandle = backend.createLease(LeaseType.TEMPORARY, newCoordinate, serviceData.toJsonString()); numRetries++; } if (numRetries == MAX_COORDINATE_RETRIES && leaseHandle == null) { LOG.severe("Could not find available coordinate after " + MAX_COORDINATE_RETRIES + " for service " + serviceCoordinate); return null; } final ServiceHandle serviceHandle = new ServiceHandle( new InstanceCoordinate(leaseHandle.getLeasePath()), serviceData, leaseHandle); synchronized (syncObject) { handles.add(serviceHandle); } return serviceHandle; }
CloudnameService implements AutoCloseable { public ServiceHandle registerService( final ServiceCoordinate serviceCoordinate, final ServiceData serviceData) { if (serviceCoordinate == null) { throw new IllegalArgumentException("Coordinate cannot be null"); } if (serviceData == null) { throw new IllegalArgumentException("Service Data cannot be null"); } int numRetries = 0; LeaseHandle leaseHandle = null; while (numRetries < MAX_COORDINATE_RETRIES && leaseHandle == null) { final CloudnamePath newCoordinate = new CloudnamePath( serviceCoordinate.toCloudnamePath(), Long.toHexString(random.nextLong())); leaseHandle = backend.createLease(LeaseType.TEMPORARY, newCoordinate, serviceData.toJsonString()); numRetries++; } if (numRetries == MAX_COORDINATE_RETRIES && leaseHandle == null) { LOG.severe("Could not find available coordinate after " + MAX_COORDINATE_RETRIES + " for service " + serviceCoordinate); return null; } final ServiceHandle serviceHandle = new ServiceHandle( new InstanceCoordinate(leaseHandle.getLeasePath()), serviceData, leaseHandle); synchronized (syncObject) { handles.add(serviceHandle); } return serviceHandle; } }
CloudnameService implements AutoCloseable { public ServiceHandle registerService( final ServiceCoordinate serviceCoordinate, final ServiceData serviceData) { if (serviceCoordinate == null) { throw new IllegalArgumentException("Coordinate cannot be null"); } if (serviceData == null) { throw new IllegalArgumentException("Service Data cannot be null"); } int numRetries = 0; LeaseHandle leaseHandle = null; while (numRetries < MAX_COORDINATE_RETRIES && leaseHandle == null) { final CloudnamePath newCoordinate = new CloudnamePath( serviceCoordinate.toCloudnamePath(), Long.toHexString(random.nextLong())); leaseHandle = backend.createLease(LeaseType.TEMPORARY, newCoordinate, serviceData.toJsonString()); numRetries++; } if (numRetries == MAX_COORDINATE_RETRIES && leaseHandle == null) { LOG.severe("Could not find available coordinate after " + MAX_COORDINATE_RETRIES + " for service " + serviceCoordinate); return null; } final ServiceHandle serviceHandle = new ServiceHandle( new InstanceCoordinate(leaseHandle.getLeasePath()), serviceData, leaseHandle); synchronized (syncObject) { handles.add(serviceHandle); } return serviceHandle; } CloudnameService(final CloudnameBackend backend); }
CloudnameService implements AutoCloseable { public ServiceHandle registerService( final ServiceCoordinate serviceCoordinate, final ServiceData serviceData) { if (serviceCoordinate == null) { throw new IllegalArgumentException("Coordinate cannot be null"); } if (serviceData == null) { throw new IllegalArgumentException("Service Data cannot be null"); } int numRetries = 0; LeaseHandle leaseHandle = null; while (numRetries < MAX_COORDINATE_RETRIES && leaseHandle == null) { final CloudnamePath newCoordinate = new CloudnamePath( serviceCoordinate.toCloudnamePath(), Long.toHexString(random.nextLong())); leaseHandle = backend.createLease(LeaseType.TEMPORARY, newCoordinate, serviceData.toJsonString()); numRetries++; } if (numRetries == MAX_COORDINATE_RETRIES && leaseHandle == null) { LOG.severe("Could not find available coordinate after " + MAX_COORDINATE_RETRIES + " for service " + serviceCoordinate); return null; } final ServiceHandle serviceHandle = new ServiceHandle( new InstanceCoordinate(leaseHandle.getLeasePath()), serviceData, leaseHandle); synchronized (syncObject) { handles.add(serviceHandle); } return serviceHandle; } 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(); }
CloudnameService implements AutoCloseable { public ServiceHandle registerService( final ServiceCoordinate serviceCoordinate, final ServiceData serviceData) { if (serviceCoordinate == null) { throw new IllegalArgumentException("Coordinate cannot be null"); } if (serviceData == null) { throw new IllegalArgumentException("Service Data cannot be null"); } int numRetries = 0; LeaseHandle leaseHandle = null; while (numRetries < MAX_COORDINATE_RETRIES && leaseHandle == null) { final CloudnamePath newCoordinate = new CloudnamePath( serviceCoordinate.toCloudnamePath(), Long.toHexString(random.nextLong())); leaseHandle = backend.createLease(LeaseType.TEMPORARY, newCoordinate, serviceData.toJsonString()); numRetries++; } if (numRetries == MAX_COORDINATE_RETRIES && leaseHandle == null) { LOG.severe("Could not find available coordinate after " + MAX_COORDINATE_RETRIES + " for service " + serviceCoordinate); return null; } final ServiceHandle serviceHandle = new ServiceHandle( new InstanceCoordinate(leaseHandle.getLeasePath()), serviceData, leaseHandle); synchronized (syncObject) { handles.add(serviceHandle); } return serviceHandle; } 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();  }