@NotThreadSafe class InternalStreamConnection extends java.lang.Object implements InternalConnection
Modifier and Type | Class and Description |
---|---|
private class |
InternalStreamConnection.CommandEventSender |
private static class |
InternalStreamConnection.LazyCommandDocument |
private class |
InternalStreamConnection.MessageHeaderCallback |
Modifier and Type | Field and Description |
---|---|
private CommandListener |
commandListener |
private java.util.List<MongoCompressor> |
compressorList |
private java.util.Map<java.lang.Byte,Compressor> |
compressorMap |
private InternalConnectionInitializer |
connectionInitializer |
private ConnectionDescription |
description |
private java.util.concurrent.atomic.AtomicBoolean |
isClosed |
private static Logger |
LOGGER |
private java.util.concurrent.atomic.AtomicBoolean |
opened |
private static java.util.Set<java.lang.String> |
SECURITY_SENSITIVE_COMMANDS |
private Compressor |
sendCompressor |
private ServerId |
serverId |
private Stream |
stream |
private StreamFactory |
streamFactory |
Constructor and Description |
---|
InternalStreamConnection(ServerId serverId,
StreamFactory streamFactory,
java.util.List<MongoCompressor> compressorList,
CommandListener commandListener,
InternalConnectionInitializer connectionInitializer) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection.
|
private Compressor |
createCompressor(MongoCompressor mongoCompressor) |
private java.util.Map<java.lang.Byte,Compressor> |
createCompressorMap(java.util.List<MongoCompressor> compressorList) |
private Compressor |
findSendCompressor(ConnectionDescription description) |
ByteBuf |
getBuffer(int size)
Gets a buffer with the givens capacity.
|
private Compressor |
getCompressor(CompressedHeader compressedHeader) |
ConnectionDescription |
getDescription()
Gets the description of this connection.
|
private ConnectionId |
getId() |
private static <T extends BsonDocument> |
getResponseDocument(ResponseBuffers responseBuffers,
int messageId,
Decoder<T> decoder) |
private ServerAddress |
getServerAddress() |
boolean |
isClosed()
Returns the closed state of the connection
|
void |
open()
Opens the connection so its ready for use
|
void |
openAsync(SingleResultCallback<java.lang.Void> callback)
Opens the connection so its ready for use
|
boolean |
opened()
Returns if the connection has been opened
|
private void |
readAsync(int numBytes,
SingleResultCallback<ByteBuf> callback) |
private <T> T |
receiveCommandMessageResponse(CommandMessage message,
Decoder<T> decoder,
InternalStreamConnection.CommandEventSender commandEventSender,
SessionContext sessionContext) |
ResponseBuffers |
receiveMessage(int responseTo)
Receive a response to a sent message from the server.
|
void |
receiveMessageAsync(int responseTo,
SingleResultCallback<ResponseBuffers> callback)
Asynchronously receive a response to a sent message from the server.
|
private ResponseBuffers |
receiveResponseBuffers() |
<T> T |
sendAndReceive(CommandMessage message,
Decoder<T> decoder,
SessionContext sessionContext)
Send a command message to the server.
|
<T> void |
sendAndReceiveAsync(CommandMessage message,
Decoder<T> decoder,
SessionContext sessionContext,
SingleResultCallback<T> callback)
Send a command message to the server.
|
private void |
sendCommandMessage(CommandMessage message,
InternalStreamConnection.LazyCommandDocument lazyCommandDocument,
ByteBufferBsonOutput bsonOutput,
SessionContext sessionContext) |
private <T> void |
sendCommandMessageAsync(int messageId,
Decoder<T> decoder,
SessionContext sessionContext,
SingleResultCallback<T> callback,
ByteBufferBsonOutput bsonOutput,
InternalStreamConnection.CommandEventSender commandEventSender,
boolean responseExpected) |
void |
sendMessage(java.util.List<ByteBuf> byteBuffers,
int lastRequestId)
Send a message to the server.
|
void |
sendMessageAsync(java.util.List<ByteBuf> byteBuffers,
int lastRequestId,
SingleResultCallback<java.lang.Void> callback)
Asynchronously send a message to the server.
|
private MongoException |
translateReadException(java.lang.Throwable e) |
private MongoException |
translateWriteException(java.lang.Throwable e) |
private void |
updateSessionContext(SessionContext sessionContext,
ResponseBuffers responseBuffers) |
private void |
writeAsync(java.util.List<ByteBuf> byteBuffers,
SingleResultCallback<java.lang.Void> callback) |
private static final java.util.Set<java.lang.String> SECURITY_SENSITIVE_COMMANDS
private static final Logger LOGGER
private final ServerId serverId
private final StreamFactory streamFactory
private final InternalConnectionInitializer connectionInitializer
private volatile ConnectionDescription description
private volatile Stream stream
private final java.util.concurrent.atomic.AtomicBoolean isClosed
private final java.util.concurrent.atomic.AtomicBoolean opened
private final java.util.List<MongoCompressor> compressorList
private final CommandListener commandListener
private volatile Compressor sendCompressor
private volatile java.util.Map<java.lang.Byte,Compressor> compressorMap
InternalStreamConnection(ServerId serverId, StreamFactory streamFactory, java.util.List<MongoCompressor> compressorList, CommandListener commandListener, InternalConnectionInitializer connectionInitializer)
public ConnectionDescription getDescription()
InternalConnection
getDescription
in interface InternalConnection
public void open()
InternalConnection
open
in interface InternalConnection
public void openAsync(SingleResultCallback<java.lang.Void> callback)
InternalConnection
openAsync
in interface InternalConnection
callback
- the callback to be called once the connection has been openedprivate java.util.Map<java.lang.Byte,Compressor> createCompressorMap(java.util.List<MongoCompressor> compressorList)
private Compressor findSendCompressor(ConnectionDescription description)
private Compressor createCompressor(MongoCompressor mongoCompressor)
public void close()
InternalConnection
close
in interface InternalConnection
public boolean opened()
InternalConnection
opened
in interface InternalConnection
public boolean isClosed()
InternalConnection
isClosed
in interface InternalConnection
public <T> T sendAndReceive(CommandMessage message, Decoder<T> decoder, SessionContext sessionContext)
InternalConnection
sendAndReceive
in interface InternalConnection
message
- the command message to sendsessionContext
- the session contextprivate void sendCommandMessage(CommandMessage message, InternalStreamConnection.LazyCommandDocument lazyCommandDocument, ByteBufferBsonOutput bsonOutput, SessionContext sessionContext)
private <T> T receiveCommandMessageResponse(CommandMessage message, Decoder<T> decoder, InternalStreamConnection.CommandEventSender commandEventSender, SessionContext sessionContext)
public <T> void sendAndReceiveAsync(CommandMessage message, Decoder<T> decoder, SessionContext sessionContext, SingleResultCallback<T> callback)
InternalConnection
sendAndReceiveAsync
in interface InternalConnection
message
- the command message to sendsessionContext
- the session contextcallback
- the callbackprivate <T> void sendCommandMessageAsync(int messageId, Decoder<T> decoder, SessionContext sessionContext, SingleResultCallback<T> callback, ByteBufferBsonOutput bsonOutput, InternalStreamConnection.CommandEventSender commandEventSender, boolean responseExpected)
public void sendMessage(java.util.List<ByteBuf> byteBuffers, int lastRequestId)
InternalConnection
sendMessage
in interface InternalConnection
byteBuffers
- the list of byte buffers to send.lastRequestId
- the request id of the last message in byteBufferspublic ResponseBuffers receiveMessage(int responseTo)
InternalConnection
receiveMessage
in interface InternalConnection
responseTo
- the request id that this message is a response topublic void sendMessageAsync(java.util.List<ByteBuf> byteBuffers, int lastRequestId, SingleResultCallback<java.lang.Void> callback)
InternalConnection
sendMessageAsync
in interface InternalConnection
byteBuffers
- the list of byte buffers to sendlastRequestId
- the request id of the last message in byteBufferscallback
- the callback to invoke on completionprivate void writeAsync(java.util.List<ByteBuf> byteBuffers, SingleResultCallback<java.lang.Void> callback)
public void receiveMessageAsync(int responseTo, SingleResultCallback<ResponseBuffers> callback)
InternalConnection
receiveMessageAsync
in interface InternalConnection
responseTo
- the request id that this message is a response tocallback
- the callback to invoke on completionprivate void readAsync(int numBytes, SingleResultCallback<ByteBuf> callback)
private ConnectionId getId()
private ServerAddress getServerAddress()
private void updateSessionContext(SessionContext sessionContext, ResponseBuffers responseBuffers)
private MongoException translateWriteException(java.lang.Throwable e)
private MongoException translateReadException(java.lang.Throwable e)
private ResponseBuffers receiveResponseBuffers() throws java.io.IOException
java.io.IOException
private Compressor getCompressor(CompressedHeader compressedHeader)
public ByteBuf getBuffer(int size)
BufferProvider
getBuffer
in interface BufferProvider
size
- the size required for the bufferprivate static <T extends BsonDocument> T getResponseDocument(ResponseBuffers responseBuffers, int messageId, Decoder<T> decoder)