org.zeroturnaround.process
Class AbstractProcess

java.lang.Object
  extended by org.zeroturnaround.process.AbstractProcess
All Implemented Interfaces:
SystemProcess
Direct Known Subclasses:
CompositeProcess, JavaProcess, PollingProcess

public abstract class AbstractProcess
extends Object
implements SystemProcess

Base implementation of the process.


Field Summary
protected  org.slf4j.Logger log
           
 
Constructor Summary
AbstractProcess()
           
 
Method Summary
abstract  void destroy(boolean forceful)
          Destroys the process handled by this killer either forcefully or gracefully according to the given option.
 AbstractProcess destroyForcefully()
          Kills the process handled by this killer.
 AbstractProcess destroyGracefully()
          Terminates the process handled by this killer.
protected abstract  String getDescription()
          Returns the description of the system process represented.
 String toString()
           
 boolean waitFor(long timeout, TimeUnit unit)
          Causes the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified waiting time elapses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zeroturnaround.process.SystemProcess
isAlive, waitFor
 

Field Detail

log

protected final org.slf4j.Logger log
Constructor Detail

AbstractProcess

public AbstractProcess()
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getDescription

protected abstract String getDescription()
Returns the description of the system process represented.

Returns:
the description of the system process represented.

waitFor

public boolean waitFor(long timeout,
                       TimeUnit unit)
                throws InterruptedException
Causes the current thread to wait, if necessary, until the process handled by this killer has terminated, or the specified waiting time elapses.

If the process has already terminated then this method returns immediately with the value true. If the process has not terminated and the timeout value is less than, or equal to, zero, then this method returns immediately with the value false.

Specified by:
waitFor in interface SystemProcess
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the process has exited and false if the waiting time elapsed before the process has exited.
Throws:
InterruptedException

destroyGracefully

public AbstractProcess destroyGracefully()
                                  throws IOException,
                                         InterruptedException,
                                         UnsupportedOperationException
Terminates the process handled by this killer. The process is gracefully terminated (like kill -TERM does).

Note: The process may not terminate at all. i.e. isAlive() may return true for a any period after destroyGracefully() is called. This method may be chained to waitFor() if needed.

No error is thrown if the process was already terminated.

Specified by:
destroyGracefully in interface SystemProcess
Returns:
this killer object.
Throws:
UnsupportedOperationException - if this killer object is unable to gracefully terminate any process.
IOException
InterruptedException

destroyForcefully

public AbstractProcess destroyForcefully()
                                  throws IOException,
                                         InterruptedException,
                                         UnsupportedOperationException
Kills the process handled by this killer. The process is forcibly terminated (like kill -KILL does).

Note: The process may not terminate immediately. i.e. isAlive() may return true for a brief period after destroyForcefully() is called. This method may be chained to waitFor() if needed.

No error is thrown if the process was already terminated.

Specified by:
destroyForcefully in interface SystemProcess
Returns:
this killer object.
Throws:
UnsupportedOperationException - if this killer object is unable to forcibly terminate any process.
IOException
InterruptedException

destroy

public abstract void destroy(boolean forceful)
                      throws IOException,
                             InterruptedException
Destroys the process handled by this killer either forcefully or gracefully according to the given option.

Note: The process may not terminate at all. i.e. isAlive() may return true for a any period after destroy() is called. This method may be chained to waitFor() if needed.

No error is thrown if the process was already terminated.

Parameters:
forceful - true if the process must be destroyed forcefully (like kill -KILL), false if it must be destroyed gracefully (like kill -TERM).
Throws:
UnsupportedOperationException - if this killer object is unable to destroy any process with this forceful value.
IOException
InterruptedException


Copyright © 2015 ZeroTurnaround. All rights reserved.