public abstract class Task extends Object implements Comparable<Task>
Future
that monitors it's work via log appenders specific for the
BroadWorksServer sessions in the taskServers list. Tasks also receive TaskEvent
s that are sent on the BroadWorksServers
within the taskServers list.
There is also support for a final action result message that can easily tell the user if the action was successful.Modifier and Type | Field and Description |
---|---|
protected static org.apache.logging.log4j.Logger |
log |
protected String |
name |
protected List<String> |
taskLog |
Constructor and Description |
---|
Task(String name,
BroadWorksServer... broadWorksServers)
Creates a new Task with the provided name and backing BroadWorksServer list.
|
Modifier and Type | Method and Description |
---|---|
void |
addTaskLogListener(TaskLogListener logListener)
Adds a listener for log events for this task.
|
protected void |
close()
Closes the log appenders and unregisters this from the BroadWorksServer event buses.
|
int |
compareTo(Task o) |
void |
finish(String resultMessage)
Finishes the action with the provided result message.
|
void |
finish(TaskStatus finalStatus,
String resultMessage)
Finishes the action with the provided result message.
|
Completion |
getCompletion() |
String |
getName() |
TaskResult |
getResult() |
TaskStatus |
getStatus() |
List<String> |
getTaskLog() |
protected List<BroadWorksServer> |
getTaskServers() |
abstract Completion |
getTaskSpecificCompletion() |
boolean |
isComplete()
Returns if the action thread has ran and completed.
|
void |
logToConsole(Alpaca alpaca)
Sends the Task events to the provided Alpaca console.
|
protected void |
postLogMessage(String logMessage)
Adds a log message for this action.
|
protected Future |
start(ThreadPoolExecutor executorService)
Begins the action with the provided
ExecutorService |
void |
stop(String resultMessage)
Finishes the action with the provided result message.
|
abstract void |
task()
The action that the task performs
|
void |
taskEvent(TaskEvent event) |
TaskResult |
waitForResult()
Waits for the Task to complete and returns the result.
|
protected static final org.apache.logging.log4j.Logger log
protected final String name
public Task(String name, BroadWorksServer... broadWorksServers)
name
- The name of the action. This identifies the process to the user and should be unique.broadWorksServers
- The varargs of backing BroadWorksServers for the action.protected Future start(ThreadPoolExecutor executorService)
ExecutorService
executorService
- The thread pool to run the Task upon.protected void close()
public void logToConsole(Alpaca alpaca)
alpaca
- The alpaca console to log to.public void addTaskLogListener(TaskLogListener logListener)
logListener
- The log listener to add.public boolean isComplete()
public TaskResult waitForResult() throws ExecutionException, InterruptedException
TaskResult
for the action.ExecutionException
- if the computation threw an exceptionInterruptedException
- if the current thread was interrupted while waitingpublic TaskStatus getStatus()
public String getName()
public void stop(String resultMessage)
resultMessage
- The result message.public void finish(String resultMessage)
resultMessage
- The result message.public void finish(TaskStatus finalStatus, String resultMessage)
finalStatus
- The final status.resultMessage
- The result message.public TaskResult getResult()
public Completion getCompletion()
public abstract Completion getTaskSpecificCompletion()
protected List<BroadWorksServer> getTaskServers()
public abstract void task() throws Exception
Exception
protected void postLogMessage(String logMessage)
logMessage
- The log message to add.public void taskEvent(TaskEvent event)
public int compareTo(Task o)
compareTo
in interface Comparable<Task>
Copyright © 2017 ECG. All rights reserved.