Class TaskDispatcher
- java.lang.Object
-
- org.forgerock.openam.cts.impl.queue.TaskDispatcher
-
@Singleton public class TaskDispatcher extends Object
TaskDispatcher operates as the coordinator of asynchronous task processing in the CTS persistence layer. It does so by mapping the creation of tasks to be performed to a method of processing those tasks. The intention is to decouple the caller from the storage mechanism to ensure high throughput and independence from the storage layer. The TaskDispatcher is unaware of theTaskExecutorimplementation that will be used to dispatch tasks to perform.- See Also:
TaskExecutor,Task
-
-
Constructor Summary
Constructors Constructor Description TaskDispatcher(TaskFactory taskFactory, TaskExecutor taskExecutor)Create a default instance of the TaskDispatcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcontinuousQuery(ContinuousQueryListener listener, TokenFilter tokenFilter)Perform a continuous query against the persistent store and signal the results to the providedContinuousQueryListener.voidcreate(Token token, org.forgerock.util.Options options, ResultHandler<Token,?> handler)The CTS Token to create in the persistent store.voiddelete(String tokenId, ResultHandler<PartialToken,?> handler)The Token ID to delete from the persistent store.voiddelete(String tokenId, org.forgerock.util.Options options, ResultHandler<PartialToken,?> handler)The Token ID, for a specific revision of the token, to delete from the persistent store.voidpartialQuery(TokenFilter tokenFilter, ResultHandler<Collection<PartialToken>,?> handler)Perform a query against the persistent store and signal the results to the provided ResultHandler.voidquery(TokenFilter tokenFilter, ResultHandler<Collection<Token>,?> handler)Perform a query against the persistent store and signal the results to the provided ResultHandler.voidread(String tokenId, org.forgerock.util.Options options, ResultHandler<Token,?> handler)The CTS Token to read from the persistent store.voidremoveContinuousQueryListener(ContinuousQueryListener listener, TokenFilter tokenFilter)Removes the suppliedContinuousQueryListenerfrom the query which is operating the suppliedTokenFilter.voidstartDispatcher()Start the dispatcher.voidstopContinuousQuery(TokenFilter tokenFilter)Stops aContinuousQueryhaving removed all itsContinuousQueryListeners.voidupdate(Token token, org.forgerock.util.Options options, ResultHandler<Token,?> handler)The CTS Token to update in the persistent store.
-
-
-
Constructor Detail
-
TaskDispatcher
@Inject public TaskDispatcher(TaskFactory taskFactory, TaskExecutor taskExecutor)
Create a default instance of the TaskDispatcher.- Parameters:
taskFactory- Required to create Task instances.taskExecutor- Required for execution of the tasks.
-
-
Method Detail
-
startDispatcher
public void startDispatcher()
Start the dispatcher. Synchronized to ensure that the taskExecutor is not started multiple times in parallel.
-
create
public void create(Token token, org.forgerock.util.Options options, ResultHandler<Token,?> handler) throws CoreTokenException
The CTS Token to create in the persistent store.- Parameters:
token- Non null token to create.options- Non null Options for the operation.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- See Also:
TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
read
public void read(String tokenId, org.forgerock.util.Options options, ResultHandler<Token,?> handler) throws CoreTokenException
The CTS Token to read from the persistent store. The provided ResultHandler will be notified when the read has been completed.- Parameters:
tokenId- Non null Token ID.options- Non null Options for the operation.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was a problem adding the task to the queue.- See Also:
ResultHandler,TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
update
public void update(Token token, org.forgerock.util.Options options, ResultHandler<Token,?> handler) throws CoreTokenException
The CTS Token to update in the persistent store.- Parameters:
token- Non null Token.options- Non null Options for the operation.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was a problem adding the task to the queue.- See Also:
TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
delete
public void delete(String tokenId, ResultHandler<PartialToken,?> handler) throws CoreTokenException
The Token ID to delete from the persistent store.- Parameters:
tokenId- Non null Token ID.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was an unexpected error during processing.IllegalArgumentException- If tokenId was null.- See Also:
TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
delete
public void delete(String tokenId, org.forgerock.util.Options options, ResultHandler<PartialToken,?> handler) throws CoreTokenException
The Token ID, for a specific revision of the token, to delete from the persistent store.- Parameters:
tokenId- Non null Token ID.options- Non null Options for the operation.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was an unexpected error during processing.IllegalArgumentException- If tokenId was null.- See Also:
TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
query
public void query(TokenFilter tokenFilter, ResultHandler<Collection<Token>,?> handler) throws CoreTokenException
Perform a query against the persistent store and signal the results to the provided ResultHandler. Note: Because a query has no associated Token ID, this function will select a random queue to place theQueryTaskon. There is no guarantee that multiple query operations will be performed by the sameSeriesTaskExecutorThread.- Parameters:
tokenFilter- Non null TokenFilter.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was a problem adding the task to the queue.- See Also:
ResultHandler,TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
partialQuery
public void partialQuery(TokenFilter tokenFilter, ResultHandler<Collection<PartialToken>,?> handler) throws CoreTokenException
Perform a query against the persistent store and signal the results to the provided ResultHandler. Note: Because a query has no associated Token ID, this function will select a random queue to place thePartialQueryTaskon. There is no guarantee that multiple query operations will be performed by the sameSeriesTaskExecutorThread.- Parameters:
tokenFilter- Non null TokenFilter.handler- Non null ResultHandler to notify.- Throws:
CoreTokenException- If there was a problem adding the task to the queue.- See Also:
ResultHandler,TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
continuousQuery
public void continuousQuery(ContinuousQueryListener listener, TokenFilter tokenFilter) throws CoreTokenException
Perform a continuous query against the persistent store and signal the results to the providedContinuousQueryListener. If aContinuousQueryalready exists for the providedTokenFilterthis method will simply add the listener to that query. Note: Because a continuous query has no associated Token ID, this function will select a random queue to place theQueryTaskon. There is no guarantee that multiple continuous query operations will be performed by the sameSeriesTaskExecutorThread.- Parameters:
listener- Non null ResultHandler to notify.tokenFilter- Non null TokenFilter.- Throws:
CoreTokenException- If there was a problem adding the task to the queue.- See Also:
ContinuousQueryListener,TaskDispatcher,CTSQueueConfiguration.getQueueTimeout()
-
removeContinuousQueryListener
public void removeContinuousQueryListener(ContinuousQueryListener listener, TokenFilter tokenFilter)
Removes the suppliedContinuousQueryListenerfrom the query which is operating the suppliedTokenFilter. A continuous query that has no listeners will NOT be stopped, and may have further listeners added to it later.- Parameters:
listener- Non null ResultHandler to notify.tokenFilter- Non null TokenFilter.- See Also:
ContinuousQueryListener,TaskDispatcher
-
stopContinuousQuery
public void stopContinuousQuery(TokenFilter tokenFilter)
Stops aContinuousQueryhaving removed all itsContinuousQueryListeners. If no query exists for the filter this method performs no action.- Parameters:
tokenFilter- Non null TokenFilter.
-
-