use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.
the class CommandProtocol method execute.
@Override
public T execute(final InternalConnection connection) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Sending command {%s : %s} to database %s on connection [%s] to server %s", getCommandName(), command.values().iterator().next(), namespace.getDatabaseName(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress()));
}
long startTimeNanos = System.nanoTime();
CommandMessage commandMessage = new CommandMessage(namespace.getFullName(), command, slaveOk, fieldNameValidator, ProtocolHelper.getMessageSettings(connection.getDescription()));
ResponseBuffers responseBuffers = null;
try {
sendMessage(commandMessage, connection);
responseBuffers = connection.receiveMessage(commandMessage.getId());
if (!ProtocolHelper.isCommandOk(new BsonBinaryReader(new ByteBufferBsonInput(responseBuffers.getBodyByteBuffer())))) {
throw getCommandFailureException(getResponseDocument(responseBuffers, commandMessage, new BsonDocumentCodec()), connection.getDescription().getServerAddress());
}
T retval = getResponseDocument(responseBuffers, commandMessage, commandResultDecoder);
if (commandListener != null) {
sendSucceededEvent(connection.getDescription(), startTimeNanos, commandMessage, getResponseDocument(responseBuffers, commandMessage, new RawBsonDocumentCodec()));
}
LOGGER.debug("Command execution completed");
return retval;
} catch (RuntimeException e) {
sendFailedEvent(connection.getDescription(), startTimeNanos, commandMessage, e);
throw e;
} finally {
if (responseBuffers != null) {
responseBuffers.close();
}
}
}
use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.
the class GetMoreProtocol method execute.
@Override
public QueryResult<T> execute(final InternalConnection connection) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(format("Getting more documents from namespace %s with cursor %d on connection [%s] to server %s", namespace, cursorId, connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress()));
}
long startTimeNanos = System.nanoTime();
GetMoreMessage message = new GetMoreMessage(namespace.getFullName(), cursorId, numberToReturn);
QueryResult<T> queryResult = null;
try {
sendMessage(message, connection);
ResponseBuffers responseBuffers = connection.receiveMessage(message.getId());
try {
if (responseBuffers.getReplyHeader().isCursorNotFound()) {
throw new MongoCursorNotFoundException(message.getCursorId(), connection.getDescription().getServerAddress());
}
if (responseBuffers.getReplyHeader().isQueryFailure()) {
BsonDocument errorDocument = new ReplyMessage<BsonDocument>(responseBuffers, new BsonDocumentCodec(), message.getId()).getDocuments().get(0);
throw getQueryFailureException(errorDocument, connection.getDescription().getServerAddress());
}
queryResult = new QueryResult<T>(namespace, new ReplyMessage<T>(responseBuffers, resultDecoder, message.getId()), connection.getDescription().getServerAddress());
if (commandListener != null) {
sendCommandSucceededEvent(message, COMMAND_NAME, asGetMoreCommandResponseDocument(queryResult, responseBuffers), connection.getDescription(), startTimeNanos, commandListener);
}
} finally {
responseBuffers.close();
}
LOGGER.debug("Get-more completed");
return queryResult;
} catch (RuntimeException e) {
if (commandListener != null) {
sendCommandFailedEvent(message, COMMAND_NAME, connection.getDescription(), startTimeNanos, e, commandListener);
}
throw e;
}
}
use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.
the class TestCommandListener method getWritableClone.
private BsonDocument getWritableClone(final BsonDocument original) {
BsonDocument clone = new BsonDocument();
BsonDocumentWriter writer = new BsonDocumentWriter(clone);
new BsonDocumentCodec(CODEC_REGISTRY_HACK).encode(writer, original, EncoderContext.builder().build());
return clone;
}
use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.
the class ClusterFixture method enableMaxTimeFailPoint.
public static void enableMaxTimeFailPoint() {
assumeThat(isSharded(), is(false));
new CommandWriteOperation<BsonDocument>("admin", new BsonDocumentWrapper<Document>(new Document("configureFailPoint", "maxTimeAlwaysTimeOut").append("mode", "alwaysOn"), new DocumentCodec()), new BsonDocumentCodec()).execute(getBinding());
}
use of org.bson.codecs.BsonDocumentCodec in project mongo-java-driver by mongodb.
the class MessageHelper method decodeCommand.
public static BsonDocument decodeCommand(final BsonInput bsonInput) {
// length
bsonInput.readInt32();
//requestId
bsonInput.readInt32();
//responseTo
bsonInput.readInt32();
// opcode
bsonInput.readInt32();
// flags
bsonInput.readInt32();
//collectionName
bsonInput.readCString();
// numToSkip
bsonInput.readInt32();
// numToReturn
bsonInput.readInt32();
BsonBinaryReader reader = new BsonBinaryReader(bsonInput);
return new BsonDocumentCodec().decode(reader, DecoderContext.builder().build());
}
Aggregations