Class BlinkSession<M>
java.lang.Object
com.tccc.kos.commons.core.service.blink.BlinkSession<M>
- All Implemented Interfaces:
BlinkProtocol
,Runnable
- Direct Known Subclasses:
BinaryMsgSession
Session that sits on top of a connection and implements a particular protocol
as well as the api used to interact with the protocol.
- Since:
- 1.0
- Version:
- 2022-08-30
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
connect()
Called once the session is established after the identity phase.abstract void
Dispatch a message to a handler.Return the remote address of the connection.void
Queue a message to be dispatched in a worker thread.void
run()
Called by a worker thread to dispatch all the messages in the queue.toString()
void
write
(ByteBuffer buf) Write the data in the buffer to the socket.void
write
(ByteBuffer[] bufs) Write the data in the buffers to the socket.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.service.blink.BlinkProtocol
disconnect, getReadBuf, read
-
Constructor Details
-
BlinkSession
public BlinkSession()
-
-
Method Details
-
connect
public void connect()Called once the session is established after the identity phase. The session can do any additional setup now that is is past the identity timeout phase of the protocol. -
write
Write the data in the buffers to the socket. This is an asynchronous operation and the buffers can be queued in the connection waiting for the send queue to empty. The buffers provided to this call should never be modified after calling write().- Parameters:
bufs
- the list of buffers to send to the client
-
write
Write the data in the buffer to the socket. This is an asynchronous operation and the buffer can be queued in the connection waiting for the send queue to empty. The buffer provided to this call should never be modified after calling write().- Parameters:
buf
- the buffer to send to the client
-
queue
Queue a message to be dispatched in a worker thread. This is typically called from read() when a message needs to be passed to a handler that might be long running or block which would then block the main IO thread that called read(). By putting a message into the queue, it will be picked up by a worker thread and then the worker will call dispatch() with the message and the handler can be called without worry that it will impact the main IO thread.- Parameters:
msg
- the message to queue for dispatch
-
run
public void run()Called by a worker thread to dispatch all the messages in the queue. This ensures they are processed in order and minimizes the overhead of processing messages if they burst in faster than we can process them as it skips queuing them in the thread pool. -
dispatch
Dispatch a message to a handler. This will be called for every message placed in the dispatch queue by calling queue(). This will be called by a worker thread from the endpoint thread pool so it can block or be long running. Only one message is dispatched at a time. This means that if a dispatched message blocks, this method will not be called again until the blocked message finally returns. This ensures that messages are dispatched in the order they were received.- Parameters:
msg
- the handler to run in the dispatch thread pool
-
toString
-
getRemoteAddr
Return the remote address of the connection.
-