com.squareup.okhttp.Dispatcher Java Examples

The following examples show how to use com.squareup.okhttp.Dispatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OkHttpRequestorTest.java    From dropbox-sdk-java with MIT License 6 votes vote down vote up
@Test
public void testCustomDispatcher() {
    OkHttpClient client = new OkHttpClient();

    // should be fine with default Dispatcher
    new OkHttpRequestor(client);

    // should also be fine with other common executors that run on separate threads
    client.setDispatcher(new Dispatcher(Executors.newSingleThreadExecutor()));
    new OkHttpRequestor(client);

    client.setDispatcher(new Dispatcher(Executors.newCachedThreadPool()));
    new OkHttpRequestor(client);

    client.setDispatcher(new Dispatcher(Executors.newFixedThreadPool(3)));
    new OkHttpRequestor(client);
}
 
Example #2
Source File: OkHttpStack.java    From OkVolley with Apache License 2.0 5 votes vote down vote up
/**
 * set dispatcher to OkHttpClient
 * @param dispatcher {@link OkHttpClient}.setDispatcher({@link Dispatcher})
 */
public void setDispatcher(Dispatcher dispatcher) {
    if (dispatcher == null) {
        return;
    }
    this.mClient.setDispatcher(dispatcher);
}
 
Example #3
Source File: OkHttpRequestorTest.java    From dropbox-sdk-java with MIT License 5 votes vote down vote up
@Test(expectedExceptions={ IllegalArgumentException.class })
public void testSameThreadDispatcher() {
    OkHttpClient client = new OkHttpClient();

    // should fail for same-thread executors
    client.setDispatcher(new Dispatcher(MoreExecutors.newDirectExecutorService()));
    new OkHttpRequestor(client);
}
 
Example #4
Source File: OkVolley.java    From OkVolley with Apache License 2.0 4 votes vote down vote up
public void setDispatcher(Dispatcher dispatcher) {
    if (dispatcher == null) {
        return;
    }
    getDefaultHttpStack().setDispatcher(dispatcher);
}