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
019import org.apache.camel.ShutdownRunningTask;
020
021/**
022 * Allows {@link org.apache.camel.Consumer} to fine grained control on shutdown which mostly
023 * have to cater for in-memory based components. These components need to be able to have an extra
024 * chance to have their pending exchanges being completed to support graceful shutdown. This helps
025 * ensure that no messages get lost.
026 * @see org.apache.camel.spi.ShutdownStrategy
027 */
028public interface ShutdownAware extends ShutdownPrepared {
029
030    /**
031     * To defer shutdown during first phase of shutdown. This allows any pending exchanges to be completed
032     * and therefore ensure a graceful shutdown without loosing messages. At the very end when there are no
033     * more inflight and pending messages the consumer could then safely be shutdown.
034     * <p/>
035     * This is needed by {@link org.apache.camel.component.seda.SedaConsumer}.
036     *
037     * @param shutdownRunningTask the configured option for how to act when shutting down running tasks.
038     * @return <tt>true</tt> to defer shutdown to very last.
039     */
040    boolean deferShutdown(ShutdownRunningTask shutdownRunningTask);
041
042    /**
043     * Gets the number of pending exchanges.
044     * <p/>
045     * Some consumers has internal queues with {@link org.apache.camel.Exchange} which are pending.
046     * For example the {@link org.apache.camel.component.seda.SedaConsumer}.
047     * <p/>
048     * Return <tt>zero</tt> to indicate no pending exchanges and therefore ready to shutdown.
049     *
050     * @return number of pending exchanges
051     */
052    int getPendingExchangesSize();
053
054}