/** * 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); } }
/** * 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); } }
/** * Convert any exception into a {@link RuntimeException}. * If the caught exception is already of that type, it is typecast to a * {@link RuntimeException} and returned. * * All other exception types are wrapped in a new instance of * {@code ServiceStateException}. * @param text text to use if a new exception is created * @param fault exception or throwable * @return a {@link RuntimeException} to rethrow */ public static RuntimeException convert(String text, Throwable fault) { if (fault instanceof RuntimeException) { return (RuntimeException) fault; } else { return new ServiceStateException(text, fault); } } }
/** * 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); } }
public void init(Configuration conf) { if (conf == null) { throw new ServiceStateException("Cannot initialize service " + getName() + ": null configuration");
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * Convert any exception into a {@link RuntimeException}. * If the caught exception is already of that type, it is typecast to a * {@link RuntimeException} and returned. * * All other exception types are wrapped in a new instance of * ServiceStateException * @param fault exception or throwable * @return a ServiceStateException to rethrow */ public static RuntimeException convert(Throwable fault) { if (fault instanceof RuntimeException) { return (RuntimeException) fault; } else { return new ServiceStateException(fault); } }
@Override //AbstractService protected void serviceStart() throws Exception { if (process == null) { throw new ServiceStateException("Process not yet configured"); } //now spawn the process -expect updates via callbacks process.start(); }
@Override //AbstractService protected void serviceStart() throws Exception { if (process == null) { throw new ServiceStateException("Process not yet configured"); } //now spawn the process -expect updates via callbacks process.start(); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * Internal check that a service is in the live state * @throws ServiceStateException if not */ private void checkServiceLive() throws ServiceStateException { if (!isInState(STATE.STARTED)) { throw new ServiceStateException( "Service " + getName() + " is in wrong state: " + getServiceState()); } }
/** * Internal check that a service is in the live state. * * @throws ServiceStateException if not */ private void checkServiceLive() throws ServiceStateException { if (!isInState(STATE.STARTED)) { throw new ServiceStateException( "Service " + getName() + " is in wrong state: " + getServiceState()); } }
void finish() { if (fail) { ServiceStateException e = new ServiceStateException(getName() + " failed"); noteFailure(e); stop(); throw e; } else { stop(); } }
void finish() { if (fail) { ServiceStateException e = new ServiceStateException(getName() + " failed"); noteFailure(e); stop(); throw e; } else { stop(); } }