Search in sources :

Example 1 with ShutdownPrepared

use of org.apache.camel.spi.ShutdownPrepared in project camel by apache.

the class DefaultShutdownStrategy method prepareShutdown.

/**
     * Prepares the services for shutdown, by invoking the {@link ShutdownPrepared#prepareShutdown(boolean, boolean)} method
     * on the service if it implement this interface.
     *
     * @param service the service
     * @param forced  whether to force shutdown
     * @param includeChildren whether to prepare the child of the service as well
     */
private static void prepareShutdown(Service service, boolean suspendOnly, boolean forced, boolean includeChildren, boolean suppressLogging) {
    Set<Service> list;
    if (includeChildren) {
        // include error handlers as we want to prepare them for shutdown as well
        list = ServiceHelper.getChildServices(service, true);
    } else {
        list = new LinkedHashSet<Service>(1);
        list.add(service);
    }
    for (Service child : list) {
        if (child instanceof ShutdownPrepared) {
            try {
                LOG.trace("Preparing {} shutdown on {}", forced ? "forced" : "", child);
                ((ShutdownPrepared) child).prepareShutdown(suspendOnly, forced);
            } catch (Exception e) {
                if (suppressLogging) {
                    LOG.trace("Error during prepare shutdown on " + child + ". This exception will be ignored.", e);
                } else {
                    LOG.warn("Error during prepare shutdown on " + child + ". This exception will be ignored.", e);
                }
            }
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Service(org.apache.camel.Service) ShutdownPrepared(org.apache.camel.spi.ShutdownPrepared) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Service (org.apache.camel.Service)1 ShutdownPrepared (org.apache.camel.spi.ShutdownPrepared)1