public class SocketConnection extends AbstractSocketConnection
This version uses single receive thread. Sending of messages is done by the application thread sending the message.
This implementation does not perform as well as the
TwoThreadSocketConnection
when the Socket
implementation does
not have built in buffering of messages or requires acknowledgment of
messages before releasing a write request. For that reason this
implementation is only used with the normal Java Socket implementations.
HEADER_LENGTH, myBsonIn, myConfig, myEncoderCache, myEventSupport, myExecutor, myInput, myLog, myOpen, myOutput, myPendingQueue, myServer, myShutdown, mySocket
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
SocketConnection(Server server,
MongoClientConfiguration config)
Creates a new SocketConnection to a MongoDB server.
|
SocketConnection(Server server,
MongoClientConfiguration config,
StringEncoderCache encoderCache,
StringDecoderCache decoderCache,
ThreadLocal<Reference<BufferingBsonOutputStream>> buffers)
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 |
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, raiseErrors, readIntSuppressTimeoutOnNonFirstByte, removePropertyChangeListener, reply, send, shutdown, shutdown, stop, toString, tryReceive, updateSocketWithOptions, validate, waitForClosed
public SocketConnection(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 SocketConnection(Server server, MongoClientConfiguration config, StringEncoderCache encoderCache, StringDecoderCache decoderCache, ThreadLocal<Reference<BufferingBsonOutputStream>> buffers) 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.buffers
- The buffers used each connection. Each buffer is shared by all
connections but there can be up to 1 buffer per application
thread.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()
True if the send and pending queues are empty.
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 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.