Modifier and Type | Class and Description |
---|---|
private static class |
Mux.SessionShutdownTask |
Modifier and Type | Field and Description |
---|---|
(package private) static int |
Abort |
(package private) static int |
Abort_partial |
(package private) static int |
Acknowledgment |
(package private) BitSet |
busySessions |
(package private) static int |
CLIENT |
(package private) static int |
ClientConnectionHeader_negotiate |
private boolean |
clientConnectionReady |
(package private) static int |
Close |
private ConnectionIO |
connectionIO |
private ByteBuffer |
currentDataBuffer |
private int |
currentLengthRemaining |
private int |
currentOp |
private int |
currentSessionID |
(package private) static int |
Data |
(package private) static int |
Data_ackRequired |
(package private) static int |
Data_close |
(package private) static int |
Data_eof |
(package private) static int |
Data_open |
private boolean |
directBuffersUseful |
(package private) static int |
Error |
private int |
expectedPingCookie |
(package private) static int |
IncrementRation |
(package private) static int |
IncrementRation_shift |
(package private) int |
initialInboundRation |
(package private) int |
initialOutboundRation |
private static Logger |
logger
mux logger
|
private static byte[] |
magic |
static int |
MAX_REQUESTS |
(package private) static int |
MAX_SESSION_ID |
(package private) int |
maxFragmentSize |
(package private) boolean |
muxDown |
(package private) Throwable |
muxDownCause |
(package private) String |
muxDownMessage |
(package private) Object |
muxLock
lock guarding all mutable instance state (below)
|
(package private) static int |
NoOperation |
(package private) static int |
Ping |
(package private) static int |
PingAck |
private static int |
READ_CLIENT_CONNECTION_HEADER |
private static int |
READ_MESSAGE_BODY |
private static int |
READ_MESSAGE_HEADER |
private static int |
READ_SERVER_CONNECTION_HEADER |
private int |
readState |
private Object |
readStateLock |
(package private) int |
role |
(package private) static int |
SERVER |
(package private) boolean |
serverConnectionReady |
(package private) Map |
sessions |
private static LinkedList |
sessionShutdownQueue
session shutdown tasks to be executed asynchronously
|
(package private) static int |
Shutdown |
private long |
startTimeout |
private static Executor |
systemThreadPool
pool of threads for executing tasks in system thread group:
used for shutting down sessions when a connection goes down
|
private static int |
VERSION |
Constructor and Description |
---|
Mux(OutputStream out,
InputStream in,
int role,
int initialInboundRation,
int maxFragmentSize)
Constructs a new Mux instance for a connection accessible through
standard (blocking) I/O streams.
|
Mux(SocketChannel channel,
int role,
int initialInboundRation,
int maxFragmentSize) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addSession(int sessionID,
Session session)
This method is intended to be invoked by subclasses only.
|
(package private) void |
asyncSendAbort(int op,
int sessionID,
ByteBuffer data)
Sends an Abort message for the specified "sessionID" with the contents
of the specified buffer as the data.
|
(package private) void |
asyncSendAcknowledgment(int sessionID)
Sends an Acknowledgment message for the specified "sessionID".
|
(package private) void |
asyncSendClientConnectionHeader()
Sends the ClientConnectionHeader message for this connection.
|
(package private) void |
asyncSendClose(int sessionID)
Sends a Close message for the specified "sessionID".
|
(package private) void |
asyncSendData(int op,
int sessionID,
ByteBuffer data)
Sends a Data message for the specified "sessionID" with the contents
of the supplied buffer as the data.
|
(package private) void |
asyncSendError(String message)
Sends an Error message with the UTF-8 encoding of the supplied
message as the data.
|
(package private) void |
asyncSendIncrementRation(int sessionID,
int increment)
Sends an IncrementRation message for the specified "sessionID" and
the specified "increment".
|
(package private) void |
asyncSendNoOperation(ByteBuffer buffer)
Sends a NoOperation message with the contents of the supplied buffer
as the data.
|
(package private) void |
asyncSendPing(int cookie)
Sends a Ping message with the specified "cookie".
|
(package private) void |
asyncSendPingAck(int cookie)
Sends a PingAck message with the specified "cookie".
|
(package private) void |
asyncSendServerConnectionHeader()
Sends the ServerConnectionHeader message for this connection.
|
(package private) void |
asyncSendShutdown(String message)
Sends a Shutdown message with the UTF-8 encoding of the supplied
message as the data.
|
(package private) boolean |
directBuffersUseful()
Returns true if it would be useful to pass direct buffers to
this instance's *Send* methods (because the underlying I/O
implementation will pass such buffers directly to channel write
operations); returns false otherwise.
|
private void |
dispatchCurrentMessage() |
(package private) IOFuture |
futureSendData(int op,
int sessionID,
ByteBuffer data)
Sends a Data message for the specified sessionID with the contents
of the supplied buffer as the data.
|
(package private) IOFuture |
futureSendError(String message)
Sends an Error message with the UTF-8 encoding of the supplied
message as the data.
|
private Session |
getSession(int sessionID) |
private static String |
getStringFromUTF8Buffer(ByteBuffer buffer) |
private static ByteBuffer |
getUTF8BufferFromString(String s) |
private void |
handleAbort(int sessionID,
boolean partial,
String message) |
private void |
handleAcknowledgment(int sessionID) |
private void |
handleClose(int sessionID) |
private void |
handleData(int sessionID,
boolean open,
boolean close,
boolean eof,
boolean ackRequired,
ByteBuffer data) |
protected void |
handleDown()
Handles indication that this multiplexed connection has
gone down, either through normal operation or failure.
|
private void |
handleError(String message) |
private void |
handleIncrementRation(int sessionID,
int increment) |
private void |
handleNoOperation() |
(package private) void |
handleOpen(int sessionID)
This method is invoked internally and is intended to be
overridden by subclasses.
|
private void |
handlePing(int cookie) |
private void |
handlePingAck(int cookie) |
private void |
handleShutdown(String message) |
(package private) void |
processIncomingData(ByteBuffer buffer) |
private boolean |
readClientConnectionHeader(ByteBuffer buffer) |
private boolean |
readMessageBody(ByteBuffer buffer) |
private boolean |
readMessageHeader(ByteBuffer buffer) |
private boolean |
readServerConnectionHeader(ByteBuffer buffer) |
(package private) void |
removeSession(int sessionID)
Removes the identified session from the session table.
|
(package private) void |
setDown(String message,
Throwable cause)
This method is intended to be invoked by this class and
subclasses only.
|
void |
setStartTimeout(long timeout)
Time in milliseconds for client-side connections to wait for the server
to acknowledge an opening handshake.
|
void |
start()
Starts I/O processing.
|
private static char |
toHexChar(int x) |
private static String |
toHexString(byte x) |
private static String |
toHexString(byte[] b) |
private static String |
toHexString(int x) |
private void |
validatePartialMagicNumber(ByteBuffer buffer) |
static final int CLIENT
static final int SERVER
static final int MAX_SESSION_ID
public static final int MAX_REQUESTS
static final int NoOperation
static final int Shutdown
static final int Ping
static final int PingAck
static final int Error
static final int IncrementRation
static final int Abort
static final int Close
static final int Acknowledgment
static final int Data
static final int IncrementRation_shift
static final int Abort_partial
static final int Data_open
static final int Data_close
static final int Data_eof
static final int Data_ackRequired
static final int ClientConnectionHeader_negotiate
private static final byte[] magic
private static final int VERSION
private static final Executor systemThreadPool
private static final LinkedList sessionShutdownQueue
private static final Logger logger
final int role
final int initialInboundRation
final int maxFragmentSize
private final ConnectionIO connectionIO
private final boolean directBuffersUseful
final Object muxLock
int initialOutboundRation
private boolean clientConnectionReady
boolean serverConnectionReady
boolean muxDown
String muxDownMessage
Throwable muxDownCause
final BitSet busySessions
final Map sessions
private int expectedPingCookie
private long startTimeout
private static final int READ_CLIENT_CONNECTION_HEADER
private static final int READ_SERVER_CONNECTION_HEADER
private static final int READ_MESSAGE_HEADER
private static final int READ_MESSAGE_BODY
private final Object readStateLock
private int readState
private int currentOp
private int currentSessionID
private int currentLengthRemaining
private ByteBuffer currentDataBuffer
Mux(OutputStream out, InputStream in, int role, int initialInboundRation, int maxFragmentSize) throws IOException
IOException
Mux(SocketChannel channel, int role, int initialInboundRation, int maxFragmentSize) throws IOException
IOException
public void setStartTimeout(long timeout)
This method is not thread-safe. It is expected to be called immediately after a constructor.
timeout
- positive value in millisecondspublic void start() throws IOException
IOException
protected void handleDown()
void handleOpen(int sessionID) throws ProtocolException
ProtocolException
final void addSession(int sessionID, Session session)
final void setDown(String message, Throwable cause)
final void removeSession(int sessionID)
final boolean directBuffersUseful()
final void asyncSendClientConnectionHeader()
final void asyncSendServerConnectionHeader()
final void asyncSendNoOperation(ByteBuffer buffer)
final void asyncSendShutdown(String message)
final void asyncSendPing(int cookie)
final void asyncSendPingAck(int cookie)
final void asyncSendError(String message)
final IOFuture futureSendError(String message)
final void asyncSendIncrementRation(int sessionID, int increment)
final void asyncSendAbort(int op, int sessionID, ByteBuffer data)
final void asyncSendClose(int sessionID)
final void asyncSendAcknowledgment(int sessionID)
final void asyncSendData(int op, int sessionID, ByteBuffer data)
final IOFuture futureSendData(int op, int sessionID, ByteBuffer data)
void processIncomingData(ByteBuffer buffer) throws ProtocolException
ProtocolException
private boolean readClientConnectionHeader(ByteBuffer buffer) throws ProtocolException
ProtocolException
private boolean readServerConnectionHeader(ByteBuffer buffer) throws ProtocolException
ProtocolException
private void validatePartialMagicNumber(ByteBuffer buffer) throws ProtocolException
ProtocolException
private boolean readMessageHeader(ByteBuffer buffer) throws ProtocolException
ProtocolException
private boolean readMessageBody(ByteBuffer buffer) throws ProtocolException
ProtocolException
private void dispatchCurrentMessage() throws ProtocolException
ProtocolException
private void handleNoOperation() throws ProtocolException
ProtocolException
private void handleShutdown(String message) throws ProtocolException
ProtocolException
private void handlePing(int cookie) throws ProtocolException
ProtocolException
private void handlePingAck(int cookie) throws ProtocolException
ProtocolException
private void handleError(String message) throws ProtocolException
ProtocolException
private void handleIncrementRation(int sessionID, int increment) throws ProtocolException
ProtocolException
private void handleAbort(int sessionID, boolean partial, String message) throws ProtocolException
ProtocolException
private void handleClose(int sessionID) throws ProtocolException
ProtocolException
private void handleAcknowledgment(int sessionID) throws ProtocolException
ProtocolException
private void handleData(int sessionID, boolean open, boolean close, boolean eof, boolean ackRequired, ByteBuffer data) throws ProtocolException
ProtocolException
private Session getSession(int sessionID) throws ProtocolException
ProtocolException
private static ByteBuffer getUTF8BufferFromString(String s)
private static String getStringFromUTF8Buffer(ByteBuffer buffer)
private static String toHexString(byte x)
private static String toHexString(int x)
private static String toHexString(byte[] b)
private static char toHexChar(int x)
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.