private void sendStartedEvent( final InternalConnection connection, final ByteBufferBsonOutput bsonOutput, final CommandMessage message, final int documentPosition) { if (commandListener != null) { ByteBufBsonDocument byteBufBsonDocument = createOne(bsonOutput, documentPosition); BsonDocument commandDocument; if (byteBufBsonDocument.containsKey("$query")) { commandDocument = byteBufBsonDocument.getDocument("$query"); commandName = commandDocument.keySet().iterator().next(); } else { commandDocument = byteBufBsonDocument; commandName = byteBufBsonDocument.getFirstKey(); } BsonDocument commandDocumentForEvent = (SECURITY_SENSITIVE_COMMANDS.contains(commandName)) ? new BsonDocument() : commandDocument; sendCommandStartedEvent( message, namespace.getDatabaseName(), commandName, commandDocumentForEvent, connection.getDescription(), commandListener); } }
private String getCommandName() { return commandName != null ? commandName : command.keySet().iterator().next(); }