Class GridNioServer<T>
- java.lang.Object
-
- org.apache.ignite.internal.util.nio.GridNioServer<T>
-
- Type Parameters:
T- Message type.
public class GridNioServer<T> extends Object
TCP NIO server. Due to asynchronous nature of connections processing network events such as client connection, disconnection and message receiving are passed to the server listener. Once client connected, an associatedGridNioSessionobject is created and can be used in communication.This implementation supports several selectors and several reading threads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGridNioServer.Builder<T>Constructs a new instance ofGridNioServer.
-
Field Summary
Fields Modifier and Type Field Description static intDFLT_IO_BALANCE_PERIODstatic intDFLT_SEND_QUEUE_LIMITDefault send queue limit.static intDFLT_SES_WRITE_TIMEOUTDefault session write timeout.static StringIGNITE_IO_BALANCE_RANDOM_BALANCEstatic StringOUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_DESCstatic StringOUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_NAMEstatic StringRECEIVED_BYTES_METRIC_DESCstatic StringRECEIVED_BYTES_METRIC_NAMEstatic intRECOVERY_DESC_META_KEYSession future meta key.static StringSENT_BYTES_METRIC_DESCstatic StringSENT_BYTES_METRIC_NAMEstatic StringSESSIONS_CNT_METRIC_NAMEThe name of the metric that provides the active TCP sessions count.static StringSSL_ENABLED_METRIC_NAMEThe name of the metric that indicates whether SSL is enabled for the connector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> GridNioServer.Builder<T>builder()Creates and returns a builder for a new instance of this class.GridNioFuture<GridNioSession>cancelConnect(SocketChannel ch, Map<Integer,?> meta)GridNioFuture<Boolean>close(GridNioSession ses)voidcloseFromWorkerThread(GridNioSession ses)GridNioFuture<GridNioSession>createSession(SocketChannel ch, @Nullable Map<Integer,Object> meta, boolean async, @Nullable IgniteInClosure<? super IgniteInternalFuture<GridNioSession>> lsnr)Establishes a session.IgniteInternalFuture<String>dumpNodeStats(String msg, IgnitePredicate<GridNioSession> p)IgniteInternalFuture<String>dumpStats()IgniteInternalFuture<String>dumpStats(String msg, IgnitePredicate<GridNioSession> p)longidleTimeout()Gets configurable idle timeout for this session.voididleTimeout(long idleTimeout)Sets configurable idle timeout for session.InetSocketAddresslocalAddress()Gets the address server is bound to.intoutboundMessagesQueueSize()Gets outbound messages queue size.intport()longreaderMoveCount()voidresend(GridNioSession ses)longselectorSpins()voidsendSystem(GridNioSession ses, Message msg)Adds message at the front of the queue without acquiring back pressure semaphore.voidsendSystem(GridNioSession ses, Message msg, @Nullable IgniteInClosure<? super IgniteInternalFuture<?>> lsnr)Adds message at the front of the queue without acquiring back pressure semaphore.Collection<? extends GridNioSession>sessions()voidstart()Starts all associated threads to perform accept and read activities.voidstop()Stops all threads and releases all resources.StringtoString()List<org.apache.ignite.internal.util.nio.GridNioServer.AbstractNioClientWorker>workers()longwriterMoveCount()longwriteTimeout()Gets configurable write timeout for this session.voidwriteTimeout(long writeTimeout)Sets configurable write timeout for session.
-
-
-
Field Detail
-
IGNITE_IO_BALANCE_RANDOM_BALANCE
public static final String IGNITE_IO_BALANCE_RANDOM_BALANCE
- See Also:
- Constant Field Values
-
DFLT_SES_WRITE_TIMEOUT
public static final int DFLT_SES_WRITE_TIMEOUT
Default session write timeout.- See Also:
- Constant Field Values
-
DFLT_SEND_QUEUE_LIMIT
public static final int DFLT_SEND_QUEUE_LIMIT
Default send queue limit.- See Also:
- Constant Field Values
-
RECOVERY_DESC_META_KEY
public static final int RECOVERY_DESC_META_KEY
Session future meta key.
-
DFLT_IO_BALANCE_PERIOD
public static final int DFLT_IO_BALANCE_PERIOD
-
OUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_NAME
public static final String OUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_NAME
- See Also:
- Constant Field Values
-
OUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_DESC
public static final String OUTBOUND_MESSAGES_QUEUE_SIZE_METRIC_DESC
- See Also:
- Constant Field Values
-
RECEIVED_BYTES_METRIC_NAME
public static final String RECEIVED_BYTES_METRIC_NAME
- See Also:
- Constant Field Values
-
RECEIVED_BYTES_METRIC_DESC
public static final String RECEIVED_BYTES_METRIC_DESC
- See Also:
- Constant Field Values
-
SENT_BYTES_METRIC_NAME
public static final String SENT_BYTES_METRIC_NAME
- See Also:
- Constant Field Values
-
SENT_BYTES_METRIC_DESC
public static final String SENT_BYTES_METRIC_DESC
- See Also:
- Constant Field Values
-
SSL_ENABLED_METRIC_NAME
public static final String SSL_ENABLED_METRIC_NAME
The name of the metric that indicates whether SSL is enabled for the connector.- See Also:
- Constant Field Values
-
SESSIONS_CNT_METRIC_NAME
public static final String SESSIONS_CNT_METRIC_NAME
The name of the metric that provides the active TCP sessions count.- See Also:
- Constant Field Values
-
-
Method Detail
-
readerMoveCount
public long readerMoveCount()
- Returns:
- Number of reader sessions move.
-
writerMoveCount
public long writerMoveCount()
- Returns:
- Number of reader writer move.
-
port
public int port()
- Returns:
- Configured port.
-
builder
public static <T> GridNioServer.Builder<T> builder()
Creates and returns a builder for a new instance of this class.- Returns:
- Builder for new instance.
-
start
public void start()
Starts all associated threads to perform accept and read activities.
-
stop
public void stop()
Stops all threads and releases all resources.
-
localAddress
public InetSocketAddress localAddress()
Gets the address server is bound to.- Returns:
- Address server is bound to.
-
selectorSpins
public long selectorSpins()
- Returns:
- Selector spins.
-
close
public GridNioFuture<Boolean> close(GridNioSession ses)
- Parameters:
ses- Session to close.- Returns:
- Future for operation.
-
closeFromWorkerThread
public void closeFromWorkerThread(GridNioSession ses)
- Parameters:
ses- Session.
-
sendSystem
public void sendSystem(GridNioSession ses, Message msg) throws IgniteCheckedException
Adds message at the front of the queue without acquiring back pressure semaphore.- Parameters:
ses- Session.msg- Message.- Throws:
IgniteCheckedException- If session was closed.
-
sendSystem
public void sendSystem(GridNioSession ses, Message msg, @Nullable @Nullable IgniteInClosure<? super IgniteInternalFuture<?>> lsnr) throws IgniteCheckedException
Adds message at the front of the queue without acquiring back pressure semaphore.- Parameters:
ses- Session.msg- Message.lsnr- Future listener notified from the session thread.- Throws:
IgniteCheckedException- If session was closed.
-
resend
public void resend(GridNioSession ses)
- Parameters:
ses- Session.
-
sessions
public Collection<? extends GridNioSession> sessions()
- Returns:
- Sessions.
-
workers
public List<org.apache.ignite.internal.util.nio.GridNioServer.AbstractNioClientWorker> workers()
- Returns:
- Workers.
-
dumpStats
public IgniteInternalFuture<String> dumpStats()
- Returns:
- Future.
-
dumpStats
public IgniteInternalFuture<String> dumpStats(String msg, IgnitePredicate<GridNioSession> p)
- Parameters:
msg- Message to add.p- Session predicate.- Returns:
- Future.
-
dumpNodeStats
public IgniteInternalFuture<String> dumpNodeStats(String msg, IgnitePredicate<GridNioSession> p)
- Parameters:
msg- Message to add.p- Session predicate.- Returns:
- Future.
-
createSession
public GridNioFuture<GridNioSession> createSession(SocketChannel ch, @Nullable @Nullable Map<Integer,Object> meta, boolean async, @Nullable @Nullable IgniteInClosure<? super IgniteInternalFuture<GridNioSession>> lsnr)
Establishes a session.- Parameters:
ch- Channel to register within the server and create session for.meta- Optional meta for new session.async- Async connection.lsnr- Listener that should be invoked in NIO thread.- Returns:
- Future to get session.
-
cancelConnect
public GridNioFuture<GridNioSession> cancelConnect(SocketChannel ch, Map<Integer,?> meta)
- Parameters:
ch- Channel.meta- Session meta.
-
writeTimeout
public long writeTimeout()
Gets configurable write timeout for this session. If not set, default value isDFLT_SES_WRITE_TIMEOUT.- Returns:
- Write timeout in milliseconds.
-
writeTimeout
public void writeTimeout(long writeTimeout)
Sets configurable write timeout for session.- Parameters:
writeTimeout- Write timeout in milliseconds.
-
idleTimeout
public long idleTimeout()
Gets configurable idle timeout for this session. If not set, default value isConnectorConfiguration.DFLT_IDLE_TIMEOUT.- Returns:
- Idle timeout in milliseconds.
-
idleTimeout
public void idleTimeout(long idleTimeout)
Sets configurable idle timeout for session.- Parameters:
idleTimeout- Idle timeout in milliseconds.
-
outboundMessagesQueueSize
public int outboundMessagesQueueSize()
Gets outbound messages queue size.- Returns:
- Write queue size.
-
-