You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2002/05/07 14:53:24 UTC

DO NOT REPLY [Bug 8866] New: - Signal handling in java task

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8866>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8866

Signal handling in java task

           Summary: Signal handling in java task
           Product: Ant
           Version: 1.4.1
          Platform: All
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Core tasks
        AssignedTo: ant-dev@jakarta.apache.org
        ReportedBy: simon@newphoric.com


It would be nice to be able to catch Interrupt / Temrinate signals in the java 
task and forward them to the launched executable. This would *really* nice if 
it was a parameter on the task. 

For example (this is a hack tho') :

in the org.apache.tools.ant.taskdefs.Java class I changed the execute line to 
be :

execute = new Execute(new LogStreamHandler(this, 2, 1), new 
GracefulShutdownWatchdog(1));

where the GracefulShutdownWatchdog is as follows:

public class GracefulShutdownWatchdog extends ExecuteWatchdog {
    public GracefulShutdownWatchdog(int timeout) {
      super(timeout);
    }

    public void start(java.lang.Process process) {
      final Process p= process;
      Signal.handle(new Signal("INT"), new SignalHandler () {
          public void handle(Signal sig) {
            p.destroy();
            System.err.println("Child process INTERRUPT request recieved"); 
            try {
              p.waitFor();
            }
            catch(InterruptedException exc) {
              System.err.println("Interrupted whilst waiting for Running 
process to die gracefully");
            }
          }
        });
    }

    public void stop() {
      myWatching= false;
      myKilled= true;
    }

    public void run() {
    }

    public boolean isWatching() {
      return myWatching;
    }
    
    public boolean killedProcess() {
      return myKilled;
    }

    private boolean myWatching= false;
    private boolean myKilled= false;
    private Process myProcess;
  }

This is only an example of what I was trying to achieve - not a recommendation 
fro the actual implementation. Part of the problem is that you cannot subclass 
the Java task to override the implementation of run(String[]) and you cannot 
get to the CommandLineJava memeber of the Java class to override the call in 
executeJava. A lot of the problem stems from the fact that it seems (to me 
anyway) virtually impossible to subclass org.apache.tools.ant.taskdefs.Java and 
get hold of the java.lang.Process created in the run(String[]) method. This 
makes it very difficult to pass on the signals to the forked JVM. My method 
above is to illustrate what I am trying to do, obviously there are better ways! 
(Apologies for abuse of the Watchdog :)

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>