Browse Source

spruced.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270268 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
007e5e2034
4 changed files with 104 additions and 100 deletions
  1. +27
    -27
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java
  2. +25
    -23
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/PumpStreamHandler.java
  3. +27
    -27
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java
  4. +25
    -23
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/PumpStreamHandler.java

+ 27
- 27
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java View File

@@ -24,34 +24,34 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
* @see Execute * @see Execute
*/ */
public class ExecuteWatchdog implements Runnable
public class ExecuteWatchdog
implements Runnable
{ {

/** /**
* say whether or not the watchog is currently monitoring a process * say whether or not the watchog is currently monitoring a process
*/ */
private boolean watch = false;
private boolean m_watch;


/** /**
* exception that might be thrown during the process execution * exception that might be thrown during the process execution
*/ */
private Exception caught = null;
private Exception m_caught;


/** /**
* say whether or not the process was killed due to running overtime * say whether or not the process was killed due to running overtime
*/ */
private boolean killedProcess = false;
private boolean m_killedProcess;


/** /**
* the process to execute and watch for duration * the process to execute and watch for duration
*/ */
private Process process;
private Process m_process;


/** /**
* timeout duration. Once the process running time exceeds this it should be * timeout duration. Once the process running time exceeds this it should be
* killed * killed
*/ */
private int timeout;
private int m_timeout;


/** /**
* Creates a new watchdog with a given timeout. * Creates a new watchdog with a given timeout.
@@ -65,7 +65,7 @@ public class ExecuteWatchdog implements Runnable
{ {
throw new IllegalArgumentException( "timeout lesser than 1." ); throw new IllegalArgumentException( "timeout lesser than 1." );
} }
this.timeout = timeout;
this.m_timeout = timeout;
} }


/** /**
@@ -76,7 +76,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public boolean isWatching() public boolean isWatching()
{ {
return watch;
return m_watch;
} }


/** /**
@@ -91,10 +91,10 @@ public class ExecuteWatchdog implements Runnable
public void checkException() public void checkException()
throws TaskException throws TaskException
{ {
if( caught != null )
if( m_caught != null )
{ {
throw new TaskException( "Exception in ExecuteWatchdog.run: " throw new TaskException( "Exception in ExecuteWatchdog.run: "
+ caught.getMessage(), caught );
+ m_caught.getMessage(), m_caught );
} }
} }


@@ -106,7 +106,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public boolean killedProcess() public boolean killedProcess()
{ {
return killedProcess;
return m_killedProcess;
} }


/** /**
@@ -118,9 +118,9 @@ public class ExecuteWatchdog implements Runnable
{ {
// This isn't a Task, don't have a Project object to log. // This isn't a Task, don't have a Project object to log.
// project.log("ExecuteWatchdog: timeout = "+timeout+" msec", Project.MSG_VERBOSE); // project.log("ExecuteWatchdog: timeout = "+timeout+" msec", Project.MSG_VERBOSE);
final long until = System.currentTimeMillis() + timeout;
final long until = System.currentTimeMillis() + m_timeout;
long now; long now;
while( watch && until > ( now = System.currentTimeMillis() ) )
while( m_watch && until > ( now = System.currentTimeMillis() ) )
{ {
try try
{ {
@@ -138,22 +138,22 @@ public class ExecuteWatchdog implements Runnable
{ {
// We must check if the process was not stopped // We must check if the process was not stopped
// before being here // before being here
process.exitValue();
m_process.exitValue();
} }
catch( IllegalThreadStateException e ) catch( IllegalThreadStateException e )
{ {
// the process is not terminated, if this is really // the process is not terminated, if this is really
// a timeout and not a manual stop then kill it. // a timeout and not a manual stop then kill it.
if( watch )
if( m_watch )
{ {
killedProcess = true;
process.destroy();
m_killedProcess = true;
m_process.destroy();
} }
} }
} }
catch( Exception e ) catch( Exception e )
{ {
caught = e;
m_caught = e;
} }
finally finally
{ {
@@ -175,14 +175,14 @@ public class ExecuteWatchdog implements Runnable
{ {
throw new NullPointerException( "process is null." ); throw new NullPointerException( "process is null." );
} }
if( this.process != null )
if( this.m_process != null )
{ {
throw new IllegalStateException( "Already running." ); throw new IllegalStateException( "Already running." );
} }
this.caught = null;
this.killedProcess = false;
this.watch = true;
this.process = process;
this.m_caught = null;
this.m_killedProcess = false;
this.m_watch = true;
this.m_process = process;
final Thread thread = new Thread( this, "WATCHDOG" ); final Thread thread = new Thread( this, "WATCHDOG" );
thread.setDaemon( true ); thread.setDaemon( true );
thread.start(); thread.start();
@@ -194,7 +194,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public synchronized void stop() public synchronized void stop()
{ {
watch = false;
m_watch = false;
notifyAll(); notifyAll();
} }


@@ -203,8 +203,8 @@ public class ExecuteWatchdog implements Runnable
*/ */
protected void cleanUp() protected void cleanUp()
{ {
watch = false;
process = null;
m_watch = false;
m_process = null;
} }
} }



