Package com.mongodb.internal.connection
Class DefaultServerConnection
- java.lang.Object
-
- com.mongodb.internal.connection.DefaultServerConnection
-
- All Implemented Interfaces:
ReferenceCounted,AsyncConnection,Connection
public class DefaultServerConnection extends java.lang.Object implements Connection, AsyncConnection
-
-
Constructor Summary
Constructors Constructor Description DefaultServerConnection(InternalConnection wrapped, ProtocolExecutor protocolExecutor, ClusterConnectionMode clusterConnectionMode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tcommand(java.lang.String database, BsonDocument command, boolean slaveOk, FieldNameValidator fieldNameValidator, Decoder<T> commandResultDecoder)Execute the command.<T> Tcommand(java.lang.String database, BsonDocument command, FieldNameValidator fieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext)Execute the command.<T> Tcommand(java.lang.String database, BsonDocument command, FieldNameValidator commandFieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, boolean responseExpected, SplittablePayload payload, FieldNameValidator payloadFieldNameValidator)Executes the command, consuming as much of theSplittablePayloadas possible.<T> voidcommandAsync(java.lang.String database, BsonDocument command, boolean slaveOk, FieldNameValidator fieldNameValidator, Decoder<T> commandResultDecoder, SingleResultCallback<T> callback)Execute the command asynchronously.<T> voidcommandAsync(java.lang.String database, BsonDocument command, FieldNameValidator commandFieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, boolean responseExpected, SplittablePayload payload, FieldNameValidator payloadFieldNameValidator, SingleResultCallback<T> callback)Executes the command, consuming as much of theSplittablePayloadas possible.<T> voidcommandAsync(java.lang.String database, BsonDocument command, FieldNameValidator fieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, SingleResultCallback<T> callback)Execute the command.WriteConcernResultdelete(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest)Delete the documents using the delete wire protocol and apply the write concern.voiddeleteAsync(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest, SingleResultCallback<WriteConcernResult> callback)Delete the documents using the delete wire protocol and apply the write concern asynchronously.intgetCount()Gets the current reference count, which starts at 0.ConnectionDescriptiongetDescription()Gets the description of the connection.<T> QueryResult<T>getMore(MongoNamespace namespace, long cursorId, int numberToReturn, Decoder<T> resultDecoder)Get more result documents from a cursor.<T> voidgetMoreAsync(MongoNamespace namespace, long cursorId, int numberToReturn, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)Get more result documents from a cursor asynchronously.WriteConcernResultinsert(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest)Insert the documents using the insert wire protocol and apply the write concern.voidinsertAsync(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest, SingleResultCallback<WriteConcernResult> callback)Insert the documents using the insert wire protocol and apply the write concern asynchronously.voidkillCursor(MongoNamespace namespace, java.util.List<java.lang.Long> cursors)Kills the given list of cursors.voidkillCursor(java.util.List<java.lang.Long> cursors)Kills the given list of cursors.voidkillCursorAsync(MongoNamespace namespace, java.util.List<java.lang.Long> cursors, SingleResultCallback<java.lang.Void> callback)Asynchronously Kills the given list of cursors.voidkillCursorAsync(java.util.List<java.lang.Long> cursors, SingleResultCallback<java.lang.Void> callback)Asynchronously Kills the given list of cursors.<T> QueryResult<T>query(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int numberToReturn, int skip, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder)Execute the query.<T> QueryResult<T>query(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int skip, int limit, int batchSize, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder)Execute the query.<T> voidqueryAsync(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int numberToReturn, int skip, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)Execute the query asynchronously.<T> voidqueryAsync(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int skip, int limit, int batchSize, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)Execute the query asynchronously.voidrelease()Release a reference to this object.DefaultServerConnectionretain()Retain an additional reference to this object.WriteConcernResultupdate(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest)Update the documents using the update wire protocol and apply the write concern.voidupdateAsync(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest, SingleResultCallback<WriteConcernResult> callback)Update the documents using the update wire protocol and apply the write concern asynchronously.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.mongodb.binding.ReferenceCounted
getCount
-
-
-
-
Constructor Detail
-
DefaultServerConnection
public DefaultServerConnection(InternalConnection wrapped, ProtocolExecutor protocolExecutor, ClusterConnectionMode clusterConnectionMode)
-
-
Method Detail
-
retain
public DefaultServerConnection retain()
Description copied from interface:ReferenceCountedRetain an additional reference to this object. All retained references must be released, or there will be a leak.- Specified by:
retainin interfaceAsyncConnection- Specified by:
retainin interfaceConnection- Specified by:
retainin interfaceReferenceCounted- Returns:
- this
-
release
public void release()
Description copied from interface:ReferenceCountedRelease a reference to this object.- Specified by:
releasein interfaceReferenceCounted
-
getDescription
public ConnectionDescription getDescription()
Description copied from interface:ConnectionGets the description of the connection.- Specified by:
getDescriptionin interfaceAsyncConnection- Specified by:
getDescriptionin interfaceConnection- Returns:
- the connection description
-
insert
public WriteConcernResult insert(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest)
Description copied from interface:ConnectionInsert the documents using the insert wire protocol and apply the write concern.- Specified by:
insertin interfaceConnection- Parameters:
namespace- the namespaceordered- whether the writes are orderedinsertRequest- the insert request- Returns:
- the write concern result
-
insertAsync
public void insertAsync(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest, SingleResultCallback<WriteConcernResult> callback)
Description copied from interface:AsyncConnectionInsert the documents using the insert wire protocol and apply the write concern asynchronously.- Specified by:
insertAsyncin interfaceAsyncConnection- Parameters:
namespace- the namespaceordered- whether the writes are orderedinsertRequest- the insert requestcallback- the callback to be passed the write result
-
update
public WriteConcernResult update(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest)
Description copied from interface:ConnectionUpdate the documents using the update wire protocol and apply the write concern.- Specified by:
updatein interfaceConnection- Parameters:
namespace- the namespaceordered- whether the writes are orderedupdateRequest- the update request- Returns:
- the write concern result
-
updateAsync
public void updateAsync(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest, SingleResultCallback<WriteConcernResult> callback)
Description copied from interface:AsyncConnectionUpdate the documents using the update wire protocol and apply the write concern asynchronously.- Specified by:
updateAsyncin interfaceAsyncConnection- Parameters:
namespace- the namespaceordered- whether the writes are orderedupdateRequest- the update requestcallback- the callback to be passed the write result
-
delete
public WriteConcernResult delete(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest)
Description copied from interface:ConnectionDelete the documents using the delete wire protocol and apply the write concern.- Specified by:
deletein interfaceConnection- Parameters:
namespace- the namespaceordered- whether the writes are ordereddeleteRequest- the delete request- Returns:
- the write concern result
-
deleteAsync
public void deleteAsync(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest, SingleResultCallback<WriteConcernResult> callback)
Description copied from interface:AsyncConnectionDelete the documents using the delete wire protocol and apply the write concern asynchronously.- Specified by:
deleteAsyncin interfaceAsyncConnection- Parameters:
namespace- the namespaceordered- whether the writes are ordereddeleteRequest- the delete requestcallback- the callback to be passed the write result
-
command
public <T> T command(java.lang.String database, BsonDocument command, boolean slaveOk, FieldNameValidator fieldNameValidator, Decoder<T> commandResultDecoder)Description copied from interface:ConnectionExecute the command.- Specified by:
commandin interfaceConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentslaveOk- whether the command can run on a secondaryfieldNameValidator- the field name validator for the command documentcommandResultDecoder- the decoder for the result- Returns:
- the command result
-
command
public <T> T command(java.lang.String database, BsonDocument command, FieldNameValidator fieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext)Description copied from interface:ConnectionExecute the command.- Specified by:
commandin interfaceConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentfieldNameValidator- the field name validator for the command documentreadPreference- the read preference that was applied to get this connection, or null if this is a write operationcommandResultDecoder- the decoder for the resultsessionContext- the session context- Returns:
- the command result
-
command
public <T> T command(java.lang.String database, BsonDocument command, FieldNameValidator commandFieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, boolean responseExpected, SplittablePayload payload, FieldNameValidator payloadFieldNameValidator)Description copied from interface:ConnectionExecutes the command, consuming as much of theSplittablePayloadas possible.- Specified by:
commandin interfaceConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentcommandFieldNameValidator- the field name validator for the command documentreadPreference- the read preference that was applied to get this connection, or null if this is a write operationcommandResultDecoder- the decoder for the resultsessionContext- the session contextresponseExpected- true if a response from the server is expectedpayload- the splittable payload to incorporate with the commandpayloadFieldNameValidator- the field name validator for the payload documents- Returns:
- the command result
-
commandAsync
public <T> void commandAsync(java.lang.String database, BsonDocument command, boolean slaveOk, FieldNameValidator fieldNameValidator, Decoder<T> commandResultDecoder, SingleResultCallback<T> callback)Description copied from interface:AsyncConnectionExecute the command asynchronously.- Specified by:
commandAsyncin interfaceAsyncConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentslaveOk- whether the command can run on a secondaryfieldNameValidator- the field name validator for the command documentcommandResultDecoder- the decoder for the resultcallback- the callback to be passed the command result
-
commandAsync
public <T> void commandAsync(java.lang.String database, BsonDocument command, FieldNameValidator fieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, SingleResultCallback<T> callback)Description copied from interface:AsyncConnectionExecute the command.- Specified by:
commandAsyncin interfaceAsyncConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentfieldNameValidator- the field name validator for the command documentreadPreference- the read preference that was applied to get this connection, or null if this is a write operationcommandResultDecoder- the decoder for the resultsessionContext- the session contextcallback- the callback to be passed the write result
-
commandAsync
public <T> void commandAsync(java.lang.String database, BsonDocument command, FieldNameValidator commandFieldNameValidator, ReadPreference readPreference, Decoder<T> commandResultDecoder, SessionContext sessionContext, boolean responseExpected, SplittablePayload payload, FieldNameValidator payloadFieldNameValidator, SingleResultCallback<T> callback)Description copied from interface:AsyncConnectionExecutes the command, consuming as much of theSplittablePayloadas possible.- Specified by:
commandAsyncin interfaceAsyncConnection- Type Parameters:
T- the type of the result- Parameters:
database- the database to execute the command incommand- the command documentcommandFieldNameValidator- the field name validator for the command documentreadPreference- the read preference that was applied to get this connection, or null if this is a write operationcommandResultDecoder- the decoder for the resultsessionContext- the session contextresponseExpected- true if a response from the server is expectedpayload- the splittable payload to incorporate with the commandpayloadFieldNameValidator- the field name validator for the payload documentscallback- the callback to be passed the write result
-
query
public <T> QueryResult<T> query(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int numberToReturn, int skip, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder)
Description copied from interface:ConnectionExecute the query.- Specified by:
queryin interfaceConnection- Type Parameters:
T- the query result document type- Parameters:
namespace- the namespace to queryqueryDocument- the query documentfields- the field to include or excludenumberToReturn- the number of documents to returnskip- the number of documents to skipslaveOk- whether the query can run on a secondarytailableCursor- whether to return a tailable cursorawaitData- whether a tailable cursor should wait before returning if no documents are availablenoCursorTimeout- whether the cursor should not timeoutpartial- whether partial results from sharded clusters are acceptableoplogReplay- whether to replay the oplogresultDecoder- the decoder for the query result documents- Returns:
- the query results
-
query
public <T> QueryResult<T> query(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int skip, int limit, int batchSize, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder)
Description copied from interface:ConnectionExecute the query.- Specified by:
queryin interfaceConnection- Type Parameters:
T- the query result document type- Parameters:
namespace- the namespace to queryqueryDocument- the query documentfields- the field to include or excludeskip- the number of documents to skiplimit- the maximum number of documents to return in all batchesbatchSize- the maximum number of documents to return in this batchslaveOk- whether the query can run on a secondarytailableCursor- whether to return a tailable cursorawaitData- whether a tailable cursor should wait before returning if no documents are availablenoCursorTimeout- whether the cursor should not timeoutpartial- whether partial results from sharded clusters are acceptableoplogReplay- whether to replay the oplogresultDecoder- the decoder for the query result documents- Returns:
- the query results
-
queryAsync
public <T> void queryAsync(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int numberToReturn, int skip, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)
Description copied from interface:AsyncConnectionExecute the query asynchronously.- Specified by:
queryAsyncin interfaceAsyncConnection- Type Parameters:
T- the query result document type- Parameters:
namespace- the namespace to queryqueryDocument- the query documentfields- the field to include or excludenumberToReturn- the number of documents to returnskip- the number of documents to skipslaveOk- whether the query can run on a secondarytailableCursor- whether to return a tailable cursorawaitData- whether a tailable cursor should wait before returning if no documents are availablenoCursorTimeout- whether the cursor should not timeoutpartial- whether partial results from sharded clusters are acceptableoplogReplay- whether to replay the oplogresultDecoder- the decoder for the query result documentscallback- the callback to be passed the write result
-
queryAsync
public <T> void queryAsync(MongoNamespace namespace, BsonDocument queryDocument, BsonDocument fields, int skip, int limit, int batchSize, boolean slaveOk, boolean tailableCursor, boolean awaitData, boolean noCursorTimeout, boolean partial, boolean oplogReplay, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)
Description copied from interface:AsyncConnectionExecute the query asynchronously.- Specified by:
queryAsyncin interfaceAsyncConnection- Type Parameters:
T- the query result document type- Parameters:
namespace- the namespace to queryqueryDocument- the query documentfields- the field to include or excludeskip- the number of documents to skiplimit- the maximum number of documents to return in all batchesbatchSize- the maximum number of documents to return in this batchslaveOk- whether the query can run on a secondarytailableCursor- whether to return a tailable cursorawaitData- whether a tailable cursor should wait before returning if no documents are availablenoCursorTimeout- whether the cursor should not timeoutpartial- whether partial results from sharded clusters are acceptableoplogReplay- whether to replay the oplogresultDecoder- the decoder for the query result documentscallback- the callback to be passed the write result
-
getMore
public <T> QueryResult<T> getMore(MongoNamespace namespace, long cursorId, int numberToReturn, Decoder<T> resultDecoder)
Description copied from interface:ConnectionGet more result documents from a cursor.- Specified by:
getMorein interfaceConnection- Type Parameters:
T- the type of the query result documents- Parameters:
namespace- the namespace to get more documents fromcursorId- the cursor idnumberToReturn- the number of documents to returnresultDecoder- the decoder for the query results- Returns:
- the query results
-
getMoreAsync
public <T> void getMoreAsync(MongoNamespace namespace, long cursorId, int numberToReturn, Decoder<T> resultDecoder, SingleResultCallback<QueryResult<T>> callback)
Description copied from interface:AsyncConnectionGet more result documents from a cursor asynchronously.- Specified by:
getMoreAsyncin interfaceAsyncConnection- Type Parameters:
T- the type of the query result documents- Parameters:
namespace- the namespace to get more documents fromcursorId- the cursor idnumberToReturn- the number of documents to returnresultDecoder- the decoder for the query result documentscallback- the callback to be passed the query result
-
killCursor
public void killCursor(java.util.List<java.lang.Long> cursors)
Description copied from interface:ConnectionKills the given list of cursors.- Specified by:
killCursorin interfaceConnection- Parameters:
cursors- the cursors
-
killCursor
public void killCursor(MongoNamespace namespace, java.util.List<java.lang.Long> cursors)
Description copied from interface:ConnectionKills the given list of cursors.- Specified by:
killCursorin interfaceConnection- Parameters:
namespace- the namespace to in which the cursors livecursors- the cursors
-
killCursorAsync
public void killCursorAsync(java.util.List<java.lang.Long> cursors, SingleResultCallback<java.lang.Void> callback)Description copied from interface:AsyncConnectionAsynchronously Kills the given list of cursors.- Specified by:
killCursorAsyncin interfaceAsyncConnection- Parameters:
cursors- the cursorscallback- the callback that is called once the cursors have been killed
-
killCursorAsync
public void killCursorAsync(MongoNamespace namespace, java.util.List<java.lang.Long> cursors, SingleResultCallback<java.lang.Void> callback)
Description copied from interface:AsyncConnectionAsynchronously Kills the given list of cursors.- Specified by:
killCursorAsyncin interfaceAsyncConnection- Parameters:
namespace- the namespace in which the cursors livecursors- the cursorscallback- the callback that is called once the cursors have been killed
-
getCount
public int getCount()
Description copied from interface:ReferenceCountedGets the current reference count, which starts at 0.- Specified by:
getCountin interfaceReferenceCounted- Returns:
- the current count, which must be greater than or equal to 0
-
-