Author: richard.opalka(a)jboss.com
Date: 2008-09-29 02:14:54 -0400 (Mon, 29 Sep 2008)
New Revision: 8282
Removed:
common/trunk/src/main/java/org/jboss/wsf/common/concurrent/CopyJob.java
Modified:
common/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java
Log:
[JBWS-2322] Removing copy thread capability
Deleted: common/trunk/src/main/java/org/jboss/wsf/common/concurrent/CopyJob.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/concurrent/CopyJob.java 2008-09-28
20:19:48 UTC (rev 8281)
+++ common/trunk/src/main/java/org/jboss/wsf/common/concurrent/CopyJob.java 2008-09-29
06:14:54 UTC (rev 8282)
@@ -1,142 +0,0 @@
-/*
- * 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.wsf.common.concurrent;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Sample usage:
- *
- * <blockquote><pre>
- * CopyJob copyJob = new CopyJob( inputStream, printStream );
- * new Thread( copyJob ).start();
- * try
- * {
- * // do some other staff
- * ...
- * }
- * finally
- * {
- * copyJob.kill();
- * }
- * </pre></blockquote>
- *
- * @author richard.opalka(a)jboss.com
- */
-public final class CopyJob implements Runnable
-{
-
- /**
- * Input stream to data read from.
- */
- private final InputStream is;
- /**
- * Output stream to write data to.
- */
- private final OutputStream os;
- /**
- * Whether this job is terminated.
- */
- private boolean terminated;
-
- /**
- * Constructor.
- * @param is input stream to read data from
- * @param os output stream to write data to
- */
- public CopyJob( InputStream is, OutputStream os )
- {
- super();
-
- if ( ( is == null ) || ( os == null ) )
- {
- throw new IllegalArgumentException( "Constructor parameters can't be
null" );
- }
-
- this.is = is;
- this.os = os;
- }
-
- /**
- * Copies all data from <b>input stream</b> to <b>output
stream</b> (both passed to constructor) until job is killed
- */
- public final void run()
- {
- try
- {
- copy( this.is, this.os );
- }
- catch ( IOException ioe )
- {
- ioe.printStackTrace(System.err);
- }
- finally
- {
- try { this.is.close(); } catch ( IOException ioe ) { ioe.printStackTrace(
System.err ); }
- }
- }
-
- /**
- * Copies all data from <b>is</b> to <b>os</b> until job is
killed
- * @param is input stream to read data from
- * @param os output stream to write data to
- * @throws IOException if I/O error occurs
- */
- private void copy( final InputStream is, final OutputStream os ) throws IOException
- {
- final byte[] buffer = new byte[ 512 ];
- int countOfBytes = -1;
-
- while ( !this.terminated )
- {
- while ( is.available() <= 0 )
- {
- synchronized( this )
- {
- try
- {
- this.wait( 50 ); // guard
- if ( this.terminated ) return;
- }
- catch ( InterruptedException ie )
- {
- ie.printStackTrace( System.err );
- }
- }
- }
-
- countOfBytes = is.read( buffer, 0, buffer.length );
- os.write( buffer, 0, countOfBytes );
- }
- }
-
- /**
- * Kills this job. Calling this method also ensures that input stream passed to the
constructor will be closed properly
- */
- public final void kill()
- {
- this.terminated = true;
- }
-
-}
\ No newline at end of file
Modified: common/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java 2008-09-28 20:19:48 UTC
(rev 8281)
+++ common/trunk/src/main/java/org/jboss/wsf/test/JBossWSTest.java 2008-09-29 06:14:54 UTC
(rev 8282)
@@ -41,7 +41,6 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.common.DOMWriter;
import org.jboss.wsf.common.IOUtils;
-import org.jboss.wsf.common.concurrent.CopyJob;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -54,9 +53,7 @@
*/
public abstract class JBossWSTest extends TestCase
{
- // provide logging
protected Logger log = Logger.getLogger(getClass().getName());
-
private JBossWSTestHelper delegate = new JBossWSTestHelper();
public JBossWSTest()
@@ -109,19 +106,23 @@
*/
public void executeCommand(String command, OutputStream os, String message) throws
IOException
{
- if ( command == null )
+ if (command == null)
throw new NullPointerException( "Command cannot be null" );
System.out.println("Executing command: " + command);
-
Process p = Runtime.getRuntime().exec(command);
- CopyJob job = new CopyJob(p.getInputStream(), os == null ? System.out : os);
- // unfortunately the following thread is needed (otherwise it will not work on
windows)
- new Thread( job ).start();
- int statusCode = -1;
+ System.out.println("Process input stream:");
+ IOUtils.copyStream(os == null ? System.out : os, p.getInputStream());
try
{
- statusCode = p.waitFor();
+ int statusCode = p.waitFor();
+ if (statusCode != 0)
+ {
+ System.err.println("Process error stream:");
+ IOUtils.copyStream(System.err, p.getErrorStream());
+ }
+ String fallbackMessage = "Process did exit with status " + statusCode;
+ assertTrue(message != null ? message : fallbackMessage, statusCode == 0);
}
catch (InterruptedException ie)
{
@@ -129,21 +130,8 @@
}
finally
{
- job.kill();
p.destroy();
}
-
- // check status code
- if (statusCode != 0)
- {
- System.err.println("Error stream");
- System.err.println();
- IOUtils.copyStream(System.err, p.getErrorStream());
- System.err.println();
- }
-
- String fallbackMessage = "Process did exit with status " + statusCode;
- assertTrue(message != null ? message : fallbackMessage, statusCode == 0);
}
public MBeanServerConnection getServer() throws NamingException
@@ -262,7 +250,6 @@
if (expStr.equals(wasStr) == false)
{
System.out.println("\nExp: " + expStr + "\nWas: " +
wasStr);
- Logger.getLogger(JBossWSTest.class).error("\nExp: " + expStr +
"\nWas: " + wasStr);
}
assertEquals(expStr, wasStr);
}