/** * {@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 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 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 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); }
if (endpointNode.isLive()) { byte[] content = endpointNode.getContent(); SLEndpoint endpoint = transformer.toSLEndpoint(serviceName, content, true); SLProperties props = endpoint.getProperties(); liveEndpoints.add(endpointNode.getEndpointName()); if (LOG.isLoggable(Level.FINE)) LOG.fine("matched = " + endpointNode.getEndpointName()); } else if (LOG.isLoggable(Level.FINE)) LOG.fine("not matched = " + endpointNode.getEndpointName());
/** * {@inheritDoc} */ @Override synchronized public List<SLEndpoint> getEndpoints(final QName serviceName) throws ServiceLocatorException, InterruptedException { RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); if (serviceNode.exists()) { List<EndpointNode> endpointNodes = serviceNode.getEndPoints(); List<SLEndpoint> slEndpoints = new ArrayList<SLEndpoint>(endpointNodes.size()); for (EndpointNode endpointNode : endpointNodes) { byte[] content = endpointNode.getContent(); final boolean isLive = endpointNode.isLive(); SLEndpoint slEndpoint = transformer.toSLEndpoint(serviceName, content, isLive); slEndpoints.add(slEndpoint); } return slEndpoints; } else { return Collections.emptyList(); } }
@Override public synchronized void performCollection() { LOG.fine("Performing expired endpoint collection."); Date now = new Date(); try { RootNode root = getBackend().connect(); List<QName> svcs = root.getServiceNames(); for (QName svc : svcs) { ServiceNode svcNode = root.getServiceNode(svc); List<EndpointNode> epts = svcNode.getEndPoints(); for (EndpointNode ept : epts) { Date expTime = ept.getExpiryTime(); if (expTime != null && expTime.before(now)) { unregisterEndpoint(svc, ept.getEndpointName()); } } } } catch (Exception e) { throw new RuntimeException(e); } }
@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); }
if (endpointNode.isLive()) { byte[] content = endpointNode.getContent(); SLEndpoint endpoint = transformer.toSLEndpoint(serviceName, content, true); SLProperties props = endpoint.getProperties(); liveEndpoints.add(endpointNode.getEndpointName()); if (LOG.isLoggable(Level.FINE)) LOG.fine("matched = " + endpointNode.getEndpointName()); } else if (LOG.isLoggable(Level.FINE)) LOG.fine("not matched = " + endpointNode.getEndpointName());
/** * {@inheritDoc} */ @Override synchronized public List<SLEndpoint> getEndpoints(final QName serviceName) throws ServiceLocatorException, InterruptedException { RootNode rootNode = getBackend().connect(); ServiceNode serviceNode = rootNode.getServiceNode(serviceName); if (serviceNode.exists()) { List<EndpointNode> endpointNodes = serviceNode.getEndPoints(); List<SLEndpoint> slEndpoints = new ArrayList<SLEndpoint>(endpointNodes.size()); for (EndpointNode endpointNode : endpointNodes) { byte[] content = endpointNode.getContent(); final boolean isLive = endpointNode.isLive(); SLEndpoint slEndpoint = transformer.toSLEndpoint(serviceName, content, isLive); slEndpoints.add(slEndpoint); } return slEndpoints; } else { return Collections.emptyList(); } }
@Override public synchronized void performCollection() { LOG.fine("Performing expired endpoint collection."); Date now = new Date(); try { RootNode root = getBackend().connect(); List<QName> svcs = root.getServiceNames(); for (QName svc : svcs) { ServiceNode svcNode = root.getServiceNode(svc); List<EndpointNode> epts = svcNode.getEndPoints(); for (EndpointNode ept : epts) { Date expTime = ept.getExpiryTime(); if (expTime != null && expTime.before(now)) { unregisterEndpoint(svc, ept.getEndpointName()); } } } } catch (Exception e) { throw new RuntimeException(e); } }
/** * {@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 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 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(); }