Search in sources :

Example 1 with ConnectionSource

use of com.mongodb.internal.binding.ConnectionSource in project mongo-java-driver by mongodb.

the class ClientSessionBinding method getPinnedConnectionSource.

private ConnectionSource getPinnedConnectionSource(final boolean isRead) {
    TransactionContext<Connection> transactionContext = TransactionContext.get(session);
    ConnectionSource source;
    if (transactionContext == null) {
        source = isRead ? wrapped.getReadConnectionSource() : wrapped.getWriteConnectionSource();
        transactionContext = new TransactionContext<>(wrapped.getCluster().getDescription().getType());
        session.setTransactionContext(source.getServerDescription().getAddress(), transactionContext);
        // The session is responsible for retaining a reference to the context
        transactionContext.release();
    } else {
        source = wrapped.getConnectionSource(session.getPinnedServerAddress());
    }
    return source;
}
Also used : ConnectionSource(com.mongodb.internal.binding.ConnectionSource) Connection(com.mongodb.internal.connection.Connection)

Aggregations

ConnectionSource (com.mongodb.internal.binding.ConnectionSource)1 Connection (com.mongodb.internal.connection.Connection)1