Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Set up continuous integration on CircleCI with test coverage (#27) Apr 1, 2019
.github Initialize repo with fully functional Gradle 4.10 build, JUnit 5 Oct 24, 2018
codequality
docs/api Switch all URLs to HTTPS Mar 15, 2019
gradle [chores] Update a few build file licence header years Mar 29, 2019
src fix #65 Correctly account missed concurrent acquires in drainLoop Sep 17, 2019
.gitignore Initialize repo with fully functional Gradle 4.10 build, JUnit 5 Oct 24, 2018
.travis.yml Initialize repo with fully functional Gradle 4.10 build, JUnit 5 Oct 24, 2018
CONTRIBUTING.md Add NOTICE and CONTRIBUTING files Mar 15, 2019
LICENSE Switch all URLs to HTTPS Mar 15, 2019
NOTICE Add NOTICE and CONTRIBUTING files Mar 15, 2019
README.md [polish] Fix javadoc/README still referencing acquireInScope Apr 26, 2019
build.gradle Back to 3.3.0 snapshots Sep 4, 2019
gradle.properties [artifactory-release] Next development version 0.1.0.BUILD-SNAPSHOT Sep 3, 2019
gradlew Bump to Gradle 5.1.1, better compat between IDEA and JUnit5 Nested Jan 25, 2019
gradlew.bat Bump to Gradle 5.1.1, better compat between IDEA and JUnit5 Nested Jan 25, 2019
settings.gradle Switch all URLs to HTTPS Mar 15, 2019

README.md

Reactor-Pool

Join the chat at https://gitter.im/reactor/reactor CircleCI Code Coverage

The reactor-pool project aims at providing a generic object pool to reactive application that:

  • exposes a reactive API (Publisher input types, Mono return types)
  • is non-blocking (never blocking a user that makes an attempt to acquire() a resource)
  • has lazy acquire behavior

For use-cases where granular control of the release() is needed, the classic path of acquire() is offered, which exposes a PooledRef wrapper to the resource. This also allows access to statistics about the resource lifecycle in the pool.

// given Pool<T> pool
Mono<PooledRef<T>> grabResource = pool.acquire();
//no resource is actually requested yet at this point

grabResouce.subscribe();
//now one resource is requested from the pool asynchronously

//Another example, this time synchronously acquiring, immediately followed up by a release:
PooledRef<T> ref = grabResource.block(); //second subscription requests a second resource
ref.release().block(); //release() is also asynchronous and lazy

For use-cases where the resource itself can be consumed reactively (exposes a reactive API), a scoped mode of acquisition is offered. withPoolable:

  • let the consumer declaratively use the resource
  • provides a scope / closure in which the resource is acquired, used as instructed and released automatically
  • avoids dealing with an indirection (the resource is directly exposed)
//given at DbConnection type and a Pool<DbConnection> pool
pool.withPoolable(resource -> resource
    //we declare using the connection to create a Statement...
    .createStatement()
    //...then performing a SELECT query...
    .flatMapMany(st -> st.query("SELECT * FROM foo"))
    //...then marshalling the rows to JSON
    .map(row -> rowToJson(row))
    //(all of which need the live resource)
)
//at this point the rest of the steps are outside the scope
//so the resource can be released
.map(json -> sanitize(json));

Licensed under Apache Software License 2.0

You can’t perform that action at this time.