/** * Start a service. * <p/> * The service state is checked <i>before</i> the operation begins. * This process is <i>not</i> thread safe. * @param service a service that must be in the state * {@link Service.STATE#INITED} * @throws RuntimeException on a state change failure * @throws IllegalStateException if the service is in the wrong state */ public static void start(Service service) { Service.STATE state = service.getServiceState(); ensureCurrentState(state, Service.STATE.INITED); service.start(); }
@Override public HiveConf getHiveConf() { return service.getHiveConf(); }
/** * Stop a service. * <p/>Do nothing if the service is null or not * in a state in which it can be/needs to be stopped. * <p/> * The service state is checked <i>before</i> the operation begins. * This process is <i>not</i> thread safe. * @param service a service or null */ public static void stop(Service service) { if (service != null) { Service.STATE state = service.getServiceState(); if (state == Service.STATE.STARTED) { service.stop(); } } }
/** * Initialize a service. * <p/> * The service state is checked <i>before</i> the operation begins. * This process is <i>not</i> thread safe. * @param service a service that must be in the state * {@link Service.STATE#NOTINITED} * @param configuration the configuration to initialize the service with * @throws RuntimeException on a state change failure * @throws IllegalStateException if the service is in the wrong state */ public static void init(Service service, HiveConf configuration) { Service.STATE state = service.getServiceState(); ensureCurrentState(state, Service.STATE.NOTINITED); service.init(configuration); }
@Override public String getName() { return service.getName(); }
@Override public void init(HiveConf config) { service.init(config); }
@Override public void start() { service.start(); }
@Override public STATE getServiceState() { return service.getServiceState(); }
@Override public void unregister(ServiceStateChangeListener listener) { service.unregister(listener); }
@Override public void register(ServiceStateChangeListener listener) { service.register(listener); }
@Override public void stop() { service.stop(); }
/** * Initialize a service. * <p/> * The service state is checked <i>before</i> the operation begins. * This process is <i>not</i> thread safe. * @param service a service that must be in the state * {@link Service.STATE#NOTINITED} * @param configuration the configuration to initialize the service with * @throws RuntimeException on a state change failure * @throws IllegalStateException if the service is in the wrong state */ public static void init(Service service, HiveConf configuration) { Service.STATE state = service.getServiceState(); ensureCurrentState(state, Service.STATE.NOTINITED); service.init(configuration); }
/** * Stop a service. * <p/>Do nothing if the service is null or not * in a state in which it can be/needs to be stopped. * <p/> * The service state is checked <i>before</i> the operation begins. * This process is <i>not</i> thread safe. * @param service a service or null */ public static void stop(Service service) { if (service != null) { Service.STATE state = service.getServiceState(); if (state == Service.STATE.STARTED) { service.stop(); } } }
/** * 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) { try { stop(service); } catch (Exception e) { LOG.warn("When stopping the service " + service.getName() + " : " + e, e); return e; } return null; }
@Override public synchronized void init(HiveConf hiveConf) { for (Service service : serviceList) { service.init(hiveConf); } super.init(hiveConf); }
@Override public synchronized void start() { int i = 0; try { for (int n = serviceList.size(); i < n; i++) { Service service = serviceList.get(i); service.start(); } super.start(); } catch (Throwable e) { LOG.error("Error starting services " + getName(), e); // Note that the state of the failed service is still INITED and not // STARTED. Even though the last service is not started completely, still // call stop() on all services including failed service to make sure cleanup // happens. stop(i); throw new ServiceException("Failed to Start " + getName(), e); } }
@Override public STATE getServiceState() { return service.getServiceState(); }
@Override public void unregister(ServiceStateChangeListener listener) { service.unregister(listener); }
@Override public void register(ServiceStateChangeListener listener) { service.register(listener); }