class 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");
        }
        // Create unique coordinate; the coordinate is just a random number.
        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;
    }

    public  CloudnameService(final CloudnameBackend backend);

}