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.CamelContextAware;
020    import org.apache.camel.Consumer;
021    import org.apache.camel.ShutdownableService;
022    
023    /**
024     * A pluggable scheduler for {@link org.apache.camel.impl.ScheduledPollConsumer} consumers.
025     * <p/>
026     * The default implementation {@link org.apache.camel.impl.DefaultScheduledPollConsumerScheduler} is
027     * using the {@link java.util.concurrent.ScheduledExecutorService} from the JDK to schedule and run the poll task.
028     * <p/>
029     * An alternative implementation is in <tt>camel-quartz2</tt> component that allows to use CRON expression
030     * to define when the scheduler should run.
031     */
032    public interface ScheduledPollConsumerScheduler extends ShutdownableService, CamelContextAware {
033    
034        /**
035         * Initializes this {@link ScheduledPollConsumerScheduler} with the associated {@link Consumer}.
036         *
037         * @param consumer the consumer.
038         */
039        void onInit(Consumer consumer);
040    
041        /**
042         * Schedules the task to run.
043         *
044         * @param task the task to run.
045         */
046        void scheduleTask(Runnable task);
047    
048        /**
049         * Attempts to unschedules the last task which was scheduled.
050         * <p/>
051         * An implementation may not implement this method.
052         */
053        void unscheduleTask();
054    
055        /**
056         * Starts the scheduler.
057         * <p/>
058         * If the scheduler is already started, then this is a noop method call.
059         */
060        void startScheduler();
061    
062        /**
063         * Whether the scheduler has been started.
064         *
065         * @return <tt>true</tt> if started, <tt>false</tt> otherwise.
066         */
067        boolean isSchedulerStarted();
068    
069    }