org.apache.ignite.internal.util.nio

## Class GridNioSessionImpl

- java.lang.Object
- - org.apache.ignite.internal.util.nio.GridNioSessionImpl

All Implemented Interfaces:
  GridNioSession

    public class GridNioSessionImpl
    extends Object
    implements GridNioSession

### Constructor Summary

Constructors
Constructor and Description
`GridNioSessionImpl(GridNioFilterChain filterChain, InetSocketAddress locAddr, InetSocketAddress rmtAddr, boolean accepted)`

### Method Summary

Methods
`boolean` `accepted()`
`<T> T` `addMeta(int key, T val)` Adds metadata associated with specified key.
`long` `bytesReceived()` Gets the total count of bytes received since the session was created.
`void` `bytesReceived(int cnt)` Adds given amount ob bytes to the received bytes counter.
`long` `bytesSent()` Gets the total count of bytes sent since the session was created.
`void` `bytesSent(int cnt)` Adds given amount of bytes to the sent bytes counter.
`protected <T> GridNioFilterChain<T>` `chain()`
`GridNioFuture<Boolean>` `close()` Performs a request for asynchronous session close.
`boolean` `closed()`
`long` `closeTime()` If session is closed, this method will return session close time returned by `System.currentTimeMillis()`.
`long` `createTime()` Gets the time when the session was created.
`long` `lastReceiveTime()` Returns the time when last read activity was performed on this session.
`long` `lastSendScheduleTime()` Returns time when last send was scheduled on this session.
`long` `lastSendTime()` Returns time when last send activity was performed on this session.
`InetSocketAddress` `localAddress()` Gets local address of this session.
`<T> T` `meta(int key)` Gets metadata associated with specified key.
`GridNioFuture<?>` `pauseReads()` Pauses reads.
`boolean` `readsPaused()` Checks whether reads are paused.
`void` `readsPaused(boolean readsPaused)`
`GridNioRecoveryDescriptor` `recoveryDescriptor()`
`void` `recoveryDescriptor(GridNioRecoveryDescriptor recoveryDesc)`
`InetSocketAddress` `remoteAddress()` Gets address of remote peer on this session.
`<T> T` `removeMeta(int key)` Removes metadata with the specified key.
`void` `resetSendScheduleTime()` Resets send schedule time to avoid multiple idle notifications.
`GridNioFuture<?>` `resumeReads()` Resumes session reads.
`GridNioFuture<?>` `send(Object msg)` Performs a request for asynchronous data send.
`boolean` `setClosed()` Atomically moves this session into a closed state.
`String` `toString()`

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

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

### Constructor Detail

#### GridNioSessionImpl

    public GridNioSessionImpl(GridNioFilterChain filterChain,
                      @Nullable
                      InetSocketAddress locAddr,
                      @Nullable
                      InetSocketAddress rmtAddr,
                      boolean accepted)

Parameters:
  `filterChain` - Chain.
  `locAddr` - Local address.
  `rmtAddr` - Remote address.
  `accepted` - `True` if this session was initiated from remote host.

### Method Detail

#### send

    public GridNioFuture<?> send(Object msg)

Performs a request for asynchronous data send.

Specified by:
  `send` in interface `GridNioSession`
Parameters:
  `msg` - Message to be sent. This message will be eventually passed in to a parser plugged to the nio server.
Returns:
  Future representing result.

#### resumeReads

    public GridNioFuture<?> resumeReads()

Resumes session reads.

Specified by:
  `resumeReads` in interface `GridNioSession`
Returns:
  Future representing result.

#### pauseReads

    public GridNioFuture<?> pauseReads()

Pauses reads.

Specified by:
  `pauseReads` in interface `GridNioSession`
Returns:
  Future representing result.

#### close

    public GridNioFuture<Boolean> close()

Performs a request for asynchronous session close.

Specified by:
  `close` in interface `GridNioSession`
Returns:
  Future representing result.

#### localAddress

    @Nullable
    public InetSocketAddress localAddress()

Gets local address of this session.

Specified by:
  `localAddress` in interface `GridNioSession`
Returns:
  Local network address or `null` if non-socket communication is used.

#### remoteAddress

    @Nullable
    public InetSocketAddress remoteAddress()

Gets address of remote peer on this session.

Specified by:
  `remoteAddress` in interface `GridNioSession`
Returns:
  Address of remote peer or `null` if non-socket communication is used.

