public class TwoThreadSocketConnection extends AbstractSocketConnection
This version uses a pair of threads (1 send and 1 receive) to handle the messages going to and from MongoDB.
This implementation was the default for the driver through the 1.2.3 release. It is still used by the driver for communication sockets that are not know to be standard Java Sockets as it performs better when the communication path does not have built in buffering of messages.
Modifier and Type | Class and Description |
---|---|
protected class |
TwoThreadSocketConnection.SendRunnable
Runnable to push data out over the MongoDB connection.
|
Modifier and Type | Field and Description |
---|---|
protected BufferingBsonOutputStream |
myBsonOut
The writer for BSON documents.
|
protected PendingMessageQueue |
myToSendQueue
The queue of messages to be sent.
|
HEADER_LENGTH, myBsonIn, myConfig, myEncoderCache, myEventSupport, myExecutor, myInput, myLog, myOpen, myOutput, myPendingQueue, myServer, myShutdown, mySocket
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
TwoThreadSocketConnection(Server server,
MongoClientConfiguration config)
Creates a new SocketConnection to a MongoDB server.
|
TwoThreadSocketConnection(Server server,
MongoClientConfiguration config,
StringEncoderCache encoderCache,
StringDecoderCache decoderCache)
Creates a new SocketConnection to a MongoDB server.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getPendingCount()
Returns the number of messages that are pending responses from the
server.
|
boolean |
isIdle()
Determines if the connection is idle.
|
void |
raiseErrors(MongoDbException exception)
Notifies the call backs for the pending and optionally the to be sent
messages that there has been an external, unrecoverable error.
|
void |
send(Message message1,
Message message2,
ReplyCallback replyCallback)
Sends a message on the connection.
|
void |
send(Message message,
ReplyCallback replyCallback)
Sends a message on the connection.
|
void |
start()
Starts the connections read and write threads.
|
addPropertyChangeListener, doReceive, doReceiveOne, doSend, flush, getServerName, isAvailable, isOpen, isShuttingDown, markReaderNeedsToFlush, raiseError, readIntSuppressTimeoutOnNonFirstByte, removePropertyChangeListener, reply, send, shutdown, shutdown, stop, toString, tryReceive, updateSocketWithOptions, validate, waitForClosed
protected final BufferingBsonOutputStream myBsonOut
protected final PendingMessageQueue myToSendQueue
public TwoThreadSocketConnection(Server server, MongoClientConfiguration config) throws SocketException, IOException
server
- The MongoDB server to connect to.config
- The configuration for the Connection to the MongoDB server.SocketException
- On a failure connecting to the MongoDB server.IOException
- On a failure to read or write data to the MongoDB server.public TwoThreadSocketConnection(Server server, MongoClientConfiguration config, StringEncoderCache encoderCache, StringDecoderCache decoderCache) throws SocketException, IOException
server
- The MongoDB server to connect to.config
- The configuration for the Connection to the MongoDB server.encoderCache
- Cache used for encoding strings.decoderCache
- Cache used for decoding strings.SocketException
- On a failure connecting to the MongoDB server.IOException
- On a failure to read or write data to the MongoDB server.public void close() throws IOException
IOException
public int getPendingCount()
getPendingCount
in interface Connection
getPendingCount
in class AbstractSocketConnection
public boolean isIdle()
True if the send and pending queues are empty.
True if the send and pending queues are empty.
isIdle
in interface Connection
isIdle
in class AbstractSocketConnection
public void raiseErrors(MongoDbException exception)
Notifies the appropriate messages of the error.
Notifies the appropriate messages of the error.
raiseErrors
in interface Connection
raiseErrors
in class AbstractSocketConnection
exception
- The error condition.public void send(Message message1, Message message2, ReplyCallback replyCallback) throws MongoDbException
message1
- The first message to send on the connection.message2
- The second message to send on the connection.replyCallback
- The callback to notify of responses to the message2
.
May be null
.MongoDbException
- On an error sending the message.public void send(Message message, ReplyCallback replyCallback) throws MongoDbException
message
- The message to send on the connection.replyCallback
- The callback to notify of responses to the messages. May be
null
.MongoDbException
- On an error sending the message.public void start()
start
in class AbstractSocketConnection
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.