Search in sources :

Example 1 with ShutdownableService

use of org.apache.camel.ShutdownableService in project camel by apache.

the class ServiceHelper method stopAndShutdownService.

/**
     * Stops and shutdowns the given {@code service}, rethrowing the first exception caught.
     * <p/>
     * Calling this method has no effect if {@code value} is {@code null}.
     * 
     * @see #stopService(Object)
     * @see ShutdownableService#shutdown()
     */
public static void stopAndShutdownService(Object value) throws Exception {
    stopService(value);
    // then try to shutdown
    if (value instanceof ShutdownableService) {
        ShutdownableService service = (ShutdownableService) value;
        LOG.trace("Shutting down service {}", value);
        service.shutdown();
    }
}
Also used : ShutdownableService(org.apache.camel.ShutdownableService)

Example 2 with ShutdownableService

use of org.apache.camel.ShutdownableService in project camel by apache.

the class ServiceHelper method stopAndShutdownServices.

/**
     * Stops and shutdowns each element of the given {@code services} if {@code services}
     * itself is not {@code null}, otherwise this method would return immediately.
     * <p/>
     * If there's any exception being thrown while stopping/shutting down the elements one after
     * the other this method would rethrow the <b>first</b> such exception being thrown.
     * 
     * @see #stopService(Object)
     * @see ShutdownableService#shutdown()
     */
public static void stopAndShutdownServices(Collection<?> services) throws Exception {
    if (services == null) {
        return;
    }
    Exception firstException = null;
    for (Object value : services) {
        try {
            // must stop it first
            stopService(value);
            // then try to shutdown
            if (value instanceof ShutdownableService) {
                ShutdownableService service = (ShutdownableService) value;
                LOG.trace("Shutting down service: {}", service);
                service.shutdown();
            }
        } catch (Exception e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Caught exception shutting down service: " + value, e);
            }
            if (firstException == null) {
                firstException = e;
            }
        }
    }
    if (firstException != null) {
        throw firstException;
    }
}
Also used : ShutdownableService(org.apache.camel.ShutdownableService)

Aggregations

ShutdownableService (org.apache.camel.ShutdownableService)2