You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2001/12/23 04:42:18 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec ProcessDestroyer.java
donaldp 01/12/22 19:42:18
Added: proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec
ProcessDestroyer.java
Log:
MOve ProcessDestroyer into myrmidon hierarchy
Revision Changes Path
1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/ProcessDestroyer.java
Index: ProcessDestroyer.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* 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.txt file.
*/
package org.apache.myrmidon.framework.exec;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Destroys all registered <code>Process</code>es when
* the VM exits (if in JDK1.3) or when requested.
*
* @author <a href="mailto:mnewcomb@tacintel.com">Michael Newcomb</a>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2001/12/23 03:42:18 $
*/
public class ProcessDestroyer
extends Thread
{
private ArrayList m_processes = new ArrayList();
/**
* Constructs a <code>ProcessDestroyer</code> and registers it as a shutdown
* hook.
*/
public ProcessDestroyer()
{
try
{
// check to see if the method exists (support pre-JDK 1.3 VMs)
//
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( final Exception e )
{
// it just won't be added as a shutdown hook... :(
}
}
/**
* Add process to list of processes to be shutdown.
*
* @param process the process to add
*/
public synchronized void add( final Process process )
{
if( !m_processes.contains( process ) )
{
m_processes.add( process );
}
}
/**
* Remove process from list of processes to be shutdown.
*
* @param process the process to remove
*/
public synchronized void remove( final Process process )
{
m_processes.remove( process );
}
/**
* Invoked by the VM when it is exiting.
*/
public void run()
{
destroyProcesses();
}
protected synchronized void destroyProcesses()
{
final Iterator processes = m_processes.iterator();
while( processes.hasNext() )
{
( (Process)processes.next() ).destroy();
processes.remove();
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>