List of usage examples for org.apache.hadoop.service ServiceOperations stopQuietly
public static Exception stopQuietly(Logger log, Service service)
From source file:MRAppMaster.CompositeService.java
License:Apache License
/** * Stop the services in reverse order/*ww w . j a va 2s . c o m*/ * * @param numOfServicesStarted index from where the stop should work * @param stopOnlyStartedServices flag to say "only start services that are * started, not those that are NOTINITED or INITED. * @throws RuntimeException the first exception raised during the * stop process -<i>after all services are stopped</i> */ private void stop(int numOfServicesStarted, boolean stopOnlyStartedServices) { // stop in reverse order of start Exception firstException = null; List<Service> services = getServices(); for (int i = numOfServicesStarted - 1; i >= 0; i--) { Service service = services.get(i); if (LOG.isDebugEnabled()) { LOG.debug("Stopping service #" + i + ": " + service); } STATE state = service.getServiceState(); //depending on the stop police if (state == STATE.STARTED || (!stopOnlyStartedServices && state == STATE.INITED)) { Exception ex = ServiceOperations.stopQuietly(LOG, service); if (ex != null && firstException == null) { firstException = ex; } } } //after stopping all services, rethrow the first exception raised if (firstException != null) { throw ServiceStateException.convert(firstException); } }
From source file:org.apache.tez.dag.app.DAGAppMaster.java
License:Apache License
void stopServices() { // stop in reverse order of start List<Service> serviceList = new ArrayList<Service>(services.size()); for (ServiceWithDependency sd : services.values()) { serviceList.add(sd.service);/*from ww w. jav a 2s . c o m*/ } Exception firstException = null; for (int i = services.size() - 1; i >= 0; i--) { Service service = serviceList.get(i); if (LOG.isDebugEnabled()) { LOG.debug("Stopping service : " + service); } Exception ex = ServiceOperations.stopQuietly(LOG, service); if (ex != null && firstException == null) { LOG.warn("Failed to stop service, name=" + service.getName(), ex); firstException = ex; } } //after stopping all services, rethrow the first exception raised if (firstException != null) { throw ServiceStateException.convert(firstException); } }