本文整理汇总了Java中com.squareup.okhttp.Dispatcher类的典型用法代码示例。如果您正苦于以下问题:Java Dispatcher类的具体用法?Java Dispatcher怎么用?Java Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Dispatcher类属于com.squareup.okhttp包,在下文中一共展示了Dispatcher类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testCustomDispatcher
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
@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);
}
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:18,代码来源:OkHttpRequestorTest.java
示例2: setDispatcher
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
/**
* set dispatcher to OkHttpClient
* @param dispatcher {@link OkHttpClient}.setDispatcher({@link Dispatcher})
*/
public void setDispatcher(Dispatcher dispatcher) {
if (dispatcher == null) {
return;
}
this.mClient.setDispatcher(dispatcher);
}
开发者ID:googolmo,项目名称:OkVolley,代码行数:11,代码来源:OkHttpStack.java
示例3: prepare
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
@Override public void prepare(final Benchmark benchmark) {
concurrencyLevel = benchmark.concurrencyLevel;
targetBacklog = benchmark.targetBacklog;
client = new OkHttpClient();
client.setProtocols(benchmark.protocols);
client.setDispatcher(new Dispatcher(new ThreadPoolExecutor(benchmark.concurrencyLevel,
benchmark.concurrencyLevel, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>())));
if (benchmark.tls) {
SSLContext sslContext = SslContextBuilder.localhost();
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override public boolean verify(String s, SSLSession session) {
return true;
}
};
client.setSslSocketFactory(socketFactory);
client.setHostnameVerifier(hostnameVerifier);
}
receiver = new Response.Receiver() {
@Override public void onFailure(Failure failure) {
System.out.println("Failed: " + failure.exception());
}
@Override public boolean onResponse(Response response) throws IOException {
Response.Body body = response.body();
long total = SynchronousHttpClient.readAllAndClose(body.byteStream());
long finish = System.nanoTime();
if (VERBOSE) {
long start = (Long) response.request().tag();
System.out.printf("Transferred % 8d bytes in %4d ms%n",
total, TimeUnit.NANOSECONDS.toMillis(finish - start));
}
requestsInFlight.decrementAndGet();
return true;
}
};
}
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:41,代码来源:OkHttpAsync.java
示例4: testSameThreadDispatcher
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
@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);
}
开发者ID:dropbox,项目名称:dropbox-sdk-java,代码行数:9,代码来源:OkHttpRequestorTest.java
示例5: createClient
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
private ElasticSearchOkHttpClientImpl createClient(MapWrap config) {
boolean isPrefix;
String index;
String url = config.asString("url");
if (config.exists("index_prefix")) {
isPrefix = true;
index = config.asString("index_prefix");
} else {
isPrefix = false;
index = config.asString("index");
}
String cacheKey = cacheKey(url, index, isPrefix);
if (cachedClients.containsKey(cacheKey)) {
LOGGER.trace("Using cached Elasticsearch client");
return cachedClients.get(cacheKey);
}
LOGGER.trace("Creating new Elasticsearch client");
final ElasticSearchOkHttpClientImpl es = new ElasticSearchOkHttpClientImpl (
url,
index,
config.asString("type"),
isPrefix);
if (config.exists("document_id")) {
es.withDocumentId(config.asString("document_id"));
}
if (config.exists("signer")) {
es.withSigner(config.getObject("signer"));
}
if (config.exists("basic_auth")) {
if (config.exists("signer")) {
LOGGER.warn("A client cannot have both signed (AWS) and basic auth. Disabling basic auth");
} else {
String auth = config.asString("basic_auth");
if (!auth.contains(":")) {
throw new IllegalArgumentException("Invalid basic_auth value, expected 'user:passwd' but was " + auth);
}
if (auth.length() > 1) {
String[] split = auth.split(":");
es.withBasicAuth(split[0], split[1]);
}
}
}
if (config.exists("timestamp_field")) {
es.withTimestampField(config.asString("timestamp_field"));
}
if (config.exists("retry")) {
MapWrap retryConfig = MapWrap.of(config.getObject("retry")).assertExists("policy");
es.withRetryTimer(Observables.timer(retryConfig), retryConfig.asInt("attempts", DEFAULT_ATTEMPTS));
}
if (config.exists("dispatcher")) {
LOGGER.info("Configuring http dispatcher");
MapWrap dispatchConfig = MapWrap.of(config.getObject("dispatcher"));
Dispatcher dispatcher = dispatchConfig.exists("threadpool")
? new Dispatcher(dispatchConfig.getObject("threadpool"))
: new Dispatcher();
dispatcher.setMaxRequests(dispatchConfig.exists("max_concurrent_requests")
? dispatchConfig.asInt("max_concurrent_requests")
: dispatcher.getMaxRequests());
dispatcher.setMaxRequestsPerHost(dispatchConfig.exists("max_concurrent_requests")
? dispatchConfig.asInt("max_concurrent_requests")
: dispatcher.getMaxRequestsPerHost());
es.withDispatcher(dispatcher);
}
cachedClients.put(cacheKey, es);
return es;
}
开发者ID:sonyxperiadev,项目名称:lumber-mill,代码行数:77,代码来源:ElasticsearchClientFactory.java
示例6: setDispatcher
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
public void setDispatcher(Dispatcher dispatcher) {
if (dispatcher == null) {
return;
}
getDefaultHttpStack().setDispatcher(dispatcher);
}
开发者ID:googolmo,项目名称:OkVolley,代码行数:7,代码来源:OkVolley.java
示例7: setDispatcher
import com.squareup.okhttp.Dispatcher; //导入依赖的package包/类
/**
* Set an optional {@link Dispatcher} for better control of asynchronous requests.
*
* @param dispatcher
* the dispatcher
*/
@Inject(optional = true)
public void setDispatcher(final Dispatcher dispatcher) {
this.dispatcher = dispatcher;
}
开发者ID:mgm-tp,项目名称:perfload-core,代码行数:11,代码来源:OkHttpClientProvider.java
注:本文中的com.squareup.okhttp.Dispatcher类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论