Class GridWorker
- java.lang.Object
-
- org.apache.ignite.internal.util.worker.GridWorker
-
- All Implemented Interfaces:
Runnable,WorkProgressDispatcher
- Direct Known Subclasses:
Checkpointer,CommunicationWorker,DmsDataWriterWorker,FileHandleManagerImpl.WALWriter,GridJobWorker,GridTaskWorker,SchemaIndexCachePartitionWorker,SchemaOperationWorker,StripedExecutor.Stripe
public abstract class GridWorker extends Object implements Runnable, WorkProgressDispatcher
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBooleanisCancelledWhether or not this runnable is cancelled.protected IgniteLoggerlogIgnite logger.
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridWorker(@Nullable String igniteInstanceName, String name, IgniteLogger log)Creates new grid worker with given parameters.protectedGridWorker(String igniteInstanceName, String name, IgniteLogger log, @Nullable GridWorkerListener lsnr)Creates new grid worker with given parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidblockingSectionBegin()Protects the worker from timeout penalties if subsequent instructions in the calling thread does not update heartbeat timestamp timely, e.g. due to blocking operations, up to the nearestWorkProgressDispatcher.blockingSectionEnd()call.voidblockingSectionEnd()Closes the protection section previously opened byWorkProgressDispatcher.blockingSectionBegin().protected abstract voidbody()The implementation should provide the execution body for this runnable.voidcancel()Cancels this runnable.protected voidcleanup()Optional method that will be called after runnable is finished.longheartbeatTs()Last heatbeat timestamp.StringigniteInstanceName()Gets name of the Ignite instance this runnable belongs to.booleanisCancelled()Tests whether or not this runnable is cancelled.booleanisDone()Tests whether or not this runnable is finished.voidjoin()Joins this runnable.Stringname()Gets this runnable name.protected voidonCancel(boolean firstCancelRequest)Callback on runner cancellation.protected voidonCancelledBeforeWorkerScheduled()Callback on special case, when task is cancelled before is has been scheduled.protected voidonIdle()Can be called fromrunner()thread to perform idleness handling.voidrun()@Nullable Threadrunner()StringtoString()voidupdateHeartbeat()Notifying dispatcher that work is in progress and thread didn't freeze.
-
-
-
Field Detail
-
log
protected final IgniteLogger log
Ignite logger.
-
isCancelled
protected final AtomicBoolean isCancelled
Whether or not this runnable is cancelled.
-
-
Constructor Detail
-
GridWorker
protected GridWorker(String igniteInstanceName, String name, IgniteLogger log, @Nullable @Nullable GridWorkerListener lsnr)
Creates new grid worker with given parameters.- Parameters:
igniteInstanceName- Name of the Ignite instance this runnable is used in.name- Worker name. Note that in general thread name and worker (runnable) name are two different things. The same worker can be executed by multiple threads and therefore for logging and debugging purposes we separate the two.log- Grid logger to be used.lsnr- Listener for life-cycle events.
-
GridWorker
protected GridWorker(@Nullable @Nullable String igniteInstanceName, String name, IgniteLogger log)Creates new grid worker with given parameters.- Parameters:
igniteInstanceName- Name of the Ignite instance this runnable is used in.name- Worker name. Note that in general thread name and worker (runnable) name are two different things. The same worker can be executed by multiple threads and therefore for logging and debugging purposes we separate the two.log- Grid logger to be used.
-
-
Method Detail
-
body
protected abstract void body() throws InterruptedException, IgniteInterruptedCheckedExceptionThe implementation should provide the execution body for this runnable.- Throws:
InterruptedException- Thrown in case of interruption.IgniteInterruptedCheckedException- If interrupted.
-
cleanup
protected void cleanup()
Optional method that will be called after runnable is finished. Default implementation is no-op.
-
runner
@Nullable public @Nullable Thread runner()
- Returns:
- Runner thread,
nullif the worker has not yet started executing.
-
igniteInstanceName
public String igniteInstanceName()
Gets name of the Ignite instance this runnable belongs to.- Returns:
- Name of the Ignite instance this runnable belongs to.
-
name
public String name()
Gets this runnable name.- Returns:
- This runnable name.
-
cancel
public void cancel()
Cancels this runnable.
-
join
public void join() throws InterruptedExceptionJoins this runnable.- Throws:
InterruptedException- Thrown in case of interruption.
-
isCancelled
public boolean isCancelled()
Tests whether or not this runnable is cancelled.- Returns:
trueif this runnable is cancelled -falseotherwise.- See Also:
Future.isCancelled()
-
isDone
public boolean isDone()
Tests whether or not this runnable is finished.- Returns:
trueif this runnable is finished -falseotherwise.
-
heartbeatTs
public long heartbeatTs()
Last heatbeat timestamp.- Specified by:
heartbeatTsin interfaceWorkProgressDispatcher
-
updateHeartbeat
public void updateHeartbeat()
Notifying dispatcher that work is in progress and thread didn't freeze.- Specified by:
updateHeartbeatin interfaceWorkProgressDispatcher
-
blockingSectionBegin
public void blockingSectionBegin()
Protects the worker from timeout penalties if subsequent instructions in the calling thread does not update heartbeat timestamp timely, e.g. due to blocking operations, up to the nearestWorkProgressDispatcher.blockingSectionEnd()call. Nested calls are not supported.- Specified by:
blockingSectionBeginin interfaceWorkProgressDispatcher
-
blockingSectionEnd
public void blockingSectionEnd()
Closes the protection section previously opened byWorkProgressDispatcher.blockingSectionBegin().- Specified by:
blockingSectionEndin interfaceWorkProgressDispatcher
-
onIdle
protected void onIdle()
Can be called fromrunner()thread to perform idleness handling.
-
onCancel
protected void onCancel(boolean firstCancelRequest)
Callback on runner cancellation.- Parameters:
firstCancelRequest- Flag indicating that worker cancellation was requested for the first time.
-
onCancelledBeforeWorkerScheduled
protected void onCancelledBeforeWorkerScheduled()
Callback on special case, when task is cancelled before is has been scheduled.
-
-