private ServerAddress getServerAddress() { return description.getServerAddress(); }
@SuppressWarnings("unchecked") private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { return new QueryResult<T>(null, BsonDocumentWrapperHelper.<T>toList(result, "databases"), 0, description.getServerAddress()); }
@SuppressWarnings("unchecked") private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { return new QueryResult<T>(namespace, BsonDocumentWrapperHelper.<T>toList(result, "retval"), 0, description.getServerAddress()); } }
@SuppressWarnings("unchecked") private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { return new QueryResult<T>(namespace, BsonDocumentWrapperHelper.<T>toList(result, "results"), 0, description.getServerAddress()); }
private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { return new QueryResult<T>(namespace, BsonDocumentWrapperHelper.<T>toList(result, VALUES), 0L, description.getServerAddress()); }
private QueryResult<T> createQueryResult(final BsonDocument result, final ConnectionDescription description) { if (!isInline(description) || result.containsKey(CURSOR)) { return cursorDocumentToQueryResult(result.getDocument(CURSOR), description.getServerAddress()); } else { return new QueryResult<T>(namespace, BsonDocumentWrapperHelper.<T>toList(result, RESULT), 0L, description.getServerAddress()); } }
private <T> T getCommandResult(final Decoder<T> decoder, final ResponseBuffers responseBuffers, final int messageId) { T result = new ReplyMessage<T>(responseBuffers, decoder, messageId).getDocuments().get(0); MongoException writeConcernBasedError = createSpecialWriteConcernException(responseBuffers, description.getServerAddress()); if (writeConcernBasedError != null) { throw new MongoWriteConcernWithResponseException(writeConcernBasedError, result); } return result; }
@Override public void sendFailedEvent(final Throwable t) { Throwable commandEventException = t; if (t instanceof MongoCommandException && (securitySensitiveCommands.contains(commandName))) { commandEventException = new MongoCommandException(new BsonDocument(), description.getServerAddress()); } long elapsedTimeNanos = System.nanoTime() - startTimeNanos; if (loggingRequired()) { logger.debug( format("Execution of command with request id %d failed to complete successfully in %s ms on connection [%s] " + "to server %s", message.getId(), getElapsedTimeFormattedInMilliseconds(elapsedTimeNanos), description.getConnectionId(), description.getServerAddress()), commandEventException); } if (eventRequired()) { sendCommandFailedEvent(message, commandName, description, elapsedTimeNanos, commandEventException, commandListener); } }
private static <D, T> T executeWrappedCommandProtocol(final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<D> decoder, final Connection connection, final ReadPreference readPreference, final CommandTransformer<D, T> transformer, final SessionContext sessionContext) { return transformer.apply(connection.command(database, command, fieldNameValidator, readPreference, decoder, sessionContext), connection.getDescription().getServerAddress()); }
@Override public void onResult(final D result, final Throwable t) { if (t != null) { callback.onResult(null, t); } else { try { T transformedResult = transformer.apply(result, connection.getDescription().getServerAddress()); callback.onResult(transformedResult, null); } catch (Exception e) { callback.onResult(null, e); } } } });
@Override public void onResult(final D result, final Throwable t) { if (t != null) { callback.onResult(null, t); } else { try { T transformedResult = transformer.apply(result, connection.getDescription().getServerAddress()); callback.onResult(transformedResult, null); } catch (Exception e) { callback.onResult(null, e); } } } });
@Override public WriteConcernResult execute(final InternalConnection connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Deleting documents from namespace %s on connection [%s] to server %s", getNamespace(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress())); } WriteConcernResult writeConcernResult = super.execute(connection); LOGGER.debug("Delete completed"); return writeConcernResult; }
@Override public WriteConcernResult execute(final InternalConnection connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Updating documents in namespace %s on connection [%s] to server %s", getNamespace(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress())); } WriteConcernResult writeConcernResult = super.execute(connection); LOGGER.debug("Update completed"); return writeConcernResult; }
@Override public WriteConcernResult execute(final InternalConnection connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Inserting 1 document into namespace %s on connection [%s] to server %s", getNamespace(), connection.getDescription().getConnectionId(), connection.getDescription().getServerAddress())); } WriteConcernResult writeConcernResult = super.execute(connection); LOGGER.debug("Insert completed"); return writeConcernResult; }
private MongoBulkWriteException getBulkWriteException(final BsonDocument result) { if (!hasError(result)) { throw new MongoInternalException("This method should not have been called"); } return new MongoBulkWriteException(getBulkWriteResult(result), getWriteErrors(result), getWriteConcernError(result), connectionDescription.getServerAddress()); }
@Override public void sendSucceededEvent(final ResponseBuffers responseBuffers) { long elapsedTimeNanos = System.nanoTime() - startTimeNanos; if (loggingRequired()) { logger.debug( format("Execution of command with request id %d completed successfully in %s ms on connection [%s] to server %s", message.getId(), getElapsedTimeFormattedInMilliseconds(elapsedTimeNanos), description.getConnectionId(), description.getServerAddress())); } if (eventRequired()) { BsonDocument responseDocumentForEvent = (securitySensitiveCommands.contains(commandName)) ? new BsonDocument() : responseBuffers.getResponseDocument(message.getId(), new RawBsonDocumentCodec()); sendCommandSucceededEvent(message, commandName, responseDocumentForEvent, description, elapsedTimeNanos, commandListener); } }
@Override public void onResult(final T result, final Throwable originalError) { SingleResultCallback<R> releasingCallback = releasingCallback(callback, oldSource, oldConnection); if (originalError != null) { checkRetryableException(originalError, releasingCallback); } else { try { releasingCallback.onResult(transformer.apply(result, oldConnection.getDescription().getServerAddress()), null); } catch (Throwable transformError) { checkRetryableException(transformError, releasingCallback); } } }
@Override public void sendSucceededEventForOneWayCommand() { long elapsedTimeNanos = System.nanoTime() - startTimeNanos; if (loggingRequired()) { logger.debug( format("Execution of one-way command with request id %d completed successfully in %s ms on connection [%s] " + "to server %s", message.getId(), getElapsedTimeFormattedInMilliseconds(elapsedTimeNanos), description.getConnectionId(), description.getServerAddress())); } if (eventRequired()) { BsonDocument responseDocumentForEvent = new BsonDocument("ok", new BsonInt32(1)); sendCommandSucceededEvent(message, commandName, responseDocumentForEvent, description, elapsedTimeNanos, commandListener); } }
@Override public void sendStartedEvent() { if (loggingRequired()) { logger.debug( format("Sending command '%s' with request id %d to database %s on connection [%s] to server %s", getTruncatedJsonCommand(), message.getId(), message.getNamespace().getDatabaseName(), description.getConnectionId(), description.getServerAddress())); } if (eventRequired()) { BsonDocument commandDocumentForEvent = (securitySensitiveCommands.contains(commandName)) ? new BsonDocument() : commandDocument; sendCommandStartedEvent(message, message.getNamespace().getDatabaseName(), commandName, commandDocumentForEvent, description, commandListener); } // the buffer underlying the command document may be released after the started event, so set to null to ensure it's not used // when sending the failed or succeeded event commandDocument = null; }
private <T> T receiveCommandMessageResponse(final CommandMessage message, final Decoder<T> decoder, final CommandEventSender commandEventSender, final SessionContext sessionContext) { ResponseBuffers responseBuffers = receiveMessage(message.getId()); try { updateSessionContext(sessionContext, responseBuffers); if (!isCommandOk(responseBuffers)) { throw getCommandFailureException(responseBuffers.getResponseDocument(message.getId(), new BsonDocumentCodec()), description.getServerAddress()); } commandEventSender.sendSucceededEvent(responseBuffers); return getCommandResult(decoder, responseBuffers, message.getId()); } finally { responseBuffers.close(); } }