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; 018 019 /** 020 * Strategy for a {@link org.apache.camel.PollingConsumer} when polling an {@link org.apache.camel.Endpoint}. 021 * <p/> 022 * This pluggable strategy allows to plugin different implementations what to do, most noticeable what to 023 * do in case the polling goes wrong. This can be handled in the {@link #rollback(Consumer, Endpoint, int, Exception) rollback} 024 * method. 025 * 026 * @version $Revision: 789216 $ 027 */ 028 public interface PollingConsumerPollStrategy { 029 030 /** 031 * Called when poll is about to begin 032 * 033 * @param consumer the consumer 034 * @param endpoint the endpoint being consumed 035 */ 036 void begin(Consumer consumer, Endpoint endpoint); 037 038 /** 039 * Called when poll is completed successfully 040 * 041 * @param consumer the consumer 042 * @param endpoint the endpoint being consumed 043 */ 044 void commit(Consumer consumer, Endpoint endpoint); 045 046 /** 047 * Called when poll failed 048 * 049 * @param consumer the consumer 050 * @param endpoint the endpoint being consumed 051 * @param retryCounter current retry attempt, starting from 0. 052 * @param cause the caused exception 053 * @throws Exception can be used to rethrow the caused exception. Notice that thrown an exception will 054 * terminate the scheduler and thus Camel will not trigger again. So if you want to let the scheduler 055 * to continue to run then do <b>not</b> throw any exception from this method. 056 * @return whether to retry immediately or not. Return <tt>false</tt> to ignore the problem, 057 * <tt>true</tt> to try immediately again 058 */ 059 boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception; 060 061 }