private static <T> Eventual<T> fromMono(Mono<T> mono) { return new Eventual<>(mono); }
@Override public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) { return new Eventual<>(client.sendRequest(request)); } }
@Override public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) { return new Eventual<>(client.sendRequest(request)); }
private Collection<RemoteHost> pools(OriginState state) { return origins.values().stream() .filter(origin -> origin.state().equals(state)) .map(origin -> { HttpHandler hostClient = (request, context) -> new Eventual<>(origin.hostClient.sendRequest(request)); return remoteHost(origin.origin, hostClient, origin.hostClient); }) .collect(toList()); }
@Override public Eventual<LiveHttpResponse> handle(LiveHttpRequest request, HttpInterceptor.Context context) { return new Eventual<>(toPublisher(Observable.<LiveHttpResponse>create(this::reload) .subscribeOn(Schedulers.from(executor)))); }
private HttpHandler newClientHandler(BackendService backendService, OriginsInventory originsInventory, OriginStatsFactory originStatsFactory) { BackendServiceClient client = clientFactory.createClient(backendService, originsInventory, originStatsFactory); return (request, context) -> new Eventual<>(client.sendRequest(request)); }
@Test public void createFromPublisher() { String value = Mono.from(new Eventual<>(Flux.just("hello"))).block(); assertEquals(value, "hello"); }
@Override public Eventual<LiveHttpResponse> proceed(LiveHttpRequest request) { try { return new Eventual<>( toPublisher(toObservable(chain.proceed(request)) .doOnNext(response -> upstreamStatus = response.status()) .doOnError(error -> upstreamException = true))); } catch (Throwable e) { upstreamException = true; throw propagate(e); } } }
@Override public Eventual<LiveHttpResponse> proceed(LiveHttpRequest request) { requestTracker.trackRequest(request); if (index < interceptors.size()) { HttpInterceptor.Chain chain = new HttpInterceptorChain(this, index + 1); HttpInterceptor interceptor = interceptors.get(index); try { return interceptor.intercept(request, chain); } catch (Throwable e) { return Eventual.error(e); } } requestTracker.markRequestAsSent(request); return new Eventual<>(toPublisher(toObservable(client.handle(request, this.context)) .compose(StandardHttpPipeline::sendErrorOnDoubleSubscription))); } }
@Test public void mapsValues() { StepVerifier.create(new Eventual<>(Flux.just("hello")).map(String::toUpperCase)) .expectNext("HELLO") .verifyComplete(); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain originalChain) { StatusRecordingChain chain = new StatusRecordingChain(originalChain); try { return new Eventual<>(toPublisher( toObservable(plugin.intercept(request, chain)) .doOnNext(response -> recordStatusCode(chain, response)) .onErrorResumeNext(error -> error(recordAndWrapError(chain, error))))); } catch (Throwable e) { recordException(e); return Eventual.error(new PluginException(e, plugin.name())); } }