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