class InternalStreamConnection extends java.lang.Object implements InternalConnection
| Modifier and Type | Class and Description |
|---|---|
private static class |
InternalStreamConnection.ErrorHandlingConnectionListener |
private class |
InternalStreamConnection.ResponseBuffersCallback |
private class |
InternalStreamConnection.ResponseHeaderCallback |
private static class |
InternalStreamConnection.SendMessageRequest |
| Modifier and Type | Field and Description |
|---|---|
private InternalConnectionInitializer |
connectionInitializer |
private ConnectionListener |
connectionListener |
private ConnectionDescription |
description |
private MongoException |
exceptionThatPrecededStreamClosing |
private java.util.concurrent.atomic.AtomicBoolean |
isClosed |
private boolean |
isReading |
private boolean |
isWriting |
(package private) static Logger |
LOGGER |
private java.util.Map<java.lang.Integer,ResponseBuffers> |
messages |
private java.util.concurrent.atomic.AtomicBoolean |
opened |
private java.util.concurrent.locks.Lock |
readerLock |
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch> |
readingPhase |
private java.util.Map<java.lang.Integer,SingleResultCallback<ResponseBuffers>> |
readQueue |
private ServerId |
serverId |
private Stream |
stream |
private StreamFactory |
streamFactory |
private java.util.Deque<InternalStreamConnection.SendMessageRequest> |
writeQueue |
private java.util.concurrent.locks.Lock |
writerLock |
| Constructor and Description |
|---|
InternalStreamConnection(ServerId serverId,
StreamFactory streamFactory,
InternalConnectionInitializer connectionInitializer,
ConnectionListener connectionListener) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection.
|
private void |
executeCallbackAndReceiveResponse(SingleResultCallback<ResponseBuffers> callback,
ResponseBuffers result,
boolean mustRead) |
private void |
failAllQueuedReads(java.lang.Throwable t) |
ByteBuf |
getBuffer(int size)
Gets a buffer with the givens capacity.
|
ConnectionDescription |
getDescription()
Gets the description of this connection.
|
private ConnectionId |
getId() |
private int |
getMessageSize(java.util.List<ByteBuf> byteBuffers) |
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) |
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 void |
receiveResponseAsync() |
private ResponseBuffers |
receiveResponseBuffers() |
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 |
writeAsync(InternalStreamConnection.SendMessageRequest request) |
private final ServerId serverId
private final StreamFactory streamFactory
private final InternalConnectionInitializer connectionInitializer
private final ConnectionListener connectionListener
private final java.util.concurrent.locks.Lock writerLock
private final java.util.concurrent.locks.Lock readerLock
private final java.util.Deque<InternalStreamConnection.SendMessageRequest> writeQueue
private final java.util.Map<java.lang.Integer,SingleResultCallback<ResponseBuffers>> readQueue
private final java.util.Map<java.lang.Integer,ResponseBuffers> messages
private boolean isWriting
private boolean isReading
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch> readingPhase
private volatile MongoException exceptionThatPrecededStreamClosing
private volatile ConnectionDescription description
private volatile Stream stream
private final java.util.concurrent.atomic.AtomicBoolean isClosed
private final java.util.concurrent.atomic.AtomicBoolean opened
static final Logger LOGGER
InternalStreamConnection(ServerId serverId, StreamFactory streamFactory, InternalConnectionInitializer connectionInitializer, ConnectionListener connectionListener)
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 openedpublic void close()
InternalConnectionclose in interface InternalConnectionpublic boolean opened()
InternalConnectionopened in interface InternalConnectionpublic boolean isClosed()
InternalConnectionisClosed in interface InternalConnectionpublic 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(InternalStreamConnection.SendMessageRequest request)
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 executeCallbackAndReceiveResponse(SingleResultCallback<ResponseBuffers> callback, ResponseBuffers result, boolean mustRead)
private ConnectionId getId()
private ServerAddress getServerAddress()
private void receiveResponseAsync()
private void readAsync(int numBytes,
SingleResultCallback<ByteBuf> callback)
private MongoException translateWriteException(java.lang.Throwable e)
private MongoException translateReadException(java.lang.Throwable e)
private ResponseBuffers receiveResponseBuffers() throws java.io.IOException
java.io.IOExceptionpublic ByteBuf getBuffer(int size)
BufferProvidergetBuffer in interface BufferProvidersize - the size required for the bufferprivate int getMessageSize(java.util.List<ByteBuf> byteBuffers)
private void failAllQueuedReads(java.lang.Throwable t)