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(); }
@Override public void stateChanged(Service dependency) { if (LOG.isDebugEnabled()) { LOG.debug( "Service dependency: " + dependency.getName() + " notify" + " for service: " + service.getName()); } 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(); } } } else if (!service.isInState(Service.STATE.STARTED) && dependency.getFailureState() != 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"); } this.notifyAll(); } } }