donaldp 01/12/22 19:38:15
Modified: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec
ProcessDestroyer.java
Log:
Make it possible to request shutdown of all pending processes.
Revision Changes Path
1.5 +27 -26
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ProcessDestroyer.java
Index: ProcessDestroyer.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/ProcessDestroyer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ProcessDestroyer.java 2001/12/22 23:35:08 1.4
+++ ProcessDestroyer.java 2001/12/23 03:38:15 1.5
@@ -3,7 +3,7 @@
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
- * the LICENSE file.
+ * the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.exec;
@@ -12,14 +12,17 @@
import java.util.Iterator;
/**
- * Destroys all registered <code>Process</code>es when the VM exits.
+ * Destroys all registered <code>Process</code>es when
+ * the VM exits (if in JDK1.3) or when requested.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Michael Newcomb</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
+ * @version $Revision: 1.5 $ $Date: 2001/12/23 03:38:15 $
*/
public class ProcessDestroyer
extends Thread
{
- private ArrayList processes = new ArrayList();
+ private ArrayList m_processes = new ArrayList();
/**
* Constructs a <code>ProcessDestroyer</code> and registers it as a
shutdown
@@ -31,60 +34,58 @@
{
// check to see if the method exists (support pre-JDK 1.3 VMs)
//
- Class[] paramTypes = {Thread.class};
- Method addShutdownHook =
+ final Class[] paramTypes = {Thread.class};
+ final Method addShutdownHook =
Runtime.class.getMethod( "addShutdownHook", paramTypes );
// add the hook
- //
Object[] args = {this};
addShutdownHook.invoke( Runtime.getRuntime(), args );
}
- catch( Exception e )
+ catch( final Exception e )
{
// it just won't be added as a shutdown hook... :(
}
}
/**
- * Returns <code>true</code> if the specified <code>Process</code> was
- * successfully added to the list of processes to destroy upon VM exit.
+ * Add process to list of processes to be shutdown.
*
* @param process the process to add
- * @return <code>true</code> if the specified <code>Process</code> was
- * successfully added
*/
- public boolean add( Process process )
+ public synchronized void add( final Process process )
{
- processes.add( process );
- return processes.contains( process );
+ if( !m_processes.contains( process ) )
+ {
+ m_processes.add( process );
+ }
}
/**
- * Returns <code>true</code> if the specified <code>Process</code> was
- * successfully removed from the list of processes to destroy upon VM
exit.
+ * Remove process from list of processes to be shutdown.
*
* @param process the process to remove
- * @return <code>true</code> if the specified <code>Process</code> was
- * successfully removed
*/
- public boolean remove( Process process )
+ public synchronized void remove( final Process process )
{
- return processes.remove( process );
+ m_processes.remove( process );
}
/**
* Invoked by the VM when it is exiting.
*/
public void run()
+ {
+ destroyProcesses();
+ }
+
+ protected synchronized void destroyProcesses()
{
- synchronized( processes )
+ final Iterator processes = m_processes.iterator();
+ while( processes.hasNext() )
{
- Iterator e = processes.iterator();
- while( e.hasNext() )
- {
- ( (Process)e.next() ).destroy();
- }
+ ( (Process)processes.next() ).destroy();
+ processes.remove();
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>