@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; }
static void validateCollation(final ConnectionDescription connectionDescription, final Collation collation) { if (collation != null && !ServerVersionHelper.serverIsAtLeastVersionThreeDotFour(connectionDescription)) { throw new IllegalArgumentException(format("Collation not supported by server version: %s", connectionDescription.getServerVersion())); } }
/** * Creates a new connection description with the set connection id * * @param connectionId the connection id * @return the new connection description * @since 3.8 */ public ConnectionDescription withConnectionId(final ConnectionId connectionId) { notNull("connectionId", connectionId); return new ConnectionDescription(connectionId, serverVersion, maxWireVersion, serverType, maxBatchCount, maxDocumentSize, maxMessageSize, compressors); }
static MessageSettings getMessageSettings(final ConnectionDescription connectionDescription) { return MessageSettings.builder() .maxDocumentSize(connectionDescription.getMaxDocumentSize()) .maxMessageSize(connectionDescription.getMaxMessageSize()) .maxBatchCount(connectionDescription.getMaxBatchCount()) .maxWireVersion(connectionDescription.getMaxWireVersion()) .serverType(connectionDescription.getServerType()) .build(); }
private ConnectionDescription applyGetLastErrorResult(final BsonDocument getLastErrorResult, final ConnectionDescription connectionDescription) { ConnectionId connectionId; if (getLastErrorResult.containsKey("connectionId")) { connectionId = connectionDescription.getConnectionId().withServerValue(getLastErrorResult.getNumber("connectionId").intValue()); } else { connectionId = connectionDescription.getConnectionId(); } return connectionDescription.withConnectionId(connectionId); }
private ServerAddress getServerAddress() { return description.getServerAddress(); }
private ConnectionId getId() { return description.getConnectionId(); }
private ServerDescription lookupServerDescription(final InternalConnection connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Checking status of %s", serverId.getAddress())); } serverMonitorListener.serverHearbeatStarted(new ServerHeartbeatStartedEvent(connection.getDescription().getConnectionId())); long start = System.nanoTime(); try { BsonDocument isMasterResult = executeCommand("admin", new BsonDocument("ismaster", new BsonInt32(1)), clusterClock, connection); long elapsedTimeNanos = System.nanoTime() - start; averageRoundTripTime.addSample(elapsedTimeNanos); serverMonitorListener.serverHeartbeatSucceeded( new ServerHeartbeatSucceededEvent(connection.getDescription().getConnectionId(), isMasterResult, elapsedTimeNanos)); return createServerDescription(serverId.getAddress(), isMasterResult, connection.getDescription().getServerVersion(), averageRoundTripTime.getAverage()); } catch (RuntimeException e) { serverMonitorListener.serverHeartbeatFailed( new ServerHeartbeatFailedEvent(connection.getDescription().getConnectionId(), System.nanoTime() - start, e)); throw e; } }
@Override public void onResult(final ByteBuf result, final Throwable t) { if (t != null) { callback.onResult(null, t); return; } try { MessageHeader messageHeader = new MessageHeader(result, description.getMaxMessageSize()); readAsync(messageHeader.getMessageLength() - MESSAGE_HEADER_LENGTH, new MessageCallback(messageHeader)); } catch (Throwable localThrowable) { callback.onResult(null, localThrowable); } finally { if (result != null) { result.release(); } } }
private Compressor findSendCompressor(final ConnectionDescription description) { if (description.getCompressors().isEmpty()) { return null; } String firstCompressorName = description.getCompressors().get(0); for (Compressor compressor : compressorMap.values()) { if (compressor.getName().equals(firstCompressorName)) { return compressor; } } throw new MongoInternalException("Unexpected compressor negotiated: " + firstCompressorName); }
private static int getMaxMessageSizeBytes(final BsonDocument isMasterResult) { return isMasterResult.getInt32("maxMessageSizeBytes", new BsonInt32(getDefaultMaxMessageSize())).getValue(); }
private static int getMaxWriteBatchSize(final BsonDocument isMasterResult) { return isMasterResult.getInt32("maxWriteBatchSize", new BsonInt32(getDefaultMaxWriteBatchSize())).getValue(); }
@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()); }
private ConnectionId getId(final InternalConnection internalConnection) { return internalConnection.getDescription().getConnectionId(); }
static MessageSettings getMessageSettings(final ConnectionDescription connectionDescription) { return MessageSettings.builder() .maxDocumentSize(connectionDescription.getMaxDocumentSize()) .maxMessageSize(connectionDescription.getMaxMessageSize()) .maxBatchCount(connectionDescription.getMaxBatchCount()) .maxWireVersion(connectionDescription.getMaxWireVersion()) .serverType(connectionDescription.getServerType()) .build(); }
private ServerDescription lookupServerDescription(final InternalConnection connection) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Checking status of %s", serverId.getAddress())); } serverMonitorListener.serverHearbeatStarted(new ServerHeartbeatStartedEvent(connection.getDescription().getConnectionId())); long start = System.nanoTime(); try { BsonDocument isMasterResult = executeCommand("admin", new BsonDocument("ismaster", new BsonInt32(1)), clusterClock, connection); long elapsedTimeNanos = System.nanoTime() - start; averageRoundTripTime.addSample(elapsedTimeNanos); serverMonitorListener.serverHeartbeatSucceeded( new ServerHeartbeatSucceededEvent(connection.getDescription().getConnectionId(), isMasterResult, elapsedTimeNanos)); return createServerDescription(serverId.getAddress(), isMasterResult, connection.getDescription().getServerVersion(), averageRoundTripTime.getAverage()); } catch (RuntimeException e) { serverMonitorListener.serverHeartbeatFailed( new ServerHeartbeatFailedEvent(connection.getDescription().getConnectionId(), System.nanoTime() - start, e)); throw e; } }
private ConnectionDescription applyGetLastErrorResult(final BsonDocument getLastErrorResult, final ConnectionDescription connectionDescription) { ConnectionId connectionId; if (getLastErrorResult.containsKey("connectionId")) { connectionId = connectionDescription.getConnectionId().withServerValue(getLastErrorResult.getNumber("connectionId").intValue()); } else { connectionId = connectionDescription.getConnectionId(); } return connectionDescription.withConnectionId(connectionId); }
private ResponseBuffers receiveResponseBuffers() throws IOException { ByteBuf messageHeaderBuffer = stream.read(MESSAGE_HEADER_LENGTH); MessageHeader messageHeader; try { messageHeader = new MessageHeader(messageHeaderBuffer, description.getMaxMessageSize()); } finally { messageHeaderBuffer.release(); } ByteBuf messageBuffer = stream.read(messageHeader.getMessageLength() - MESSAGE_HEADER_LENGTH); if (messageHeader.getOpCode() == OP_COMPRESSED.getValue()) { CompressedHeader compressedHeader = new CompressedHeader(messageBuffer, messageHeader); Compressor compressor = getCompressor(compressedHeader); ByteBuf buffer = getBuffer(compressedHeader.getUncompressedSize()); compressor.uncompress(messageBuffer, buffer); buffer.flip(); return new ResponseBuffers(new ReplyHeader(buffer, compressedHeader), buffer); } else { return new ResponseBuffers(new ReplyHeader(messageBuffer, messageHeader), messageBuffer); } }
private Compressor findSendCompressor(final ConnectionDescription description) { if (description.getCompressors().isEmpty()) { return null; } String firstCompressorName = description.getCompressors().get(0); for (Compressor compressor : compressorMap.values()) { if (compressor.getName().equals(firstCompressorName)) { return compressor; } } throw new MongoInternalException("Unexpected compressor negotiated: " + firstCompressorName); }
private static int getMaxMessageSizeBytes(final BsonDocument isMasterResult) { return isMasterResult.getInt32("maxMessageSizeBytes", new BsonInt32(getDefaultMaxMessageSize())).getValue(); }