use of org.davidmoten.rx.jdbc.pool.PoolClosedException in project rxjava2-jdbc by davidmoten.
the class NonBlockingPool method createMembers.
private Flowable<Member<T>> createMembers() {
List<Member<T>> ms = IntStream.range(1, maxSize + 1).mapToObj(//
n -> memberFactory.create(NonBlockingPool.this)).collect(Collectors.toList());
Flowable<Member<T>> baseMembers = //
Flowable.fromIterable(ms).doOnRequest(n -> log.debug("requested={}", n));
Flowable<Member<T>> returnedMembers = //
subject.toSerialized().toFlowable(BackpressureStrategy.BUFFER);
// use CAS loop to handle a race with close
while (true) {
List<Member<T>> l = list.get();
if (l == null) {
return Flowable.error(new PoolClosedException());
} else if (list.compareAndSet(Collections.emptyList(), ms)) {
return //
returnedMembers.doOnNext(//
m -> log.debug("returned member reentering")).mergeWith(//
baseMembers).doOnNext(//
x -> log.debug("member={}", x)).<Member<T>>flatMap(member -> member.checkout().toFlowable(), false, //
1).doOnNext(x -> log.debug("checked out member={}", x));
}
}
}
Aggregations