[jboss-cvs] JBossAS SVN: r73690 - in projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common: thread and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 26 18:45:07 EDT 2008


Author: ALRubinger
Date: 2008-05-26 18:45:06 -0400 (Mon, 26 May 2008)
New Revision: 73690

Added:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputThread.java
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputToSystemOutThread.java
Log:
[EJBTHREE-1382] Added Genric Process Output Redirection Mechanism

Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputThread.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputThread.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputThread.java	2008-05-26 22:45:06 UTC (rev 73690)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.common.thread;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+
+/**
+ * RedirectProcessOutputThread
+ * 
+ * Captures output from a Process and redirects to a 
+ * specified PrintStream
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public abstract class RedirectProcessOutputThread extends Thread implements Runnable
+{
+
+   // --------------------------------------------------------------------------------||
+   // Instance Members ---------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * The Process whose output to Capture
+    */
+   private Process process;
+
+   // --------------------------------------------------------------------------------||
+   // Constructor --------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Constructor
+    * 
+    * @param process The Process whose output to capture
+    */
+   public RedirectProcessOutputThread(Process process)
+   {
+      this.process = process;
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Overridden Implementations -----------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   @Override
+   public void run()
+   {
+      // Call Super
+      super.run();
+
+      // Initialize
+      int bytesRead = 0;
+      byte[] buffer = new byte[1024];
+
+      // Obtain InputStream of process
+      InputStream in = this.process.getInputStream();
+
+      // Read in and direct PrintStream
+      try
+      {
+         while ((bytesRead = in.read(buffer)) != -1)
+         {
+            this.getPrintStream().write(buffer, 0, bytesRead);
+         }
+      }
+      catch (IOException ioe)
+      {
+         throw new RuntimeException(ioe);
+      }
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Contracts ----------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the PrintStream to which output should be
+    * redirected
+    */
+   protected abstract PrintStream getPrintStream();
+}

Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputToSystemOutThread.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputToSystemOutThread.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/thread/RedirectProcessOutputToSystemOutThread.java	2008-05-26 22:45:06 UTC (rev 73690)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.common.thread;
+
+import java.io.PrintStream;
+
+/**
+ * RedirectProcessOutputToSystemOutThread
+ * 
+ * Captures output from a Process and redirects
+ * to System.out
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class RedirectProcessOutputToSystemOutThread extends RedirectProcessOutputThread
+{
+
+   // --------------------------------------------------------------------------------||
+   // Constructor --------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Constructor
+    * 
+    * @param process The Process whose output to capture
+    */
+   public RedirectProcessOutputToSystemOutThread(Process process)
+   {
+      super(process);
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the PrintStream to which output should be
+    * redirected
+    */
+   @Override
+   protected PrintStream getPrintStream()
+   {
+      return System.out;
+   }
+
+}




More information about the jboss-cvs-commits mailing list