geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r577057 - /geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
Date Tue, 18 Sep 2007 20:59:29 GMT
Author: jdillon
Date: Tue Sep 18 13:59:28 2007
New Revision: 577057

URL: http://svn.apache.org/viewvc?rev=577057&view=rev
Log:
Adding another pumper thingy to try and figure this shiz out

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
  (contents, props changed)
      - copied, changed from r576955, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
(from r576955, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java&r1=576955&r2=577057&rev=577057&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
Tue Sep 18 13:59:28 2007
@@ -17,25 +17,82 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.client;
+package org.apache.geronimo.gshell.remote.stream;
 
-import org.apache.geronimo.gshell.remote.message.EchoMessage;
-import org.apache.geronimo.gshell.remote.message.MessageVisitor;
-import org.apache.geronimo.gshell.remote.message.MessageVisitorSupport;
-import org.codehaus.plexus.component.annotations.Component;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Defines the logic for client-side message processing.
+ * Feeds data from and input stream to an output stream.
  *
  * @version $Rev$ $Date$
  */
-@Component(role=MessageVisitor.class, hint="client")
-public class RshClientMessageVisitor
-    extends MessageVisitorSupport
+public class StreamFeeder
+    implements Runnable
 {
-    public void visitEcho(final EchoMessage msg) throws Exception {
-        assert msg != null;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final InputStream input;
+
+    private final OutputStream output;
+
+    private boolean running;
+
+    public StreamFeeder(final InputStream input, final OutputStream output) {
+        assert input != null;
+        assert output != null;
+        
+        this.input = input;
+        this.output = output;
+    }
+
+    public void run() {
+        running = true;
+
+        log.debug("Running");
+
+        //
+        // TODO: Look into using a byte[] buffer here to read larger chunks at the same time?
+        //
+        
+        try {
+            int b;
+
+            while (running && ((b = input.read()) != -1)) {
+                output.write(b);
+            }
+        }
+        catch (Throwable e) {
+            log.error("Feed failure: " + e, e);
+        }
+        finally {
+            close();
+        }
+
+        log.debug("Stopped");
+    }
+
+    public boolean isRunning() {
+        return running;
+    }
+    
+    public void close() {
+        running = false;
+        
+        log.debug("Closed");
+    }
+
+    private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(0);
+
+    public Thread createThread() {
+        Thread t = new Thread(this, getClass().getSimpleName() + "-" + THREAD_COUNTER.getAndIncrement());
 
-        log.info("ECHO: {}", msg.getText());
+        t.setDaemon(true);
+        
+        return t;
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/StreamFeeder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message