• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Dispatcher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PEPItem类代码示例发布时间:2022-05-23
下一篇:
Java Contains类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap