Class AbstractTaskCoordinator<T>
- java.lang.Object
-
- com.oracle.coherence.concurrent.executor.AbstractTaskCoordinator<T>
-
- Type Parameters:
T- the type of theTask
- All Implemented Interfaces:
Task.Coordinator<T>
- Direct Known Subclasses:
ClusteredTaskCoordinator
public abstract class AbstractTaskCoordinator<T> extends Object implements Task.Coordinator<T>
A base implementation of aTask.Coordinator.- Since:
- 21.12
- Author:
- bo
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBooleanf_cancelledHas theTaskbeen cancelled.protected AtomicBooleanf_closedIs theTask.Coordinatorclosed to accept more subscribers or offers of items.protected ExecutorServicef_executorServiceTheExecutorServicefrom theTaskExecutorServicefor asynchronously publishing items.protected booleanf_fRetainTaskThe flag to indicate whether theTaskis retained.protected Stringf_sTaskIdThe unique identity of theTask.protected Result<T>m_lastValueThe last value offered (that we'll offer to newTask.Subscribers).protected Set<Task.Subscriber<? super T>>m_setSubscribersTheTask.Subscribers to which items will be published.
-
Constructor Summary
Constructors Constructor Description AbstractTaskCoordinator(String taskId, ExecutorService executorService, boolean fRetainTask)Construct anAbstractTaskCoordinator.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Attempts to cancel execution of theTask.voidclose()Closes theAbstractTaskCoordinatorand notifies theTask.Subscribers that there will no longer be any further items by callingTask.Subscriber.onComplete().protected voidcloseSubscriber(Task.Subscriber<? super T> subscriber, boolean fRemove)A helper method to close aTask.Subscriberusing the callingThread.StringgetTaskId()Obtains the unique identity of theTaskbeing coordinated.booleanhasSubscribers()Determine if theAbstractTaskCoordinatorcurrently has anyTask.Subscribers.booleanisCancelled()Returnstrueif theTaskwas cancelled before it completed normally.booleanisDone()Returnstrueif theTaskcompleted.voidoffer(Result<T> item)Offers an item to be asynchronously published to currentTask.Subscribers.voidsubscribe(Task.Subscriber<? super T> subscriber)Subscribes the specifiedTask.Subscriberto theTask.Coordinatorof aTaskto receive collected results.protected abstract voidsubscribeRetainedTask(Task.Subscriber<?> subscriber)Subscribes to a retained task (a task that has completed execution, but it still held in memory).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.oracle.coherence.concurrent.executor.Task.Coordinator
getProperties
-
-
-
-
Field Detail
-
f_executorService
protected final ExecutorService f_executorService
TheExecutorServicefrom theTaskExecutorServicefor asynchronously publishing items.
-
f_fRetainTask
protected final boolean f_fRetainTask
The flag to indicate whether theTaskis retained.
-
f_closed
protected final AtomicBoolean f_closed
Is theTask.Coordinatorclosed to accept more subscribers or offers of items.
-
f_cancelled
protected final AtomicBoolean f_cancelled
Has theTaskbeen cancelled.
-
m_setSubscribers
protected Set<Task.Subscriber<? super T>> m_setSubscribers
TheTask.Subscribers to which items will be published.
-
m_lastValue
protected volatile Result<T> m_lastValue
The last value offered (that we'll offer to newTask.Subscribers).
-
-
Constructor Detail
-
AbstractTaskCoordinator
public AbstractTaskCoordinator(String taskId, ExecutorService executorService, boolean fRetainTask)
Construct anAbstractTaskCoordinator.- Parameters:
taskId-TaskIDexecutorService-ExecutorServiceto use for async notifications toTask.CoordinatorsfRetainTask- whether to retain theTaskafter completion
-
-
Method Detail
-
getTaskId
public String getTaskId()
Description copied from interface:Task.CoordinatorObtains the unique identity of theTaskbeing coordinated.- Specified by:
getTaskIdin interfaceTask.Coordinator<T>- Returns:
- the task identity
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
Description copied from interface:Task.CoordinatorAttempts to cancel execution of theTask. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.After this method returns, subsequent calls to isDone() will always return true. Subsequent calls to isDone() will always return true if this method returned true.
- Specified by:
cancelin interfaceTask.Coordinator<T>- Parameters:
mayInterruptIfRunning-trueif the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
falseif the task could not be cancelled, typically because it has already completed normally;trueotherwise- See Also:
Future.cancel(boolean)
-
isCancelled
public boolean isCancelled()
Description copied from interface:Task.CoordinatorReturnstrueif theTaskwas cancelled before it completed normally.- Specified by:
isCancelledin interfaceTask.Coordinator<T>- Returns:
trueif this task was cancelled before it completed- See Also:
Future.isCancelled()
-
isDone
public boolean isDone()
Description copied from interface:Task.CoordinatorReturnstrueif theTaskcompleted. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will returntrue.- Specified by:
isDonein interfaceTask.Coordinator<T>- Returns:
trueif this task completed- See Also:
Future.isDone()
-
subscribe
public void subscribe(Task.Subscriber<? super T> subscriber)
Description copied from interface:Task.CoordinatorSubscribes the specifiedTask.Subscriberto theTask.Coordinatorof aTaskto receive collected results.If already subscribed, or the attempt to subscribe fails, the
Task.Subscriber.onError(Throwable)method is invoked with anIllegalStateException.- Specified by:
subscribein interfaceTask.Coordinator<T>- Parameters:
subscriber- theTask.Subscriber
-
closeSubscriber
protected void closeSubscriber(Task.Subscriber<? super T> subscriber, boolean fRemove)
A helper method to close aTask.Subscriberusing the callingThread.Closing a
Task.Subscriberinvolves calling eitherTask.Subscriber.onComplete()orTask.Subscriber.onError(Throwable)when an error occurred.- Parameters:
subscriber- theTask.SubscriberfRemove-trueif theTask.Subscribershould additionally be removed from theTask.Coordinator,falseotherwise
-
close
public void close()
Closes theAbstractTaskCoordinatorand notifies theTask.Subscribers that there will no longer be any further items by callingTask.Subscriber.onComplete().
-
hasSubscribers
public boolean hasSubscribers()
Determine if theAbstractTaskCoordinatorcurrently has anyTask.Subscribers.- Returns:
trueif theAbstractTaskCoordinatorhasTask.Subscribers,falseotherwise
-
offer
public void offer(Result<T> item)
Offers an item to be asynchronously published to currentTask.Subscribers.- Parameters:
item- the item
-
subscribeRetainedTask
protected abstract void subscribeRetainedTask(Task.Subscriber<?> subscriber)
Subscribes to a retained task (a task that has completed execution, but it still held in memory).- Parameters:
subscriber- the subscriber- Throws:
IllegalStateException- if there is no task to subscribe to
-
-