static <T> T withConnection(final WriteBinding binding, final CallableWithConnection<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return withConnectionSource(source, callable); } finally { source.release(); } }
static <T> T withReleasableConnection(final WriteBinding binding, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return callable.call(source, source.getConnection()); } finally { source.release(); } }
static <T> T withReleasableConnection(final WriteBinding binding, final MongoException connectionException, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = null; Connection connection; try { source = binding.getWriteConnectionSource(); connection = source.getConnection(); } catch (Throwable t){ if (source != null) { source.release(); } throw connectionException; } try { return callable.call(source, connection); } finally { source.release(); } }
static <D, T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<D> decoder, final CommandTransformer<D, T> transformer) { ConnectionSource source = binding.getWriteConnectionSource(); try { return transformer.apply(executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, source, primary()), source.getServerDescription().getAddress()); } finally { source.release(); } }
static <T> T withConnection(final WriteBinding binding, final CallableWithConnection<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return withConnectionSource(source, callable); } finally { source.release(); } }
static <T> T withReleasableConnection(final WriteBinding binding, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = binding.getWriteConnectionSource(); try { return callable.call(source, source.getConnection()); } finally { source.release(); } }
static <T> T withReleasableConnection(final WriteBinding binding, final MongoException connectionException, final CallableWithConnectionAndSource<T> callable) { ConnectionSource source = null; Connection connection; try { source = binding.getWriteConnectionSource(); connection = source.getConnection(); } catch (Throwable t){ if (source != null) { source.release(); } throw connectionException; } try { return callable.call(source, connection); } finally { source.release(); } }
static <D, T> T executeWrappedCommandProtocol(final WriteBinding binding, final String database, final BsonDocument command, final FieldNameValidator fieldNameValidator, final Decoder<D> decoder, final CommandTransformer<D, T> transformer) { ConnectionSource source = binding.getWriteConnectionSource(); try { return transformer.apply(executeWrappedCommandProtocol(database, command, fieldNameValidator, decoder, source, primary()), source.getServerDescription().getAddress()); } finally { source.release(); } }