/** * Wait for service state change callbacks; notify self if the service has * now stopped * @param service service */ @Override public synchronized void stateChanged(Service service) { if (service.isInState(Service.STATE.STOPPED)) { finished.set(true); notify(); } }
/** * Wait for service state change callbacks; notify self if the service has * now stopped * @param service service */ @Override public synchronized void stateChanged(Service service) { if (service.isInState(Service.STATE.STOPPED)) { finished.set(true); notify(); } }
/** * State change event relays service stop events to * {@link #onServiceCompleted(Service)}. Subclasses can * extend that with extra logic * @param service the service that has changed. */ @Override public void stateChanged(Service service) { // only react to the state change when it is the current service // and it has entered the STOPPED state if (service == activeService && service.isInState(STATE.STOPPED)) { onServiceCompleted(service); } }
/** * State change event relays service stop events to * {@link #onServiceCompleted(Service)}. Subclasses can * extend that with extra logic * @param service the service that has changed. */ @Override public void stateChanged(Service service) { // only react to the state change when it is the current service // and it has entered the STOPPED state if (service == activeService && service.isInState(STATE.STOPPED)) { onServiceCompleted(service); } }
/** * Probe to query if all children are stopped -simply * by taking a snapshot of the child service list and enumerating * their state. * The state of the children may change during this operation -that will * not get picked up. * @return true if all the children are stopped. */ private boolean areAllChildrenStopped() { List<Service> children = getServices(); boolean stopped = true; for (Service child : children) { if (!child.isInState(STATE.STOPPED)) { stopped = false; break; } } return stopped; } }
/** * Probe to query if all children are stopped -simply * by taking a snapshot of the child service list and enumerating * their state. * The state of the children may change during this operation -that will * not get picked up. * @return true if all the children are stopped. */ private boolean areAllChildrenStopped() { List<Service> children = getServices(); boolean stopped = true; for (Service child : children) { if (!child.isInState(STATE.STOPPED)) { stopped = false; break; } } return stopped; } }
@Override protected Result check() throws Exception { return service.isInState(Service.STATE.STARTED) ? Result.healthy() : Result.unhealthy("Service is not running: %s", service); } }
@Override protected Result check() throws Exception { return service.isInState(Service.STATE.STARTED) ? Result.healthy() : Result.unhealthy("Service is not running: %s", service); } }
@Override public void stateChanged(Service dependency) { if(LOG.isDebugEnabled()) { LOG.debug("Service dependency: " + dependency.getName() + " notify" + " for service: " + service.getName()); } Throwable dependencyError = dependency.getFailureCause(); if (dependencyError != null) { synchronized(this) { dependenciesFailed = true; if(LOG.isDebugEnabled()) { LOG.debug("Service: " + service.getName() + " will fail to start" + " as dependent service " + dependency.getName() + " failed to start: " + dependencyError); } this.notifyAll(); } } else if (dependency.isInState(Service.STATE.STARTED)) { if(dependenciesStarted.incrementAndGet() == dependencies.size()) { synchronized(this) { if(LOG.isDebugEnabled()) { LOG.debug("Service: " + service.getName() + " notified to start"); } canStart = true; this.notifyAll(); } } } }
void start() throws InterruptedException { if(dependencies.size() > 0) { synchronized(this) { while(!canStart) { this.wait(1000*60*3L); if (dependenciesFailed) { throw new TezUncheckedException("Skipping service start for " + service.getName() + " as dependencies failed to start"); } } } } if(LOG.isDebugEnabled()) { LOG.debug("Service: " + service.getName() + " trying to start"); } for(Service dependency : dependencies) { if(!dependency.isInState(Service.STATE.STARTED)){ LOG.info("Service: " + service.getName() + " not started because " + " service: " + dependency.getName() + " is in state: " + dependency.getServiceState()); return; } } service.start(); } }
/** * When this service is started, any service stopping with a failure * exception is converted immediately into a failure of this service, * storing the failure and stopping ourselves. * @param child the service that has changed. */ @Override public void stateChanged(Service child) { //if that child stopped while we are running: if (isInState(STATE.STARTED) && child.isInState(STATE.STOPPED)) { // a child service has stopped //did the child fail? if so: propagate Throwable failureCause = child.getFailureCause(); if (failureCause != null) { LOG.info("Child service " + child + " failed", failureCause); //failure. Convert to an exception Exception e = (failureCause instanceof Exception) ? (Exception) failureCause : new Exception(failureCause); //flip ourselves into the failed state noteFailure(e); stop(); } else { LOG.info("Child service completed {}", child); if (areAllChildrenStopped()) { LOG.info("All children are halted: stopping"); stop(); } } } }
/** * When this service is started, any service stopping with a failure * exception is converted immediately into a failure of this service, * storing the failure and stopping ourselves. * @param child the service that has changed. */ @Override public void stateChanged(Service child) { //if that child stopped while we are running: if (isInState(STATE.STARTED) && child.isInState(STATE.STOPPED)) { // a child service has stopped //did the child fail? if so: propagate Throwable failureCause = child.getFailureCause(); if (failureCause != null) { LOG.info("Child service " + child + " failed", failureCause); //failure. Convert to an exception Exception e = (failureCause instanceof Exception) ? (Exception) failureCause : new Exception(failureCause); //flip ourselves into the failed state noteFailure(e); stop(); } else { LOG.info("Child service completed {}", child); if (areAllChildrenStopped()) { LOG.info("All children are halted: stopping"); stop(); } } } }
if (service == providerService && service.isInState(STATE.STOPPED)) {
if (service == providerService && service.isInState(STATE.STOPPED)) {
if (!service.isInState(Service.STATE.INITED)) { service.init(configuration);
if (!service.isInState(Service.STATE.INITED)) { service.init(configuration);