public abstract class ImagingTaskProcessor extends Object
| Modifier and Type | Field and Description |
|---|---|
protected int |
freeWorkers
The current number of free workers.
|
protected Object |
lock
A lock used to manipulate the inner state.
|
protected static int |
maxWorkers
The max number of workers.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ImagingTaskProcessor() |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(ImagingTaskProcessorListener listener) |
<T extends ImagingTask> |
cancellPendingTasks(Class<T> taskClass)
Cancels all the pending tasks of the given type.
|
protected void |
changeFreeWorkerCount(int delta) |
int |
getCompletedTaskCount(Class<? extends ImagingTask> taskClass)
Returns the number of completed tasks of the given class.
|
static ImagingTaskProcessor |
getInstance()
Gets the singleton instance of the processor.
|
int |
getMaxWorkers() |
protected ImagingTask |
getNextTask(Serializable workerId,
boolean remoteExecution)
Returns the next pending task to execute.
|
int |
getPendingTaskCount(Class<? extends ImagingTask> taskClass)
Returns the number of pending tasks of the given class.
|
int |
getRunningTaskCount(Class<? extends ImagingTask> taskClass)
Returns the number of running tasks of the given class.
|
Statistics |
getStatistics() |
abstract int |
getWorkerCount() |
abstract Collection<Serializable> |
getWorkerIds() |
abstract boolean |
hasFileAccess()
Returns true if the tasks will be executed in a distributed context
with the support of a distributed file system - that is, if each task
is guaranteed to have a File access to the same set of data.
|
abstract boolean |
isDistributed()
Returns true if the tasks will be executed in a distributed context
(i.e.
|
protected void |
notifyTaskCompleted(ImagingTask task)
Notifies that a task has been completed.
|
<T extends ImagingTask> |
popCompletedTask(Class<T> taskClass)
Pops a completed task out of the list.
|
void |
post(Collection<? extends ImagingTask> tasks)
Posts a new task into the queue.
|
void |
post(ImagingTask task)
Posts a new task into the queue.
|
void |
postWithPriority(Collection<? extends ImagingTask> tasks) |
void |
postWithPriority(ImagingTask task) |
boolean |
processingResourcesAvailable() |
void |
removeListener(ImagingTaskProcessorListener listener) |
static void |
setDefault(Class<? extends ImagingTaskProcessor> defaultClass)
Sets the default implementation of the ImagingTaskProcessor
|
static void |
setMaxWorkers(int maxWorkers)
Sets a limit to the number of concurrent workers.
|
protected static int maxWorkers
protected int freeWorkers
protected final Object lock
public static ImagingTaskProcessor getInstance()
public static void setDefault(Class<? extends ImagingTaskProcessor> defaultClass)
defaultClass - the implementation classpublic static void setMaxWorkers(int maxWorkers)
maxWorkers - the max. number of workerspublic int getMaxWorkers()
public abstract int getWorkerCount()
public abstract Collection<Serializable> getWorkerIds()
public abstract boolean isDistributed()
public abstract boolean hasFileAccess()
public void addListener(ImagingTaskProcessorListener listener)
public void removeListener(ImagingTaskProcessorListener listener)
public boolean processingResourcesAvailable()
public void post(Collection<? extends ImagingTask> tasks)
task - the ImagingTask to postpublic void post(ImagingTask task)
task - the ImagingTask to postpublic void postWithPriority(Collection<? extends ImagingTask> tasks)
task - the ImagingTask to postpublic void postWithPriority(ImagingTask task)
task - the ImagingTasks to postpublic final <T extends ImagingTask> Collection<T> cancellPendingTasks(Class<T> taskClass)
taskClass - the kind of task to remove (null means all)public int getPendingTaskCount(Class<? extends ImagingTask> taskClass)
taskClass - the class of the task (null for any class)public int getRunningTaskCount(Class<? extends ImagingTask> taskClass)
taskClass - the class of the task (null for any class)public int getCompletedTaskCount(Class<? extends ImagingTask> taskClass)
taskClass - the class of the task (null for any class)public <T extends ImagingTask> T popCompletedTask(Class<T> taskClass)
taskClass - the class of the taskNoSuchElementException - if no tasks of the given class
is availablepublic Statistics getStatistics()
protected void changeFreeWorkerCount(int delta)
protected final ImagingTask getNextTask(Serializable workerId, boolean remoteExecution)
protected final void notifyTaskCompleted(ImagingTask task)
Notifies that a task has been completed. The task is removed from the list of running tasks and added into the list of completed tasks. If an ImagingTaskProcessorController has been specified, it is notified too.
This method is able to filter out duplicated tasks (that could occur with some distributed implementations.
It is important that this method blocks until the controller has been invoked - otherwise e.g. the Computer Server implementation could fail, for instance if there are no running tasks and the controller has not been able to post new tasks yet. In this circumstances, the facility erroneously thinks that everything is over and quits.
task - the completed taskCopyright © 2003–2014 Tidalwave s.a.s. (http://tidalwave.it). All rights reserved.