org.sonatype.gshell.console
Class ConsoleTask

java.lang.Object
  extended by org.sonatype.gshell.console.ConsoleTask

public abstract class ConsoleTask
extends Object

Encapsulates a console execute task.

Since:
2.0
Author:
Jason Dillon

Nested Class Summary
static class ConsoleTask.AbortTaskError
          Error thrown to tasks which are asked to {link #abort}.
 
Field Summary
protected static org.slf4j.Logger log
           
 
Constructor Summary
ConsoleTask()
           
 
Method Summary
 void abort()
          Kill the tasks execute thread via Thread.stop().
abstract  boolean doExecute(String input)
          Execute the custom task for the given input.
 boolean execute(String input)
          Execute a task for the given input.
static ConsoleTask get()
          Get the currently running task.
static ConsoleTask get(boolean allowNull)
          Get the currently running task.
 Thread getExecuteThread()
          Get the execution thread of the current task.
 boolean isRunning()
          True if the task is running (ie.
 boolean isStopping()
          True if stop() was invoked.
 void setExecuteThread(Thread thread)
          Set the execution thread of the current task.
 void stop()
          Ask the tasks execute thread to stop via Thread.interrupt().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.slf4j.Logger log
Constructor Detail

ConsoleTask

public ConsoleTask()
Method Detail

isRunning

public boolean isRunning()
True if the task is running (ie. execute(java.lang.String) was invoked).


stop

public void stop()
Ask the tasks execute thread to stop via Thread.interrupt().


isStopping

public boolean isStopping()
True if stop() was invoked.


abort

public void abort()
Kill the tasks execute thread via Thread.stop(). Thread is given a ConsoleTask.AbortTaskError.


execute

public boolean execute(String input)
                throws Exception
Execute a task for the given input.

Parameters:
input - The console input.
Returns:
True to allow the console to continue, false to abort.
Throws:
Exception - The console task failed.

doExecute

public abstract boolean doExecute(String input)
                           throws Exception
Execute the custom task for the given input.

Parameters:
input - The console input.
Returns:
True to allow the console to continue, false to abort.
Throws:
Exception - The console task failed.

setExecuteThread

public void setExecuteThread(Thread thread)
Set the execution thread of the current task. This is used when asking the task to stop or abort.

Parameters:
thread - The new thread considered to be the tasks execute thread.

getExecuteThread

public Thread getExecuteThread()
Get the execution thread of the current task.

Returns:
The tasks execution thread. Null only if the task has completed.

get

public static ConsoleTask get(boolean allowNull)
Get the currently running task.

Parameters:
allowNull - False to throw an IllegalStateException if there is not current task.
Returns:
The current task or null.

get

public static ConsoleTask get()
Get the currently running task.



Copyright © 2008-2011 Sonatype. All Rights Reserved.