@Override protected void serviceStop() throws Exception { super.serviceStop(); }
/** * 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 service a service; may be null * @return any exception that was caught; null if none was. */ public static Exception stopQuietly(Service service) { return stopQuietly(LOG, service); }
/** * Relay to {@link #stop()} * @throws IOException */ @Override public final void close() throws IOException { stop(); }
protected void serviceInit(Configuration conf) throws Exception { List<Service> services = getServices(); if (LOG.isDebugEnabled()) { LOG.debug(getName() + ": initing services, size=" + services.size()); } for (Service service : services) { service.init(conf); } super.serviceInit(conf); }
protected void serviceStart() throws Exception { List<Service> services = getServices(); if (LOG.isDebugEnabled()) { LOG.debug(getName() + ": starting services, size=" + services.size()); } for (Service service : services) { // start the service. If this fails that service // will be stopped and an exception raised service.start(); } super.serviceStart(); }
@Override protected void serviceInit(Configuration conf) throws Exception { super.serviceInit(conf); }
public void serviceInit(Configuration conf) throws Exception { super.serviceInit(conf); }
/** * Check that a state tansition is valid and * throw an exception if not * @param name name of the service (can be null) * @param state current state * @param proposed proposed new state */ public static void checkStateTransition(String name, Service.STATE state, Service.STATE proposed) { if (!isValidStateTransition(state, proposed)) { throw new ServiceStateException(name + " cannot enter state " + proposed + " from state " + state); } }
/** * If the passed object is an instance of {@link Service}, * add it to the list of services managed by this {@link CompositeService} * @param object * @return true if a service is added, false otherwise. */ protected boolean addIfService(Object object) { if (object instanceof Service) { addService((Service) object); return true; } else { return false; } }
/** * Convert any exception into a {@link RuntimeException}. * All other exception types are wrapped in a new instance of * {@code ServiceStateException}. * @param fault exception or throwable * @return a {@link RuntimeException} to rethrow */ public static RuntimeException convert(Throwable fault) { if (fault instanceof RuntimeException) { return (RuntimeException) fault; } else { return new ServiceStateException(fault); } }
/** * Query that the state is in a specific state * @param proposed proposed new state * @return the state */ public boolean isInState(Service.STATE proposed) { return state.equals(proposed); }
/** * Register a global listener, which receives notifications * from the state change events of all services in the JVM * @param l listener */ public static void registerGlobalListener(ServiceStateChangeListener l) { globalListeners.add(l); }
/** * unregister a global listener. * @param l listener to unregister * @return true if the listener was found (and then deleted) */ public static boolean unregisterGlobalListener(ServiceStateChangeListener l) { return globalListeners.remove(l); }
/** * Construct the service. * @param name service name */ public AbstractService(String name) { this.name = name; stateModel = new ServiceStateModel(name); }
@Override public final STATE getServiceState() { return stateModel.getState(); }
@Override public final boolean isInState(Service.STATE expected) { return stateModel.isInState(expected); }
@Override public void run() { ServiceOperations.stopQuietly(compositeService); } }
/** * Verify that that a service is in a given state. * @param expectedState the desired state * @throws ServiceStateException if the service state is different from * the desired state */ public void ensureCurrentState(Service.STATE expectedState) { if (state != expectedState) { throw new ServiceStateException(name+ ": for this operation, the " + "current service state must be " + expectedState + " instead of " + state); } }
@Override public void registerServiceListener(ServiceStateChangeListener l) { listeners.add(l); }
@Override public void unregisterServiceListener(ServiceStateChangeListener l) { listeners.remove(l); }