org.apache.ignite.internal.util.worker

## Class GridWorker

- java.lang.Object
- - org.apache.ignite.internal.util.worker.GridWorker

All Implemented Interfaces:
  Runnable

Direct Known Subclasses:
  GridCacheDatabaseSharedManager.Checkpointer, GridJobWorker, SchemaOperationWorker

    public abstract class GridWorker
    extends Object
    implements Runnable

Extension to standard `Runnable` interface. Adds proper details to be used with `Executor` implementations. Only for internal use.

### Field Summary

Fields
`protected boolean` `isCancelled` Whether or not this runnable is cancelled.
`protected IgniteLogger` `log` Ignite logger.

### Constructor Summary

Constructors
`protected` `GridWorker(String igniteInstanceName, String name, IgniteLogger log)` Creates new grid worker with given parameters.
`protected` `GridWorker(String igniteInstanceName, String name, IgniteLogger log, GridWorkerListener lsnr)` Creates new grid worker with given parameters.

### Method Summary

Methods
`protected abstract void` `body()` The implementation should provide the execution body for this runnable.
`void` `cancel()` Cancels this runnable interrupting actual runner.
`protected void` `cleanup()` Optional method that will be called after runnable is finished.
`String` `igniteInstanceName()` Gets name of the Ignite instance this runnable belongs to.
`boolean` `isCancelled()` Tests whether or not this runnable is cancelled.
`boolean` `isDone()` Tests whether or not this runnable is finished.
`void` `join()` Joins this runnable.
`String` `name()` Gets this runnable name.
`void` `run()`
`Thread` `runner()`
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### log

    protected final IgniteLogger log

Ignite logger.

#### isCancelled

    protected volatile boolean isCancelled

Whether or not this runnable is cancelled.

### Constructor Detail

#### GridWorker

    protected GridWorker(String igniteInstanceName,
              String name,
              IgniteLogger log,
              @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
              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

#### run

    public final void run()

Specified by:
  `run` in interface `Runnable`

#### body

    protected abstract void body()
                          throws InterruptedException,
                                 IgniteInterruptedCheckedException

The 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

    public Thread runner()

Returns:
  Runner thread.

#### 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 interrupting actual runner.

#### join

    public void join()
              throws InterruptedException

Joins this runnable.

Throws:
  `InterruptedException` - Thrown in case of interruption.

#### isCancelled

    public boolean isCancelled()

Tests whether or not this runnable is cancelled.

Returns:
  `true` if this runnable is cancelled - `false` otherwise.
See Also:
  `Future.isCancelled()`

#### isDone

    public boolean isDone()

Tests whether or not this runnable is finished.

Returns:
  `true` if this runnable is finished - `false` otherwise.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.1.0
Release Date | : July 20 2017