Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidmoten/rxjava3-pool
https://github.com/davidmoten/rxjava3-pool
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/davidmoten/rxjava3-pool
- Owner: davidmoten
- License: apache-2.0
- Created: 2022-08-14T03:05:51.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T02:41:19.000Z (7 months ago)
- Last Synced: 2024-04-05T03:33:06.990Z (7 months ago)
- Language: Java
- Size: 438 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rxjava3-pool
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.davidmoten/rxjava3-pool-runtime/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.davidmoten/rxjava3-pool)
[![codecov](https://codecov.io/gh/davidmoten/rxjava3-pool/branch/master/graph/badge.svg)](https://codecov.io/gh/davidmoten/rxjava3-pool)Reactive object pool for use with RxJava 3.x. A core artifact for [rxjava3-jdbc](https://github.com/davidmoten/rxjava3-jdbc).
A pool is initialized with `n` Member objects where `n` is the maximum size of the pool.
Each Member object is either empty or holds an initialized value (like a database connection for example).
The state diagram for a Member is below. The states in green have entry procedures that can be run on user-specified schedulers (see example of creating a `NonBlockingPool` below).
A `Pool` conforms to this interface:
```java
public interface Pool extends AutoCloseable {Single> member();
}
```
A `Member` is an interface like this (slightly simplified):
```java
public interface Member {T value();
/**
* This method should not throw. Feel free to add logging so that you are aware
* of a problem with disposal.
*/
void disposeValue();
void checkin();
}
```This library provides one implementation of `Pool` being `NonBlockingPool`. Here's an example to create one:
```java
Pool pool =
NonBlockingPool
.factory(() -> DriverManager.getConnection(url))
.checkinDecorator(checkInDecorator)
.idleTimeBeforeHealthCheck(30, TimeUnit.SECONDS)
.maxIdleTime(300, TimeUnit.SECONDS)
.createRetryInterval(10, TimeUnit.SECONDS)
.scheduler(Schedulers.io())
.disposer(c -> {try { c.close();} catch (Throwable e) {log.warn(e.getMessage(),e);}})
.healthCheck(c -> true)
.scheduler(Schedulers.io())
.maxSize(10)
.build();
```The `Single` returned by `Pool.member()` can be subscribed to as many times as you like, concurrently if desired. The subscriber will be emitted to with a `Member` that has a value and when the subscriber has finished should call `Member.checkin()` to return the item to the pool.
Note that the *dispose* action should not throw, nor should the *checker* action. The *initializing* action may throw and if it does will be subject to retries on user-specified interval.