You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/02/22 14:06:21 UTC
svn commit: r912554 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/impl/ main/java/org/apache/camel/spi/
test/java/org/apache/camel/component/file/ test/java/org/apache/camel/impl/
Author: davsclaus
Date: Mon Feb 22 13:06:21 2010
New Revision: 912554
URL: http://svn.apache.org/viewvc?rev=912554&view=rev
Log:
CAMEL-2492: PollingConsumerPollStrategy supports skipping poll if begin returns false.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java
- copied, changed from r912494, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PollingConsumerPollStrategy.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyStopOnRollbackTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumerPollStrategy.java Mon Feb 22 13:06:21 2010
@@ -31,8 +31,8 @@
protected final transient Log log = LogFactory.getLog(getClass());
- public void begin(Consumer consumer, Endpoint endpoint) {
- // noop
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java Mon Feb 22 13:06:21 2010
@@ -101,10 +101,16 @@
}
}
- pollStrategy.begin(this, getEndpoint());
- retryCounter++;
- poll();
- pollStrategy.commit(this, getEndpoint());
+ boolean begin = pollStrategy.begin(this, getEndpoint());
+ if (begin) {
+ retryCounter++;
+ poll();
+ pollStrategy.commit(this, getEndpoint());
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cannot begin polling as pollStrategy returned false: " + pollStrategy);
+ }
+ }
}
if (LOG.isTraceEnabled()) {
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PollingConsumerPollStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PollingConsumerPollStrategy.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PollingConsumerPollStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/PollingConsumerPollStrategy.java Mon Feb 22 13:06:21 2010
@@ -35,8 +35,9 @@
*
* @param consumer the consumer
* @param endpoint the endpoint being consumed
+ * @return <tt>true</tt> to begin polling, or <tt>false</tt> to skip polling this time.
*/
- void begin(Consumer consumer, Endpoint endpoint);
+ boolean begin(Consumer consumer, Endpoint endpoint);
/**
* Called when poll is completed successfully
Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java (from r912494, camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java&r1=912494&r2=912554&rev=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyNotBeginTest.java Mon Feb 22 13:06:21 2010
@@ -28,7 +28,7 @@
/**
* Unit test for poll strategy
*/
-public class FileConsumerPollStrategyTest extends ContextTestSupport {
+public class FileConsumerPollStrategyNotBeginTest extends ContextTestSupport {
private static int counter;
private static String event = "";
@@ -49,7 +49,7 @@
template.sendBodyAndHeader("file:target/pollstrategy/", "Hello World", Exchange.FILE_NAME, "hello.txt");
}
- public void testFirstPollRollbackThenCommit() throws Exception {
+ public void testFirstPollNotBegin() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
@@ -58,7 +58,7 @@
// give file consumer a bit time
Thread.sleep(1000);
- assertTrue(event.startsWith("rollbackcommit"));
+ assertTrue(event.startsWith("beginbegincommit"));
}
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -71,11 +71,13 @@
private class MyPollStrategy implements PollingConsumerPollStrategy {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
+ event += "begin";
if (counter++ == 0) {
- // simulate an error on first poll
- throw new IllegalArgumentException("Damn I cannot do this");
+ // deny polling at first call
+ return false;
}
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {
@@ -83,9 +85,7 @@
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception {
- if (cause.getMessage().equals("Damn I cannot do this")) {
- event += "rollback";
- }
+ event += "rollback";
return false;
}
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyRollbackThrowExceptionTest.java Mon Feb 22 13:06:21 2010
@@ -72,7 +72,7 @@
private class MyPollStrategy implements PollingConsumerPollStrategy {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
// start consumer as we simulate the fail in begin
// and thus before camel lazy start it itself
try {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyStopOnRollbackTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyStopOnRollbackTest.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyStopOnRollbackTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyStopOnRollbackTest.java Mon Feb 22 13:06:21 2010
@@ -72,7 +72,7 @@
private class MyPollStrategy implements PollingConsumerPollStrategy {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
// start consumer as we simulate the fail in begin
// and thus before camel lazy start it itself
try {
@@ -85,6 +85,8 @@
// simulate an error on first poll
throw new IllegalArgumentException("Damn I cannot do this");
}
+
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerPollStrategyTest.java Mon Feb 22 13:06:21 2010
@@ -71,11 +71,12 @@
private class MyPollStrategy implements PollingConsumerPollStrategy {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
if (counter++ == 0) {
// simulate an error on first poll
throw new IllegalArgumentException("Damn I cannot do this");
}
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java?rev=912554&r1=912553&r2=912554&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ScheduledPollConsumerTest.java Mon Feb 22 13:06:21 2010
@@ -33,7 +33,8 @@
MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(expectedException);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {
@@ -74,7 +75,8 @@
MockScheduledPollConsumer consumer = new MockScheduledPollConsumer(expectedException);
consumer.setPollStrategy(new PollingConsumerPollStrategy() {
- public void begin(Consumer consumer, Endpoint endpoint) {
+ public boolean begin(Consumer consumer, Endpoint endpoint) {
+ return true;
}
public void commit(Consumer consumer, Endpoint endpoint) {