Search in sources :

Example 41 with Dispatcher

use of mockwebserver3.Dispatcher in project dropbox-sdk-java by dropbox.

the class OkHttp3RequestorTest method testCustomDispatcher.

@Test
public void testCustomDispatcher() {
    OkHttpClient.Builder client = new OkHttpClient.Builder();
    // should be fine with default Dispatcher
    new OkHttp3Requestor(client.build());
    // should also be fine with other common executors that run on separate threads
    client.dispatcher(new Dispatcher(Executors.newSingleThreadExecutor()));
    new OkHttp3Requestor(client.build());
    client.dispatcher(new Dispatcher(Executors.newCachedThreadPool()));
    new OkHttp3Requestor(client.build());
    client.dispatcher(new Dispatcher(Executors.newFixedThreadPool(3)));
    new OkHttp3Requestor(client.build());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Test(org.testng.annotations.Test)

Example 42 with Dispatcher

use of mockwebserver3.Dispatcher in project MVP by yuchengren.

the class OkHttpUtil method getQueuedAndRunningCallList.

public List<Call> getQueuedAndRunningCallList() {
    Dispatcher dispatcher = mOkHttpClient.dispatcher();
    List<Call> callList = new ArrayList<>();
    callList.addAll(dispatcher.queuedCalls());
    callList.addAll(dispatcher.runningCalls());
    return callList;
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) Dispatcher(okhttp3.Dispatcher)

Example 43 with Dispatcher

use of mockwebserver3.Dispatcher in project MVP by yuchengren.

the class OkHttpUtil method getQueuedAndRunningCallList.

public List<Call> getQueuedAndRunningCallList() {
    Dispatcher dispatcher = mOkHttpClient.dispatcher();
    List<Call> callList = new ArrayList<>();
    callList.addAll(dispatcher.queuedCalls());
    callList.addAll(dispatcher.runningCalls());
    return callList;
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) Dispatcher(okhttp3.Dispatcher)

Example 44 with Dispatcher

use of mockwebserver3.Dispatcher in project CubedPay-Java by MelonDevelopment.

the class CubedPayAPI method shutdown.

default void shutdown() throws InterruptedException {
    Dispatcher dispatcher = DispatcherMap.dispatcherMap.remove(this);
    dispatcher.cancelAll();
    dispatcher.executorService().shutdown();
    dispatcher.executorService().awaitTermination(10, TimeUnit.SECONDS);
    for (ExecutorService executor : EventMap.eventMap.values()) {
        executor.shutdown();
        executor.awaitTermination(10, TimeUnit.SECONDS);
    }
}
Also used : Dispatcher(okhttp3.Dispatcher)

Example 45 with Dispatcher

use of mockwebserver3.Dispatcher in project CubedPay-Java by MelonDevelopment.

the class CubedPayAPI method create.

static CubedPayAPI create(String appID, String accessToken, String apiUrl) {
    Dispatcher dispatcher = new Dispatcher();
    CubedPayAPI api = new Retrofit.Builder().baseUrl(apiUrl).addConverterFactory(new Converter.Factory() {

        @Override
        public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
            return super.responseBodyConverter(type, annotations, retrofit);
        }
    }).addConverterFactory(new APIEnvelopeTransformerConverterFactory(GsonConverterFactory.create())).addCallAdapterFactory(Java8CallAdapterFactory.create()).client(new OkHttpClient.Builder().addInterceptor(chain -> chain.proceed(chain.request().newBuilder().addHeader("app-id", appID).url(chain.request().url().newBuilder().addQueryParameter("access_token", accessToken).build()).build())).dispatcher(dispatcher).build()).build().create(CubedPayAPI.class);
    DispatcherMap.dispatcherMap.put(api, dispatcher);
    return api;
}
Also used : APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) Converter(retrofit2.Converter) co.melondev.cubedpay.data(co.melondev.cubedpay.data) java.util.concurrent(java.util.concurrent) HashMap(java.util.HashMap) CubedEventRunnable(co.melondev.cubedpay.event.CubedEventRunnable) Retrofit(retrofit2.Retrofit) Dispatcher(okhttp3.Dispatcher) CubedAnnotationProcessor(co.melondev.cubedpay.event.CubedAnnotationProcessor) Java8CallAdapterFactory(retrofit2.adapter.java8.Java8CallAdapterFactory) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) Type(java.lang.reflect.Type) retrofit2.http(retrofit2.http) Map(java.util.Map) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) Annotation(java.lang.annotation.Annotation) CubedEvent(co.melondev.cubedpay.event.CubedEvent) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit) Type(java.lang.reflect.Type) Java8CallAdapterFactory(retrofit2.adapter.java8.Java8CallAdapterFactory) APIEnvelopeTransformerConverterFactory(co.melondev.cubedpay.envelope.APIEnvelopeTransformerConverterFactory) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) Dispatcher(okhttp3.Dispatcher) ResponseBody(okhttp3.ResponseBody)

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