Author: davsclaus
Date: Sun Nov 1 14:55:03 2009
New Revision: 831684
URL: http://svn.apache.org/viewvc?rev=831684&view=rev
Log:
CAMEL-1048: scheduled consumer is now also suspendable. Added file based
example to route throttler example.
Added:
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
- copied, changed from r831671,
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-file-client.xml
- copied, changed from r831671,
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-client.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollConsumer.java
camel/trunk/examples/camel-example-route-throttling/pom.xml
camel/trunk/examples/camel-example-route-throttling/src/main/resources/META-INF/spring/camel-server.xml
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=831684&r1=831683&r2=831684&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
Sun Nov 1 14:55:03 2009
@@ -23,6 +23,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
+import org.apache.camel.SuspendableService;
import org.apache.camel.spi.PollingConsumerPollStrategy;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.concurrent.ExecutorServiceHelper;
@@ -34,7 +35,7 @@
*
* @version $Revision$
*/
-public abstract class ScheduledPollConsumer extends DefaultConsumer implements
Runnable {
+public abstract class ScheduledPollConsumer extends DefaultConsumer implements
Runnable, SuspendableService {
private static final int DEFAULT_THREADPOOL_SIZE = 10;
private static final transient Log LOG =
LogFactory.getLog(ScheduledPollConsumer.class);
@@ -47,6 +48,7 @@
private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
private boolean useFixedDelay;
private PollingConsumerPollStrategy pollStrategy = new
DefaultPollingConsumerPollStrategy();
+ private boolean suspended;
public ScheduledPollConsumer(DefaultEndpoint endpoint, Processor
processor) {
super(endpoint, processor);
@@ -73,6 +75,10 @@
* Invoked whenever we should be polled
*/
public void run() {
+ if (suspended) {
+ return;
+ }
+
int retryCounter = -1;
boolean done = false;
@@ -158,6 +164,18 @@
this.pollStrategy = pollStrategy;
}
+ public void suspend() {
+ suspended = true;
+ }
+
+ public void resume() {
+ suspended = false;
+ }
+
+ public boolean isSuspended() {
+ return suspended;
+ }
+
// Implementation methods
//
-------------------------------------------------------------------------
Modified: camel/trunk/examples/camel-example-route-throttling/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-route-throttling/pom.xml?rev=831684&r1=831683&r2=831684&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-route-throttling/pom.xml (original)
+++ camel/trunk/examples/camel-example-route-throttling/pom.xml Sun Nov 1
14:55:03 2009
@@ -85,6 +85,13 @@
<target.main.class>org.apache.camel.example.client.CamelClient</target.main.class>
</properties>
</profile>
+ <profile>
+ <id>CamelFileClient</id>
+ <properties>
+ <!-- we start using our own class to control what we do in the
main -->
+
<target.main.class>org.apache.camel.example.client.CamelFileClient</target.main.class>
+ </properties>
+ </profile>
</profiles>
<build>
<plugins>
Copied:
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
(from r831671,
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java?p2=camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java&p1=camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java&r1=831671&r2=831684&rev=831684&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelClient.java
(original)
+++
camel/trunk/examples/camel-example-route-throttling/src/main/java/org/apache/camel/example/client/CamelFileClient.java
Sun Nov 1 14:55:03 2009
@@ -16,62 +16,38 @@
*/
package org.apache.camel.example.client;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
+import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
- * Client that uses the {...@link ProducerTemplate} to easily exchange
messages with the Server.
- * <p/>
- * Requires that the JMS broker is running, as well as CamelServer
+ * Client that uses the {...@link org.apache.camel.ProducerTemplate} to easily
exchange messages with the Server.
*/
-public final class CamelClient {
+public final class CamelFileClient {
- private static final int SIZE = 10000;
- private static final int POOL = 100;
+ private static final int SIZE = 5000;
- private CamelClient() {
+ private CamelFileClient() {
// Helper class
}
public static void main(final String[] args) throws Exception {
- System.out.println("Notice this client requires that the CamelServer
is already running!");
-
- ApplicationContext context = new
ClassPathXmlApplicationContext("camel-client.xml");
+ ApplicationContext context = new
ClassPathXmlApplicationContext("camel-file-client.xml");
// get the camel template for Spring template style sending of
messages (= producer)
final ProducerTemplate producer = (ProducerTemplate)
context.getBean("camelTemplate");
// now send a lot of messages
- System.out.println("Sending ...");
-
- final CountDownLatch latch = new CountDownLatch(POOL);
+ System.out.println("Writing files ...");
- ExecutorService executors = Executors.newFixedThreadPool(POOL);
- for (int i = 0; i < POOL; i++) {
- final Integer idx = i;
- executors.execute(new Runnable() {
- public void run() {
- try {
- for (int j = 0; j < SIZE / POOL; j++) {
- producer.sendBody("jms:queue:inbox", "Message " +
idx.intValue() * j + j);
- }
- } finally {
- latch.countDown();
- }
- }
- });
+ for (int i = 0; i < SIZE; i++) {
+ producer.sendBodyAndHeader("file:target//inbox", "File " + i,
Exchange.FILE_NAME, i + ".txt");
}
- latch.await(300, TimeUnit.SECONDS);
- System.out.println("... Send " + SIZE + " message to JMS broker");
+ System.out.println("... Wrote " + SIZE + " files");
System.exit(0);
}
-}
+}
\ No newline at end of file
Modified:
camel/trunk/examples/camel-example-route-throttling/src/main/resources/META-INF/spring/camel-server.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-route-throttling/src/main/resources/META-INF/spring/camel-server.xml?rev=831684&r1=831683&r2=831684&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-route-throttling/src/main/resources/META-INF/spring/camel-server.xml
(original)
+++
camel/trunk/examples/camel-example-route-throttling/src/main/resources/META-INF/spring/camel-server.xml
Sun Nov 1 14:55:03 2009
@@ -49,17 +49,23 @@
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
- <endpoint uri="seda:inbox?concurrentConsumers=40&size=25000"
id="bar"/>
+ <endpoint uri="seda:inbox?concurrentConsumers=40&size=25000"
id="foo"/>
<route routePolicyRef="myPolicy">
<from uri="jms:queue:inbox?concurrentConsumers=100"/>
<transacted/>
<to uri="log:+++JMS +++?groupSize=100"/>
- <to ref="bar"/>
+ <to ref="foo"/>
+ </route>
+
+ <route routePolicyRef="myPolicy">
+ <from
uri="file://target/inbox?delete=true&maxMessagesPerPoll=50"/>
+ <to uri="log:+++FILE+++?groupSize=100"/>
+ <to ref="foo"/>
</route>
<route>
- <from ref="bar"/>
+ <from ref="foo"/>
<delay><constant>100</constant></delay>
<to uri="log:+++SEDA+++?groupSize=100"/>
</route>
Copied:
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-file-client.xml
(from r831671,
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-client.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-file-client.xml?p2=camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-file-client.xml&p1=camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-client.xml&r1=831671&r2=831684&rev=831684&view=diff
==============================================================================
---
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-client.xml
(original)
+++
camel/trunk/examples/camel-example-route-throttling/src/main/resources/camel-file-client.xml
Sun Nov 1 14:55:03 2009
@@ -28,8 +28,4 @@
<camel:template id="camelTemplate"/>
</camel:camelContext>
- <bean id="jms"
class="org.apache.activemq.camel.component.ActiveMQComponent">
- <property name="brokerURL" value="tcp://localhost:61616"/>
- </bean>
-
</beans>
\ No newline at end of file