use of reactor.core.publisher.SignalType in project cf-java-client by cloudfoundry.
the class OperationsLogging method log.
@SuppressWarnings("unchecked")
public static <T extends Publisher<U>, U> Function<T, T> log(String message) {
if (!LOGGER.isDebugEnabled()) {
return f -> f;
}
AtomicLong startTimeHolder = new AtomicLong();
Consumer<Subscription> start = subscription -> {
startTimeHolder.set(System.currentTimeMillis());
LOGGER.debug("START {}", message);
};
Consumer<SignalType> finish = signalType -> {
String elapsed = TimeUtils.asTime(System.currentTimeMillis() - startTimeHolder.get());
LOGGER.debug("FINISH {} ({}/{})", message, signalType, elapsed);
};
return f -> {
if (f instanceof Mono) {
return (T) ((Mono<U>) f).doOnSubscribe(start).doFinally(finish);
}
if (f instanceof Flux) {
return (T) ((Flux<U>) f).doOnSubscribe(start).doFinally(finish);
} else {
return f;
}
};
}
Aggregations