/** * Get the service name via {@link Service#getName()}. * * If the service is not instantiated, the classname is returned instead. * @return the service name */ public String getServiceName() { Service s = service; String name = null; if (s != null) { try { name = s.getName(); } catch (Exception ignored) { // ignored } } if (name != null) { return "service " + name; } else { return "service " + serviceName; } }
/** * Add the passed {@link Service} to the list of services managed by this * {@link CompositeService} * @param service the {@link Service} to be added */ protected void addService(Service service) { if (LOG.isDebugEnabled()) { LOG.debug("Adding service " + service.getName()); } synchronized (serviceList) { serviceList.add(service); } }
/** * Callback for a state change event: log it * @param service the service that has changed. */ @Override public void stateChanged(Service service) { log.info("Entry to state " + service.getServiceState() + " for " + service.getName()); } }
/** * Stop a service; if it is null do nothing. Exceptions are caught and * logged at warn level. (but not Throwables). This operation is intended to * be used in cleanup operations * * @param log the log to warn at * @param service a service; may be null * @return any exception that was caught; null if none was. * @see ServiceOperations#stopQuietly(Service) */ public static Exception stopQuietly(Logger log, Service service) { try { stop(service); } catch (Exception e) { log.warn("When stopping the service {}", service.getName(), e); return e; } return null; }
/** * Stop a service; if it is null do nothing. Exceptions are caught and * logged at warn level. (but not Throwables). This operation is intended to * be used in cleanup operations * * @param log the log to warn at * @param service a service; may be null * @return any exception that was caught; null if none was. * @see ServiceOperations#stopQuietly(Service) */ public static Exception stopQuietly(Log log, Service service) { try { stop(service); } catch (Exception e) { log.warn("When stopping the service " + service.getName(), e); return e; } return null; }
/** * Shutdown operation. * <p> * Subclasses may extend it, but it is primarily * made available for testing. * @return true if the service was stopped and no exception was raised. */ protected boolean shutdown() { Service service; boolean result = false; synchronized (this) { service = serviceRef.get(); serviceRef.clear(); } if (service != null) { try { // Stop the Service service.stop(); result = true; } catch (Throwable t) { LOG.info("Error stopping {}", service.getName(), t); } } return result; } }
/** * Wait for a service; use the service name as this instance's name * @param service service */ public EndOfServiceWaiter(Service service) { this(service.getName(), service); }
/** * Add the passed {@link Service} to the list of services managed by this * {@link WorkflowSequenceService} * @param service the {@link Service} to be added */ @Override public synchronized void addService(Service service) { Preconditions.checkArgument(service != null, "null service argument"); LOG.debug("Adding service {} ", service.getName()); synchronized (serviceList) { serviceList.add(service); } }
/** * Add the passed {@link Service} to the list of services managed by this * {@link CompositeService} * @param service the {@link Service} to be added */ protected void addService(Service service) { if (LOG.isDebugEnabled()) { LOG.debug("Adding service " + service.getName()); } synchronized (serviceList) { serviceList.add(service); } }
/** * Add the passed {@link Service} to the list of services managed by this * {@link WorkflowSequenceService} * @param service the {@link Service} to be added */ @Override public synchronized void addService(Service service) { Preconditions.checkArgument(service != null, "null service argument"); LOG.debug("Adding service {} ", service.getName()); synchronized (serviceList) { serviceList.add(service); } }
/** * Add the passed {@link Service} to the list of services managed by this * {@link CompositeService} * @param service the {@link Service} to be added */ protected void addService(Service service) { if (LOG.isDebugEnabled()) { LOG.debug("Adding service " + service.getName()); } synchronized (serviceList) { serviceList.add(service); } }
/** * Callback for a state change event: log it * @param service the service that has changed. */ @Override public void stateChanged(Service service) { log.info("Entry to state " + service.getServiceState() + " for " + service.getName()); } }
/** * Callback for a state change event: log it * @param service the service that has changed. */ @Override public void stateChanged(Service service) { log.info("Entry to state " + service.getServiceState() + " for " + service.getName()); } }
/** * Callback for a state change event: log it * @param service the service that has changed. */ @Override public void stateChanged(Service service) { log.info("Entry to state " + service.getServiceState() + " for " + service.getName()); } }
@Override public void stateChanged(Service service) { LOG.fatal("Service " + service.getName() + " changed state: " + service.getServiceState()); stop(); }
@Override public void stateChanged(Service service) { LOG.fatal("Service " + service.getName() + " changed state: " + service.getServiceState()); stop(); }
@Override public void stateChanged(Service service) { LOG.fatal("Service " + service.getName() + " changed state: " + service.getServiceState()); stop(); }
@Override public void stateChanged(Service service) { LOG.error("Service " + service.getName() + " changed state: " + service.getServiceState()); stop(); }
/** * Callback for a state change event: log it * @param service the service that has changed. */ @Override public void stateChanged(Service service) { log.info("Entry to state " + service.getServiceState() + " for " + service.getName()); } }
protected void assertInState(Service service, Service.STATE expected) { Service.STATE actual = service.getServiceState(); if (actual != expected) { fail("Service " + service.getName() + " in state " + actual + " -expected " + expected); } }