+ 25
- 23
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/PumpStreamHandler.java View File

@@ -19,18 +19,20 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author thomas.haas@softwired-inc.com * @author thomas.haas@softwired-inc.com
*/ */
public class PumpStreamHandler implements ExecuteStreamHandler
public class PumpStreamHandler
implements ExecuteStreamHandler
{ {
private Thread errorThread;
private Thread m_errorThread;
private Thread m_inputThread;


private Thread inputThread;
private OutputStream m_output;
private OutputStream m_error;


private OutputStream out, err;

public PumpStreamHandler( OutputStream out, OutputStream err )
public PumpStreamHandler( final OutputStream output,
final OutputStream error )
{ {
this.out = out;
this.err = err;
m_output = output;
m_error = error;
} }


public PumpStreamHandler( OutputStream outAndErr ) public PumpStreamHandler( OutputStream outAndErr )
@@ -45,7 +47,7 @@ public class PumpStreamHandler implements ExecuteStreamHandler


public void setProcessErrorStream( InputStream is ) public void setProcessErrorStream( InputStream is )
{ {
createProcessErrorPump( is, err );
createProcessErrorPump( is, m_error );
} }


public void setProcessInputStream( OutputStream os ) public void setProcessInputStream( OutputStream os )
@@ -54,13 +56,13 @@ public class PumpStreamHandler implements ExecuteStreamHandler


public void setProcessOutputStream( InputStream is ) public void setProcessOutputStream( InputStream is )
{ {
createProcessOutputPump( is, out );
createProcessOutputPump( is, m_output );
} }


public void start() public void start()
{ {
inputThread.start();
errorThread.start();
m_inputThread.start();
m_errorThread.start();
} }


public void stop() public void stop()
@@ -68,28 +70,28 @@ public class PumpStreamHandler implements ExecuteStreamHandler
{ {
try try
{ {
inputThread.join();
m_inputThread.join();
} }
catch( InterruptedException e ) catch( InterruptedException e )
{ {
} }
try try
{ {
errorThread.join();
m_errorThread.join();
} }
catch( InterruptedException e ) catch( InterruptedException e )
{ {
} }
try try
{ {
err.flush();
m_error.flush();
} }
catch( IOException e ) catch( IOException e )
{ {
} }
try try
{ {
out.flush();
m_output.flush();
} }
catch( IOException e ) catch( IOException e )
{ {
@@ -98,22 +100,22 @@ public class PumpStreamHandler implements ExecuteStreamHandler


protected OutputStream getErr() protected OutputStream getErr()
{ {
return err;
return m_error;
} }


protected OutputStream getOut() protected OutputStream getOut()
{ {
return out;
return m_output;
} }


protected void createProcessErrorPump( InputStream is, OutputStream os ) protected void createProcessErrorPump( InputStream is, OutputStream os )
{ {
errorThread = createPump( is, os );
m_errorThread = createPump( is, os );
} }


protected void createProcessOutputPump( InputStream is, OutputStream os ) protected void createProcessOutputPump( InputStream is, OutputStream os )
{ {
inputThread = createPump( is, os );
m_inputThread = createPump( is, os );
} }


/** /**
@@ -124,11 +126,11 @@ public class PumpStreamHandler implements ExecuteStreamHandler
* @param os Description of Parameter * @param os Description of Parameter
* @return Description of the Returned Value * @return Description of the Returned Value
*/ */
protected Thread createPump( InputStream is, OutputStream os )
protected Thread createPump( final InputStream input,
final OutputStream output )
{ {
final Thread result = new Thread( new StreamPumper( is, os ) );
final Thread result = new Thread( new StreamPumper( input, output ) );
result.setDaemon( true ); result.setDaemon( true );
return result; return result;
} }

} }

+ 27
- 27
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/ExecuteWatchdog.java View File

@@ -24,34 +24,34 @@ import org.apache.myrmidon.api.TaskException;
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a> * @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
* @see Execute * @see Execute
*/ */
public class ExecuteWatchdog implements Runnable
public class ExecuteWatchdog
implements Runnable
{ {

/** /**
* say whether or not the watchog is currently monitoring a process * say whether or not the watchog is currently monitoring a process
*/ */
private boolean watch = false;
private boolean m_watch;


/** /**
* exception that might be thrown during the process execution * exception that might be thrown during the process execution
*/ */
private Exception caught = null;
private Exception m_caught;


/** /**
* say whether or not the process was killed due to running overtime * say whether or not the process was killed due to running overtime
*/ */
private boolean killedProcess = false;
private boolean m_killedProcess;


/** /**
* the process to execute and watch for duration * the process to execute and watch for duration
*/ */
private Process process;
private Process m_process;


/** /**
* timeout duration. Once the process running time exceeds this it should be * timeout duration. Once the process running time exceeds this it should be
* killed * killed
*/ */
private int timeout;
private int m_timeout;


/** /**
* Creates a new watchdog with a given timeout. * Creates a new watchdog with a given timeout.
@@ -65,7 +65,7 @@ public class ExecuteWatchdog implements Runnable
{ {
throw new IllegalArgumentException( "timeout lesser than 1." ); throw new IllegalArgumentException( "timeout lesser than 1." );
} }
this.timeout = timeout;
this.m_timeout = timeout;
} }


/** /**
@@ -76,7 +76,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public boolean isWatching() public boolean isWatching()
{ {
return watch;
return m_watch;
} }


/** /**
@@ -91,10 +91,10 @@ public class ExecuteWatchdog implements Runnable
public void checkException() public void checkException()
throws TaskException throws TaskException
{ {
if( caught != null )
if( m_caught != null )
{ {
throw new TaskException( "Exception in ExecuteWatchdog.run: " throw new TaskException( "Exception in ExecuteWatchdog.run: "
+ caught.getMessage(), caught );
+ m_caught.getMessage(), m_caught );
} }
} }


@@ -106,7 +106,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public boolean killedProcess() public boolean killedProcess()
{ {
return killedProcess;
return m_killedProcess;
} }


/** /**
@@ -118,9 +118,9 @@ public class ExecuteWatchdog implements Runnable
{ {
// This isn't a Task, don't have a Project object to log. // This isn't a Task, don't have a Project object to log.
// project.log("ExecuteWatchdog: timeout = "+timeout+" msec", Project.MSG_VERBOSE); // project.log("ExecuteWatchdog: timeout = "+timeout+" msec", Project.MSG_VERBOSE);
final long until = System.currentTimeMillis() + timeout;
final long until = System.currentTimeMillis() + m_timeout;
long now; long now;
while( watch && until > ( now = System.currentTimeMillis() ) )
while( m_watch && until > ( now = System.currentTimeMillis() ) )
{ {
try try
{ {
@@ -138,22 +138,22 @@ public class ExecuteWatchdog implements Runnable
{ {
// We must check if the process was not stopped // We must check if the process was not stopped
// before being here // before being here
process.exitValue();
m_process.exitValue();
} }
catch( IllegalThreadStateException e ) catch( IllegalThreadStateException e )
{ {
// the process is not terminated, if this is really // the process is not terminated, if this is really
// a timeout and not a manual stop then kill it. // a timeout and not a manual stop then kill it.
if( watch )
if( m_watch )
{ {
killedProcess = true;
process.destroy();
m_killedProcess = true;
m_process.destroy();
} }
} }
} }
catch( Exception e ) catch( Exception e )
{ {
caught = e;
m_caught = e;
} }
finally finally
{ {
@@ -175,14 +175,14 @@ public class ExecuteWatchdog implements Runnable
{ {
throw new NullPointerException( "process is null." ); throw new NullPointerException( "process is null." );
} }
if( this.process != null )
if( this.m_process != null )
{ {
throw new IllegalStateException( "Already running." ); throw new IllegalStateException( "Already running." );
} }
this.caught = null;
this.killedProcess = false;
this.watch = true;
this.process = process;
this.m_caught = null;
this.m_killedProcess = false;
this.m_watch = true;
this.m_process = process;
final Thread thread = new Thread( this, "WATCHDOG" ); final Thread thread = new Thread( this, "WATCHDOG" );
thread.setDaemon( true ); thread.setDaemon( true );
thread.start(); thread.start();
@@ -194,7 +194,7 @@ public class ExecuteWatchdog implements Runnable
*/ */
public synchronized void stop() public synchronized void stop()
{ {
watch = false;
m_watch = false;
notifyAll(); notifyAll();
} }


@@ -203,8 +203,8 @@ public class ExecuteWatchdog implements Runnable
*/ */
protected void cleanUp() protected void cleanUp()
{ {
watch = false;
process = null;
m_watch = false;
m_process = null;
} }
} }



+ 25
- 23
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/exec/PumpStreamHandler.java View File

@@ -19,18 +19,20 @@ import org.apache.myrmidon.api.TaskException;
* *
* @author thomas.haas@softwired-inc.com * @author thomas.haas@softwired-inc.com
*/ */
public class PumpStreamHandler implements ExecuteStreamHandler
public class PumpStreamHandler
implements ExecuteStreamHandler
{ {
private Thread errorThread;
private Thread m_errorThread;
private Thread m_inputThread;


private Thread inputThread;
private OutputStream m_output;
private OutputStream m_error;


private OutputStream out, err;

public PumpStreamHandler( OutputStream out, OutputStream err )
public PumpStreamHandler( final OutputStream output,
final OutputStream error )
{ {
this.out = out;
this.err = err;
m_output = output;
m_error = error;
} }


public PumpStreamHandler( OutputStream outAndErr ) public PumpStreamHandler( OutputStream outAndErr )
@@ -45,7 +47,7 @@ public class PumpStreamHandler implements ExecuteStreamHandler


public void setProcessErrorStream( InputStream is ) public void setProcessErrorStream( InputStream is )
{ {
createProcessErrorPump( is, err );
createProcessErrorPump( is, m_error );
} }


public void setProcessInputStream( OutputStream os ) public void setProcessInputStream( OutputStream os )
@@ -54,13 +56,13 @@ public class PumpStreamHandler implements ExecuteStreamHandler


public void setProcessOutputStream( InputStream is ) public void setProcessOutputStream( InputStream is )
{ {
createProcessOutputPump( is, out );
createProcessOutputPump( is, m_output );
} }


public void start() public void start()
{ {
inputThread.start();
errorThread.start();
m_inputThread.start();
m_errorThread.start();
} }


public void stop() public void stop()
@@ -68,28 +70,28 @@ public class PumpStreamHandler implements ExecuteStreamHandler
{ {
try try
{ {
inputThread.join();
m_inputThread.join();
} }
catch( InterruptedException e ) catch( InterruptedException e )
{ {
} }
try try
{ {
errorThread.join();
m_errorThread.join();
} }
catch( InterruptedException e ) catch( InterruptedException e )
{ {
} }
try try
{ {
err.flush();
m_error.flush();
} }
catch( IOException e ) catch( IOException e )
{ {
} }
try try
{ {
out.flush();
m_output.flush();
} }
catch( IOException e ) catch( IOException e )
{ {
@@ -98,22 +100,22 @@ public class PumpStreamHandler implements ExecuteStreamHandler


protected OutputStream getErr() protected OutputStream getErr()
{ {
return err;
return m_error;
} }


protected OutputStream getOut() protected OutputStream getOut()
{ {
return out;
return m_output;
} }


protected void createProcessErrorPump( InputStream is, OutputStream os ) protected void createProcessErrorPump( InputStream is, OutputStream os )
{ {
errorThread = createPump( is, os );
m_errorThread = createPump( is, os );
} }


protected void createProcessOutputPump( InputStream is, OutputStream os ) protected void createProcessOutputPump( InputStream is, OutputStream os )
{ {
inputThread = createPump( is, os );
m_inputThread = createPump( is, os );
} }


/** /**
@@ -124,11 +126,11 @@ public class PumpStreamHandler implements ExecuteStreamHandler
* @param os Description of Parameter * @param os Description of Parameter
* @return Description of the Returned Value * @return Description of the Returned Value
*/ */
protected Thread createPump( InputStream is, OutputStream os )
protected Thread createPump( final InputStream input,
final OutputStream output )
{ {
final Thread result = new Thread( new StreamPumper( is, os ) );
final Thread result = new Thread( new StreamPumper( input, output ) );
result.setDaemon( true ); result.setDaemon( true );
return result; return result;
} }

} }

Loading…
Cancel
Save