svn commit: r734690 - in /activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream: StreamConsumer.java StreamEndpoint.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r734690 - in /activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream: StreamConsumer.java StreamEndpoint.java

davsclaus-2
Author: davsclaus
Date: Thu Jan 15 04:59:00 2009
New Revision: 734690

URL: http://svn.apache.org/viewvc?rev=734690&view=rev
Log:
CAMEL-1258: Added option for prompt message

Modified:
    activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
    activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java

Modified: activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java?rev=734690&r1=734689&r2=734690&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java (original)
+++ activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamConsumer.java Thu Jan 15 04:59:00 2009
@@ -81,12 +81,37 @@
         Charset charset = endpoint.getCharset();
         BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, charset));
         String line;
-        while ((line = br.readLine()) != null) {
-            consumeLine(line);
+
+        boolean eos = false;
+        while (!eos) {
+            if (endpoint.getPromptMessage() != null) {
+                doPromptMessage();
+            }
+
+            line = br.readLine();
+            eos = line == null;
+            if (!eos) {
+                consumeLine(line);
+            }
         }
         // important: do not close the reader as it will close the standard system.in etc.
     }
 
+    /**
+     * Strategy method for prompting the prompt message
+     */
+    protected void doPromptMessage() {
+        if (endpoint.getPromptDelay() > 0) {
+            try {
+                Thread.sleep(endpoint.getPromptDelay());
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+            }
+        }
+
+        System.out.print(endpoint.getPromptMessage());
+    }
+
     private void consumeLine(Object line) throws Exception {
         Exchange exchange = endpoint.createExchange();
 

Modified: activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java?rev=734690&r1=734689&r2=734690&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-stream/src/main/java/org/apache/camel/component/stream/StreamEndpoint.java Thu Jan 15 04:59:00 2009
@@ -34,6 +34,8 @@
     private String url;
     private long delay;
     private String encoding;
+    private String promptMessage;
+    private long promptDelay;
 
     public StreamEndpoint(String endpointUri, Component component) throws Exception {
         super(endpointUri, component);
@@ -84,6 +86,22 @@
         this.encoding = encoding;
     }
 
+    public String getPromptMessage() {
+        return promptMessage;
+    }
+
+    public void setPromptMessage(String promptMessage) {
+        this.promptMessage = promptMessage;
+    }
+
+    public long getPromptDelay() {
+        return promptDelay;
+    }
+
+    public void setPromptDelay(long promptDelay) {
+        this.promptDelay = promptDelay;
+    }
+
     // Implementations
     //-------------------------------------------------------------------------