@Override protected void configure() { ObjectMapper objectMapper = JavaUtils.newObjectMapper(); Builder httpConfigBuilder = HttpConfig.newBuilder().setObjectMapper(objectMapper); bind(ObjectMapper.class).annotatedWith(Names.named(MESOS_CLIENT_OBJECT_MAPPER)).toInstance(objectMapper); bind(HttpClient.class).annotatedWith(Names.named(SingularityMesosClient.DEFAULT_HTTP_CLIENT_NAME)) .toInstance(new NingHttpClient(httpConfigBuilder.build())); bind(HttpClient.class).annotatedWith(Names.named(SingularityMesosClient.SHORT_TIMEOUT_HTTP_CLIENT_NAME)) .toInstance(new NingHttpClient(httpConfigBuilder.setRequestTimeoutSeconds(MESOS_CLIENT_HTTP_SHORT_TIMEOUT_SECONDS).build())); bind(MesosClient.class).to(SingularityMesosClient.class).in(Scopes.SINGLETON); }
@Override public ListenableFuture<HttpResponse> execute(HttpRequest request, Options options) { return internalExecute(request, options, EmptyCallback.INSTANCE); }
@Override public void close() throws IOException { delegate.close(); } }
public NingAsyncHttpClient(HttpConfig config) { Preconditions.checkNotNull(config); NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); int workerThreads = Math.min(Runtime.getRuntime().availableProcessors(), 4); this.workerExecutorService = newWorkerThreadPool(workerThreads); this.channelFactory = newSocketChannelFactory(this.workerExecutorService, workerThreads); nettyConfig.setSocketChannelFactory(this.channelFactory); nettyConfig.setNettyTimer(TIMER); AsyncHttpClientConfig ningConfig = new AsyncHttpClientConfig.Builder() .addRequestFilter(new ThrottleRequestFilter(config.getMaxConnections())) .addRequestFilter(new AcceptEncodingRequestFilter()) .setMaxConnectionsPerHost(config.getMaxConnectionsPerHost()) .setConnectTimeout(config.getConnectTimeoutMillis()) .setRequestTimeout(config.getRequestTimeoutMillis()) .setReadTimeout(config.getRequestTimeoutMillis()) .setMaxRedirects(config.getMaxRedirects()) .setFollowRedirect(config.isFollowRedirects()) .setHostnameVerifier(new NingHostnameVerifier(config.getSSLConfig())) .setSSLContext(NingSSLContext.forConfig(config.getSSLConfig())) .setAsyncHttpClientProviderConfig(nettyConfig) .setUserAgent(config.getUserAgent()) .setIOThreadMultiplier(1) .build(); this.ningClient = new com.ning.http.client.AsyncHttpClient(ningConfig); this.requestConverter = new NingHttpRequestConverter(config.getObjectMapper()); this.defaultOptions = config.getOptions(); this.mapper = config.getObjectMapper(); }
public NingHttpClient(HttpConfig config) { this.delegate = new NingAsyncHttpClient(Preconditions.checkNotNull(config)); }
@Override public ListenableFuture<HttpResponse> execute(HttpRequest request) { return execute(Preconditions.checkNotNull(request), Options.DEFAULT); }
private static ExecutorService newExecutor(String qualifier) { return Executors.newCachedThreadPool(newThreadFactory(qualifier)); }
@Override public HttpResponse execute(HttpRequest request) throws HttpRuntimeException { return execute(Preconditions.checkNotNull(request), Options.DEFAULT); }
@Override protected void configure() { ObjectMapper objectMapper = JavaUtils.newObjectMapper(); objectMapper.registerModule(new GuavaModule()); objectMapper.registerModule(new Jdk8Module()); HttpClient httpClient = new NingHttpClient(httpConfig.or(HttpConfig.newBuilder().setObjectMapper(objectMapper).build())); bind(HttpClient.class).annotatedWith(Names.named(HTTP_CLIENT_NAME)).toInstance(httpClient); bind(SingularityClient.class).toProvider(SingularityClientProvider.class).in(Scopes.SINGLETON); if (hosts != null) { bindHosts(binder()).toInstance(hosts); } }
) { this.nioHttpClient = nioHttpClientFactory.wrap( new NingAsyncHttpClient( config.getHttpConfig().orElse(DEFAULT_CONFIG)
@Override public void execute(HttpRequest request, Callback callback) { execute(Preconditions.checkNotNull(request), Options.DEFAULT, callback); }
@Override public void execute(HttpRequest request, Options options, Callback callback) { internalExecute(request, options, callback); }
private static ExecutorService newWorkerThreadPool(int threads) { ThreadPoolExecutor workerPool = new ThreadPoolExecutor( threads, threads, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), newThreadFactory("NioWorker") ); workerPool.allowCoreThreadTimeOut(true); return workerPool; }
@Override protected void configure() { HttpClient httpClient = new NingHttpClient(HttpConfig.newBuilder() .setObjectMapper(buildObjectMapper()) .build()); bind(HttpClient.class).annotatedWith(Names.named(HTTP_CLIENT_NAME)).toInstance(httpClient); bind(BaragonServiceClient.class).toProvider(BaragonClientProvider.class).in(Scopes.SINGLETON); if (hosts != null) { bindHosts(binder()).toInstance(hosts); } }
@Override public HttpResponse execute(HttpRequest request, Options options) throws HttpRuntimeException { Preconditions.checkNotNull(request); Preconditions.checkNotNull(options); try { return delegate.execute(request, options).get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new HttpRuntimeException(e); } catch (ExecutionException e) { Throwables.propagateIfInstanceOf(e.getCause(), HttpRuntimeException.class); throw new HttpRuntimeException(e.getCause()); } }