Package org.silverpeas.core.thread.task
Class AbstractRequestTask<C extends AbstractRequestTask.ProcessContext>
- java.lang.Object
-
- org.silverpeas.core.thread.task.AbstractRequestTask<C>
-
- Type Parameters:
C
- the type of the context given to aAbstractRequestTask.Request
processing.
- Direct Known Subclasses:
BackgroundProcessTask
,IndexerTask
,MailSenderTask
,ServerEventDispatcherTask
,WorkflowEngineTask
public abstract class AbstractRequestTask<C extends AbstractRequestTask.ProcessContext> extends Object implements Callable<Void>
Centralizing the management of a thread in charge of processing in the background a batch ofAbstractRequestTask.Request
.
When there is no moreAbstractRequestTask.Request
to perform, the task ends.
When adding a newAbstractRequestTask.Request
to perform, the request is added into a queue and the task is started if it is not running.
Requests are performed one after one.
To add a request to process, useRequestTaskManager.push(Class, Request)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractRequestTask.ProcessContext
The process context given to theAbstractRequestTask.Request.process(Object)
method.
The process context instance is provided bygetProcessContext()
method implementation.static interface
AbstractRequestTask.Request<C>
Each request must define a method called process which will process the request.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractRequestTask()
Nothing is done for now.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterNoMoreRequest()
Invoked when it does not existAbstractRequestTask.Request
to process anymore.Void
call()
Process all the requests.protected C
getProcessContext()
Gets the context given for each request to process.protected int
getRequestQueueLimit()
protected void
processRequest(AbstractRequestTask.Request<C> request)
Processes the given request.
Useful for a task which needs to perform some stuffs around the process.
-
-
-
Method Detail
-
getRequestQueueLimit
protected int getRequestQueueLimit()
- Returns:
- 0 indicates no limit, value greater than 0 will block the threads pushing new request if the limit is reached until there is again possibility to push.
-
getProcessContext
protected C getProcessContext()
Gets the context given for each request to process.- Returns:
- the instance of process context.
-
call
public final Void call() throws Exception
Process all the requests. This method should be private but is already declared public in the base class Thread.- Specified by:
call
in interfaceCallable<C extends AbstractRequestTask.ProcessContext>
- Throws:
Exception
-
processRequest
protected void processRequest(AbstractRequestTask.Request<C> request) throws org.silverpeas.kernel.SilverpeasException
Processes the given request.
Useful for a task which needs to perform some stuffs around the process.- Parameters:
request
- the request to process.- Throws:
org.silverpeas.kernel.SilverpeasException
- on error.
-
afterNoMoreRequest
protected void afterNoMoreRequest()
Invoked when it does not existAbstractRequestTask.Request
to process anymore. Is is called in any case, even if a severe error has been thrown.
-
-