#### bytesSent

    public long bytesSent()

Gets the total count of bytes sent since the session was created.

Specified by:
  `bytesSent` in interface `GridNioSession`
Returns:
  Total count of bytes sent.

#### bytesReceived

    public long bytesReceived()

Gets the total count of bytes received since the session was created.

Specified by:
  `bytesReceived` in interface `GridNioSession`
Returns:
  Total count of bytes received.

#### createTime

    public long createTime()

Gets the time when the session was created.

Specified by:
  `createTime` in interface `GridNioSession`
Returns:
  Time when this session was created returned by `System.currentTimeMillis()`.

#### closeTime

    public long closeTime()

If session is closed, this method will return session close time returned by `System.currentTimeMillis()`. If session is not closed, this method will return `0`.

Specified by:
  `closeTime` in interface `GridNioSession`
Returns:
  Session close time.

#### lastReceiveTime

    public long lastReceiveTime()

Returns the time when last read activity was performed on this session.

Specified by:
  `lastReceiveTime` in interface `GridNioSession`
Returns:
  Lats receive time.

#### lastSendTime

    public long lastSendTime()

Returns time when last send activity was performed on this session.

Specified by:
  `lastSendTime` in interface `GridNioSession`
Returns:
  Last send time.

#### lastSendScheduleTime

    public long lastSendScheduleTime()

Returns time when last send was scheduled on this session.

Specified by:
  `lastSendScheduleTime` in interface `GridNioSession`
Returns:
  Last send schedule time.

#### meta

    public <T> T meta(int key)

Gets metadata associated with specified key.

Specified by:
  `meta` in interface `GridNioSession`
Parameters:
  `key` - Key to look up.
Returns:
  Associated meta object or `null` if meta was not found.

#### addMeta

    public <T> T addMeta(int key,
                @Nullable
                T val)

Adds metadata associated with specified key.

Specified by:
  `addMeta` in interface `GridNioSession`
Parameters:
  `key` - Metadata Key.
  `val` - Metadata value.
Returns:
  Previously associated object or `null` if no objects were associated.

#### removeMeta

    public <T> T removeMeta(int key)

Removes metadata with the specified key.

Specified by:
  `removeMeta` in interface `GridNioSession`
Parameters:
  `key` - Metadata key.
Returns:
  Object that was associated with the key or `null`.

#### accepted

    public boolean accepted()

Specified by:
  `accepted` in interface `GridNioSession`
Returns:
  `True` if this connection was initiated from remote node.

#### chain

    protected <T> GridNioFilterChain<T> chain()

Type Parameters:
  `T` - Chain type.
Returns:
  Filter chain.

#### bytesSent

    public void bytesSent(int cnt)

Adds given amount of bytes to the sent bytes counter.

Note that this method is designed to be called in one thread only.

Parameters:
  `cnt` - Number of bytes sent.

#### bytesReceived

    public void bytesReceived(int cnt)

Adds given amount ob bytes to the received bytes counter.

Note that this method is designed to be called in one thread only.

Parameters:
  `cnt` - Number of bytes received.

#### resetSendScheduleTime

    public void resetSendScheduleTime()

Resets send schedule time to avoid multiple idle notifications.

#### setClosed

    public boolean setClosed()

Atomically moves this session into a closed state.

Returns:
  `True` if session was moved to a closed state, `false` if session was already closed.

#### closed

    public boolean closed()

Returns:
  `True` if this session was closed.

#### readsPaused

    public void readsPaused(boolean readsPaused)

Parameters:
  `readsPaused` - New reads paused flag.

#### readsPaused

    public boolean readsPaused()

Description copied from interface: `GridNioSession`
Checks whether reads are paused.

Specified by:
  `readsPaused` in interface `GridNioSession`
Returns:
  Reads paused flag.

#### recoveryDescriptor

    public void recoveryDescriptor(GridNioRecoveryDescriptor recoveryDesc)

Specified by:
  `recoveryDescriptor` in interface `GridNioSession`
Parameters:
  `recoveryDesc` - Recovery descriptor.

#### recoveryDescriptor

    @Nullable
    public GridNioRecoveryDescriptor recoveryDescriptor()

Specified by:
  `recoveryDescriptor` in interface `GridNioSession`
Returns:
  Recovery descriptor if recovery is supported, `null otherwise.`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0.final
Release Date | : December 29 2015