org.apache.ignite.internal

## Class GridKernalGatewayImpl

- java.lang.Object
- - org.apache.ignite.internal.GridKernalGatewayImpl

All Implemented Interfaces:
  Serializable, GridKernalGateway

    @GridToStringExclude
    public class GridKernalGatewayImpl
    extends Object
    implements GridKernalGateway, Serializable

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`GridKernalGatewayImpl(String gridName)`

### Method Summary

Methods
`void` `addStopListener(Runnable lsnr)` Adds stop listener.
`GridKernalState` `getState()` Gets current kernal state.
`void` `lightCheck()` Performs light-weight check on the kernal state at the moment of this call.
`void` `readLock()` Should be called on entering every kernal related call originated directly or indirectly via public API.
`void` `readLockAnyway()` Same as `GridKernalGateway.readLock()` but doesn't throw IllegalStateException if grid stop.
`void` `readUnlock()` Should be called on leaving every kernal related call originated directly or indirectly via public API.
`void` `removeStopListener(Runnable lsnr)` Removes previously added stop listener.
`void` `setState(GridKernalState state)` Sets kernal state.
`String` `toString()`
`boolean` `tryWriteLock(long timeout)`
`String` `userStackTrace()` Gets user stack trace through the first call of grid public API.
`void` `writeLock()` This method waits for all current calls to exit and blocks any further `GridKernalGateway.readLock()` calls until `GridKernalGateway.writeUnlock()` method is called.
`void` `writeUnlock()` This method unblocks `GridKernalGateway.writeLock()`.

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

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

### Constructor Detail

#### GridKernalGatewayImpl

    public GridKernalGatewayImpl(String gridName)

Parameters:
  `gridName` - Grid name.

### Method Detail

#### lightCheck

    public void lightCheck()
                    throws IllegalStateException

Performs light-weight check on the kernal state at the moment of this call.

This method should only be used when the kernal state should be checked just once at the beginning of the method and the fact that kernal state can change in the middle of such method's execution should not matter.

For example, when a method returns a constant value its implementation doesn't depend on the kernal being valid throughout its execution. In such case it is enough to check the kernal's state just once at the beginning of this method to provide consistent behavior of the API without incurring overhead of `lock-based` guard methods.

Specified by:
  `lightCheck` in interface `GridKernalGateway`
Throws:
  `IllegalStateException` - Thrown in case when no kernal calls are allowed.

#### readLock

    public void readLock()
                  throws IllegalStateException

Should be called on entering every kernal related call originated directly or indirectly via public API.

This method essentially acquires a read lock and multiple threads can enter the call without blocking.

Specified by:
  `readLock` in interface `GridKernalGateway`
Throws:
  `IllegalStateException` - Thrown in case when no kernal calls are allowed.
See Also:
  `GridKernalGateway.readUnlock()`

#### readLockAnyway

    public void readLockAnyway()

Same as `GridKernalGateway.readLock()` but doesn't throw IllegalStateException if grid stop.

Specified by:
  `readLockAnyway` in interface `GridKernalGateway`

#### readUnlock

    public void readUnlock()

Should be called on leaving every kernal related call originated directly or indirectly via public API.

This method essentially releases the internal read-lock acquired previously by `GridKernalGateway.readLock()` method.

Specified by:
  `readUnlock` in interface `GridKernalGateway`
See Also:
  `GridKernalGateway.readLock()`

#### writeLock

    public void writeLock()

This method waits for all current calls to exit and blocks any further `GridKernalGateway.readLock()` calls until `GridKernalGateway.writeUnlock()` method is called.

This method essentially acquires the internal write lock.

Specified by:
  `writeLock` in interface `GridKernalGateway`

#### tryWriteLock

    public boolean tryWriteLock(long timeout)
                         throws InterruptedException

Specified by:
  `tryWriteLock` in interface `GridKernalGateway`
Parameters:
  `timeout` - Timeout.
Returns:
  `True` if write lock has been acquired.
Throws:
  `InterruptedException` - If interrupted.

#### writeUnlock

    public void writeUnlock()

This method unblocks `GridKernalGateway.writeLock()`.

This method essentially releases internal write lock previously acquired by `GridKernalGateway.writeLock()` method.

Specified by:
  `writeUnlock` in interface `GridKernalGateway`

#### setState

    public void setState(GridKernalState state)

Sets kernal state. Various kernal states drive the logic inside of the gateway.

Specified by:
  `setState` in interface `GridKernalGateway`
Parameters:
  `state` - Kernal state to set.

#### getState

    public GridKernalState getState()

Gets current kernal state.

Specified by:
  `getState` in interface `GridKernalGateway`
Returns:
  Kernal state.

#### addStopListener

    public void addStopListener(Runnable lsnr)

Adds stop listener. Note that the identity set will be used to store listeners for performance reasons. Futures can register a listener to be notified when they need to be internally interrupted.

Specified by:
  `addStopListener` in interface `GridKernalGateway`
Parameters:
  `lsnr` - Listener to add.

#### removeStopListener

    public void removeStopListener(Runnable lsnr)

Removes previously added stop listener.

Specified by:
  `removeStopListener` in interface `GridKernalGateway`
Parameters:
  `lsnr` - Listener to remove.

#### userStackTrace

    public String userStackTrace()

Gets user stack trace through the first call of grid public API.

Specified by:
  `userStackTrace` in interface `GridKernalGateway`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0
Release Date | : March 31 2015