/** * {@inheritDoc} */ @Override public synchronized void removeEndpoint(QName serviceName, String endpoint) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Removing endpoint " + endpoint + " for service " + serviceName + "..."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); endpointNode.ensureRemoved(); }
/** * {@inheritDoc} */ @Override public synchronized void removeEndpoint(QName serviceName, String endpoint) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Removing endpoint " + endpoint + " for service " + serviceName + "..."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); endpointNode.ensureRemoved(); }
@Override public void updateTimetolive(QName serviceName, String endpoint, int timetolive) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating expiring time to happen in " + timetolive + " seconds on endpoint " + endpoint + " for service " + serviceName + "..."); } if (timetolive < 0) { throw new WrongArgumentException("Time-to-live cannot be negative."); } if (timetolive == 0) { throw new WrongArgumentException("Time-to-live cannot be zero."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { endpointNode.setLive(true); endpointNode.setExpiryTime(new Date(System.currentTimeMillis() + timetolive * 1000), true); } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Unable to update endpoint expiring time for endpoint " + endpoint + " for service " + serviceName + " because it does not exist."); } throw new EndpointNotFoundException("Endpoint " + endpoint + " for service " + serviceName + " does not exist."); } }
@Override public void updateTimetolive(QName serviceName, String endpoint, int timetolive) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Updating expiring time to happen in " + timetolive + " seconds on endpoint " + endpoint + " for service " + serviceName + "..."); } if (timetolive < 0) { throw new WrongArgumentException("Time-to-live cannot be negative."); } if (timetolive == 0) { throw new WrongArgumentException("Time-to-live cannot be zero."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { endpointNode.setLive(true); endpointNode.setExpiryTime(new Date(System.currentTimeMillis() + timetolive * 1000), true); } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Unable to update endpoint expiring time for endpoint " + endpoint + " for service " + serviceName + " because it does not exist."); } throw new EndpointNotFoundException("Endpoint " + endpoint + " for service " + serviceName + " does not exist."); } }
/** * {@inheritDoc} */ @Override public SLEndpoint getEndpoint(final QName serviceName, final String endpoint) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get endpoint information for endpoint " + endpoint + " within service " + serviceName + "..."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] content = endpointNode.getContent(); final boolean isLive = endpointNode.isLive(); return transformer.toSLEndpoint(serviceName, content, isLive); } else { return null; } }
/** * {@inheritDoc} */ @Override public SLEndpoint getEndpoint(final QName serviceName, final String endpoint) throws ServiceLocatorException, InterruptedException { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Get endpoint information for endpoint " + endpoint + " within service " + serviceName + "..."); } RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] content = endpointNode.getContent(); final boolean isLive = endpointNode.isLive(); return transformer.toSLEndpoint(serviceName, content, isLive); } else { return null; } }
@Override public synchronized void unregister(Endpoint epProvider) throws ServiceLocatorException, InterruptedException { QName serviceName = epProvider.getServiceName(); String endpoint = epProvider.getAddress(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Unregistering endpoint " + endpoint + " for service " + serviceName + "..."); } long lastTimeStarted = -1; long lastTimeStopped = System.currentTimeMillis(); RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] oldContent = endpointNode.getContent(); SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, oldContent, false); lastTimeStarted = oldEndpoint.getLastTimeStarted(); endpointNode.setOffline(); byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped); endpointNode.setContent(content); } }
@Override public synchronized void unregister(Endpoint epProvider) throws ServiceLocatorException, InterruptedException { QName serviceName = epProvider.getServiceName(); String endpoint = epProvider.getAddress(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Unregistering endpoint " + endpoint + " for service " + serviceName + "..."); } long lastTimeStarted = -1; long lastTimeStopped = System.currentTimeMillis(); RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] oldContent = endpointNode.getContent(); SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, oldContent, false); lastTimeStarted = oldEndpoint.getLastTimeStarted(); endpointNode.setOffline(); byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped); endpointNode.setContent(content); } }
@Override public synchronized void register(Endpoint epProvider, boolean persistent) throws ServiceLocatorException, InterruptedException { QName serviceName = epProvider.getServiceName(); String endpoint = epProvider.getAddress(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Registering endpoint " + endpoint + " for service " + serviceName + "..."); } long lastTimeStarted = System.currentTimeMillis(); long lastTimeStopped = -1; RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); serviceNode.ensureExists(); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] content = endpointNode.getContent(); SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, content, false); lastTimeStopped = oldEndpoint.getLastTimeStopped(); } byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped); endpointNode.ensureExists(content); endpointNode.setLive(persistent); }
@Override public synchronized void register(Endpoint epProvider, boolean persistent) throws ServiceLocatorException, InterruptedException { QName serviceName = epProvider.getServiceName(); String endpoint = epProvider.getAddress(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Registering endpoint " + endpoint + " for service " + serviceName + "..."); } long lastTimeStarted = System.currentTimeMillis(); long lastTimeStopped = -1; RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); serviceNode.ensureExists(); EndpointNode endpointNode = serviceNode.getEndPoint(endpoint); if (endpointNode.exists()) { byte[] content = endpointNode.getContent(); SLEndpoint oldEndpoint = transformer.toSLEndpoint(serviceName, content, false); lastTimeStopped = oldEndpoint.getLastTimeStopped(); } byte[] content = createContent(epProvider, lastTimeStarted, lastTimeStopped); endpointNode.ensureExists(content); endpointNode.setLive(persistent); }