-
Notifications
You must be signed in to change notification settings - Fork 136
ReactPools
ReactPool provides a mechanism for caching simple-react REACTORs (SimpleReact, EagerReact, LazyReact). You can use a ReactPool to manage configured REACTORs or create new ones as needed elastically.
- bounded : to use a bounded ReactPool supply a collection of REACTORs on intiatialisation. These will be the only REACTORs allowed with the pool
- unbounded : creation of an unbounded ReactPool is similar to unbounded ReactPool - in that users provide the initial REACTORs. The pool will accept additions later on however, if needed.
- synchronous : a synchronous ReactPool will only allow a single ReactPool to be used, being transferred synchronously between clients (when one finishes, another can start).
- elastic : an elastic ReactPool will create new REACTORs on demand.
Elastic SimpleReact pool :
ReactPool<LazyReact> pool = ReactPool.elasticPool(()->new SimpleReact());
Elastic EagerReact pool :
ReactPool<LazyReact> pool = ReactPool.elasticPool(()->new EagerReact());
Elastic LazyReact pool :
ReactPool<LazyReact> pool = ReactPool.elasticPool(()->new LazyReact());
To use the pool
List<String> result = pool.react( (REACTOR) -> REACTOR.react(()->"hello",()->"world").block() );
Clients will share instances already created within the pool where available, but new ones will be created if neccessary.
simple-react provides a range of both Parallel and Sequential React Pools pre-configured.
-
ParallelElasticPools.simpleReact : SimpleReact pool with each REACTOR having parallelism equal to number of processors
-
ParallelElasticPools.eagerReact : EagerReact pool with each REACTOR having parallelism equal to number of processors
-
ParallelElasticPools.lazyReact : LazyReact pool with each REACTOR having parallelism equal to number of processors
-
SequentialElasticPools.simpleReact : SimpleReact pool with each REACTOR having parallelism of 1
-
SequentialElasticPools.eagerReact : EagerReact pool with each REACTOR having parallelism of 1
-
SequentialElasticPools.lazyReact : LazyReact pool with each REACTOR having parallelism of 1
To create a bounded pool, pass in a collection of REACTORs
ReactPool<EagerReact> pool = ReactPool.boundedPool(asList(new EagerReact(),new EagerReact()));
Any attempt to execute a Stream using the pool, will use one of the preconfigured REACTORs or block until one becomes free.
pool.react( (er) -> er.react(()->loadData(),()->loadData()).then(DAO::save));
pool.react( (er) -> er.react(()->loadData(),()->loadData()).then(DAO::save));
pool.react( (er) -> er.react(()->loadData(),()->loadData()).then(DAO::save));
pool.react( (er) -> er.react(()->loadData(),()->loadData()).then(DAO::save));
If the pool has two REACTORs available, the 3rd and 4th request will likely be blocked for sometime, until a new REACTOR becomes available.
oops - my bad