@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()
InternalConnectiongetDescription in interface InternalConnectionpublic void open()
InternalConnectionopen in interface InternalConnectionpublic void openAsync(SingleResultCallback<java.lang.Void> callback)
InternalConnectionopenAsync in interface InternalConnectioncallback - 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()
InternalConnectionclose in interface InternalConnectionpublic boolean opened()
InternalConnectionopened in interface InternalConnectionpublic boolean isClosed()
InternalConnectionisClosed in interface InternalConnectionpublic <T> T sendAndReceive(CommandMessage message, Decoder<T> decoder, SessionContext sessionContext)
InternalConnectionsendAndReceive in interface InternalConnectionmessage - 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)
InternalConnectionsendAndReceiveAsync in interface InternalConnectionmessage - 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)
InternalConnectionsendMessage in interface InternalConnectionbyteBuffers - the list of byte buffers to send.lastRequestId - the request id of the last message in byteBufferspublic ResponseBuffers receiveMessage(int responseTo)
InternalConnectionreceiveMessage in interface InternalConnectionresponseTo - the request id that this message is a response topublic void sendMessageAsync(java.util.List<ByteBuf> byteBuffers, int lastRequestId, SingleResultCallback<java.lang.Void> callback)
InternalConnectionsendMessageAsync in interface InternalConnectionbyteBuffers - 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)
InternalConnectionreceiveMessageAsync in interface InternalConnectionresponseTo - 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.IOExceptionprivate Compressor getCompressor(CompressedHeader compressedHeader)
public ByteBuf getBuffer(int size)
BufferProvidergetBuffer in interface BufferProvidersize - the size required for the bufferprivate static <T extends BsonDocument> T getResponseDocument(ResponseBuffers responseBuffers, int messageId, Decoder<T> decoder)