public final class SimpleMetricsSphereClient extends SphereClientDecorator implements SphereClient
SphereClient
s which collects the time of serialization from and to JSON
as well as the time waiting for the response from the Composable Commerce API.
public class SimpleMetricsSphereClientDemo {
public static SphereClient demo(final SphereClient asyncClient) {
final SimpleMetricsSphereClient simpleMetricsSphereClient = SimpleMetricsSphereClient.of(asyncClient);
final Observable observable = simpleMetricsSphereClient.getMetricObservable();
observable.addObserver(new LoggerObserver());//register once observer
return simpleMetricsSphereClient;//use metric client wrapper instead of async client directly
/*
logs something like:
observed: ObservedSerializationDuration[requestId=1,durationInMilliseconds=0,request=ProjectGet[]]
observed: ObservedDeserializationDuration[requestId=1,durationInMilliseconds=0,request=ProjectGet[]]
observed: ObservedTotalDuration[requestId=1,durationInMilliseconds=19,request=ProjectGet[]]
*/
}
public static class LoggerObserver implements Observer {
@Override
public void update(final Observable o, final Object arg) {
Logger.trace("observed: " + arg);
}
}
}
See the test code.
Modifier and Type | Method and Description |
---|---|
<T> CompletionStage<T> |
execute(SphereRequest<T> sphereRequest)
Executes asynchronously a request to Composable Commerce.
|
Observable |
getMetricObservable()
The observable where observers can be registered.
|
static SimpleMetricsSphereClient |
of(SphereClient delegate) |
close, getConfig
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
close, getConfig, of, of
public static SimpleMetricsSphereClient of(SphereClient delegate)
public <T> CompletionStage<T> execute(SphereRequest<T> sphereRequest)
SphereClient
execute
in interface SphereClient
execute
in class SphereClientDecorator
T
- type of the result for the requestsphereRequest
- request to Composable Commerce to performpublic Observable getMetricObservable()