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     */
017    package org.apache.camel.spi;
018    
019    import 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     *
027     * @version 
028     * @see org.apache.camel.spi.ShutdownStrategy
029     */
030    public interface ShutdownAware extends ShutdownPrepared {
031    
032        /**
033         * To defer shutdown during first phase of shutdown. This allows any pending exchanges to be completed
034         * and therefore ensure a graceful shutdown without loosing messages. At the very end when there are no
035         * more inflight and pending messages the consumer could then safely be shutdown.
036         * <p/>
037         * This is needed by {@link org.apache.camel.component.seda.SedaConsumer}.
038         *
039         * @param shutdownRunningTask the configured option for how to act when shutting down running tasks.
040         * @return <tt>true</tt> to defer shutdown to very last.
041         */
042        boolean deferShutdown(ShutdownRunningTask shutdownRunningTask);
043    
044        /**
045         * Gets the number of pending exchanges.
046         * <p/>
047         * Some consumers has internal queues with {@link org.apache.camel.Exchange} which are pending.
048         * For example the {@link org.apache.camel.component.seda.SedaConsumer}.
049         * <p/>
050         * Return <tt>zero</tt> to indicate no pending exchanges and therefore ready to shutdown.
051         *
052         * @return number of pending exchanges
053         */
054        int getPendingExchangesSize();
055    
056    }