Search in sources :

Example 6 with Dispatcher

use of mockwebserver3.Dispatcher in project hmftools by hartwigmedical.

the class SlicerHttpClient method create.

@NotNull
static OkHttpClient create(final int maxRequests) {
    final Dispatcher requestDispatcher = new Dispatcher();
    requestDispatcher.setMaxRequests(maxRequests);
    requestDispatcher.setMaxRequestsPerHost(maxRequests);
    return new OkHttpClient.Builder().connectionPool(new ConnectionPool(20, 1, TimeUnit.MINUTES)).readTimeout(20, TimeUnit.SECONDS).connectTimeout(20, TimeUnit.SECONDS).writeTimeout(20, TimeUnit.SECONDS).dispatcher(requestDispatcher).build();
}
Also used : ConnectionPool(okhttp3.ConnectionPool) Dispatcher(okhttp3.Dispatcher) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with Dispatcher

use of mockwebserver3.Dispatcher in project KalturaGeneratedAPIClientsJava by kaltura.

the class APIOkRequestsExecutor method cancelRequest.

@Override
public void cancelRequest(String reqId) {
    Dispatcher dispatcher = getOkClient(null).dispatcher();
    Call call = findCall(reqId, dispatcher.queuedCalls());
    if (call != null) {
        call.cancel();
    }
    call = findCall(reqId, dispatcher.runningCalls());
    if (call != null) {
        call.cancel();
    }
}
Also used : Call(okhttp3.Call) Dispatcher(okhttp3.Dispatcher)

Example 8 with Dispatcher

use of mockwebserver3.Dispatcher in project KalturaGeneratedAPIClientsJava by kaltura.

the class APIOkRequestsExecutor method hasRequest.

// TODO: cancel check on executor + null check on provider
// @Override
public boolean hasRequest(String reqId) {
    Dispatcher dispatcher = getOkClient(null).dispatcher();
    Call call = findCall(reqId, dispatcher.queuedCalls());
    if (call != null) {
        return true;
    }
    call = findCall(reqId, dispatcher.runningCalls());
    return call != null;
}
Also used : Call(okhttp3.Call) Dispatcher(okhttp3.Dispatcher)

Example 9 with Dispatcher

use of mockwebserver3.Dispatcher in project crnk-framework by crnk-project.

the class OkHttpBraveIntegration method onBuild.

@Override
public void onBuild(OkHttpClient.Builder builder) {
    Interceptor interceptor = TracingInterceptor.create(httpTracing);
    builder.addNetworkInterceptor(interceptor);
    builder.dispatcher(new Dispatcher(httpTracing.tracing().currentTraceContext().executorService(new Dispatcher().executorService())));
}
Also used : Dispatcher(okhttp3.Dispatcher) Interceptor(okhttp3.Interceptor) TracingInterceptor(brave.okhttp3.TracingInterceptor)

Example 10 with Dispatcher

use of mockwebserver3.Dispatcher in project butter-android by butterproject.

the class BaseProvider method cancel.

/**
 * This method will be called when user is done with data that he required. Provider should at this point
 * clean after itself. For example cancel all ongoing network request.
 */
@CallSuper
public void cancel() {
    final Dispatcher dispatcher = client.dispatcher();
    dispatcher.executorService().execute(new Runnable() {

        @Override
        public void run() {
            if (dispatcher.queuedCallsCount() > 0) {
                for (Call call : dispatcher.queuedCalls()) {
                    if (getClass().equals(call.request().tag())) {
                        call.cancel();
                    }
                }
            }
            if (dispatcher.runningCallsCount() > 0) {
                for (Call call : dispatcher.runningCalls()) {
                    if (getClass().equals(call.request().tag())) {
                        call.cancel();
                    }
                }
            }
        }
    });
}
Also used : Call(okhttp3.Call) Dispatcher(okhttp3.Dispatcher) CallSuper(android.support.annotation.CallSuper)

Aggregations

Dispatcher (okhttp3.Dispatcher)43 OkHttpClient (okhttp3.OkHttpClient)28 Before (org.junit.Before)14 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)10 IOException (java.io.IOException)9 Interceptor (okhttp3.Interceptor)7 Test (org.junit.Test)7 Call (okhttp3.Call)6 RecordedRequest (mockwebserver3.RecordedRequest)5 ApolloHttpCache (com.apollographql.apollo.cache.http.ApolloHttpCache)3 CustomTypeValue (com.apollographql.apollo.response.CustomTypeValue)3 ParseException (java.text.ParseException)3 MockResponse (mockwebserver3.MockResponse)3 ConnectionPool (okhttp3.ConnectionPool)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 Buffer (okio.Buffer)3 NonNull (android.support.annotation.NonNull)2 IdFieldCacheKeyResolver (com.apollographql.apollo.IdFieldCacheKeyResolver)2 Response (com.apollographql.apollo.api.Response)2