blob: 0aa9ef76a96f5db7c5d34c67a8870b384b538479 (
plain) (
tree)
|
|
package org.openslx.taskmanager.api;
/**
* This is what is returned on a status request.
* To return custom data for your task, call {@link AbstractTask#setStatusObject(Object)} from your
* Task.
* This class is serialized entirely, not using the Exposed annotation.
*/
public final class TaskStatus
{
public enum StatusCode
{
TASK_WAITING,
TASK_PROCESSING,
TASK_FINISHED,
TASK_ERROR,
NO_SUCH_INSTANCE,
NO_SUCH_TASK,
NO_SUCH_CONSTRUCTOR,
DUPLICATE_ID,
PARENT_FAILED,
JSON_ERROR
}
/**
* Overall status of the task. Only set by base methods of the AbstractTask class.
*/
protected volatile StatusCode statusCode;
/**
* Custom data a task might want to return on status requests.
*/
private volatile Object data = null;
@SuppressWarnings( "unused" )
private final String id;
/*
* Static members
*/
/**
* Create a single "duplicate id" status we return if trying to launch a task with an id already
* in use.
*/
public static final TaskStatus ts_duplicateId = new TaskStatus( StatusCode.DUPLICATE_ID );
/**
* Create a single "no such constructor" status we return if a task could be found, but not
* instantiated.
*/
public static final TaskStatus ts_noSuchConstructor = new TaskStatus( StatusCode.NO_SUCH_CONSTRUCTOR );
/**
* Create a single "no such task" status we return if a task should be invoked that
* doesn't actually exist.
*/
public static final TaskStatus ts_noSuchTask = new TaskStatus( StatusCode.NO_SUCH_TASK );
/**
* Create a single "no such task" status we return if an action on a task instance is requested
* that doesn't actually exist.
*/
public static final TaskStatus ts_noSuchInstance = new TaskStatus( StatusCode.NO_SUCH_INSTANCE );
/**
* Create a single "parent failed" status we return as status for a task which depends on another
* task, and that other task failed to execute, or failed during execution.
*/
public static final TaskStatus ts_parentFailed = new TaskStatus( StatusCode.PARENT_FAILED );
/**
* Create a single "task waiting" status we return as status for a task that is waiting for
* execution.
*/
public static final TaskStatus ts_waiting = new TaskStatus( StatusCode.TASK_WAITING );
/**
* Create a single "task error" status we can use everywhere.
*/
public static final TaskStatus ts_error = new TaskStatus( StatusCode.TASK_ERROR );
/**
* Create a single "json error" status we can use everywhere.
*/
public static final TaskStatus ts_jsonError = new TaskStatus( StatusCode.JSON_ERROR );
/**
* Create new TaskStatus with given initial status code
* and id.
*
* @param status The status code to initialize the TaskStatus with
* @param id id of task this status belongs to
*/
public TaskStatus( final StatusCode status, final String id )
{
this.statusCode = status;
this.id = id;
}
/**
* Create new TaskStatus with given initial status code.
*
* @param status The status code to initialize the TaskStatus with
*/
public TaskStatus( final StatusCode status )
{
this( status, null );
}
/**
* Get the status code of this TaskStatus
*
* @return
*/
public final StatusCode getStatusCode()
{
return this.statusCode;
}
/**
* Set the custom status data.
*
* @param obj custom status object
*/
protected void setStatusObject( Object obj )
{
this.data = obj;
}
public String getStatusObjectClassName()
{
if ( this.data == null ) return "(null)";
return this.data.getClass().getSimpleName();
}
}
|