001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.spi;
018
019/**
020 * Allows a {@link org.apache.camel.Service} to prepare for shutdown.
021 * <p/>
022 * <b>Important: </b> Implementators of this interface must be a {@link org.apache.camel.Service} as well.
023 * <p/>
024 * This allows {@link org.apache.camel.Processor}s to prepare for shutdown, such as when
025 * {@link org.apache.camel.CamelContext} or a {@link org.apache.camel.Route} is shutting down.
026 * The {@link org.apache.camel.Processor} could be a stateful EIP such as the
027 * {@link org.apache.camel.processor.aggregate.AggregateProcessor}, allowing it to do custom work
028 * to prepare for shutdown.
029 */
030public interface ShutdownPrepared {
031
032    /**
033     * Prepares for stop/shutdown.
034     * <p/>
035     * The {@link ShutdownStrategy} supports preparing for shutdown using two steps.
036     * First a regular preparation, where the given forced parameter will be <tt>false</tt>.
037     * And if the shutdown times out, then the {@link ShutdownStrategy} performs a more aggressive
038     * shutdown, calling this method a second time with <tt>true</tt> for the given forced parameter.
039     * For example by graceful stopping any threads or the likes.
040     * <p/>
041     * In addition a service can also be suspended (not stopped), and when this happens the parameter
042     * <tt>suspendOnly</tt> has the value <tt>true</tt>. This can be used to prepare the service
043     * for suspension, such as marking a worker thread to skip action.
044     * <p/>
045     * For forced shutdown, then the service is expected to aggressively shutdown any child services, such
046     * as thread pools etc. This is the last chance it has to perform such duties.
047     * 
048     * @param suspendOnly <tt>true</tt> if the intention is to only suspend the service, and not stop/shutdown the service.
049     * @param forced <tt>true</tt> is forcing a more aggressive shutdown, <tt>false</tt> is for preparing to shutdown.
050     */
051    void prepareShutdown(boolean suspendOnly, boolean forced);
052
053}