Refine search
@Override public void close() { httpClient.dispatcher().executorService().shutdown(); httpClient.connectionPool().evictAll(); }
private OkHttpClient createOkHttpClient(final NiFiProperties properties) { final String connectionTimeout = properties.getClusterNodeConnectionTimeout(); final long connectionTimeoutMs = FormatUtils.getTimeDuration(connectionTimeout, TimeUnit.MILLISECONDS); final String readTimeout = properties.getClusterNodeReadTimeout(); final long readTimeoutMs = FormatUtils.getTimeDuration(readTimeout, TimeUnit.MILLISECONDS); OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient().newBuilder(); okHttpClientBuilder.connectTimeout(connectionTimeoutMs, TimeUnit.MILLISECONDS); okHttpClientBuilder.readTimeout(readTimeoutMs, TimeUnit.MILLISECONDS); okHttpClientBuilder.followRedirects(true); final int connectionPoolSize = properties.getClusterNodeMaxConcurrentRequests(); okHttpClientBuilder.connectionPool(new ConnectionPool(connectionPoolSize, 5, TimeUnit.MINUTES)); final Tuple<SSLSocketFactory, X509TrustManager> tuple = createSslSocketFactory(properties); if (tuple != null) { okHttpClientBuilder.sslSocketFactory(tuple.getKey(), tuple.getValue()); } return okHttpClientBuilder.build(); }
@Override public boolean connectionBecameIdle( ConnectionPool pool, RealConnection connection) { return pool.connectionBecameIdle(connection); }
public static boolean isHttpsAvailable(Config config) { Config sslConfig = new ConfigBuilder(config) .withMasterUrl(Config.HTTPS_PROTOCOL_PREFIX + config.getMasterUrl()) .withRequestTimeout(1000) .withConnectionTimeout(1000) .build(); OkHttpClient client = HttpClientUtils.createHttpClient(config); try { Request request = new Request.Builder().get().url(sslConfig.getMasterUrl()) .build(); Response response = client.newCall(request).execute(); try (ResponseBody body = response.body()) { return response.isSuccessful(); } } catch (Throwable t) { LOG.warn("SSL handshake failed. Falling back to insecure connection."); } finally { if (client != null && client.connectionPool() != null) { client.connectionPool().evictAll(); } } return false; }
private static QueryId startQuery(String sql, DistributedQueryRunner queryRunner) OkHttpClient httpClient = new OkHttpClient(); try { ClientSession clientSession = new ClientSession( httpClient.dispatcher().executorService().shutdown(); httpClient.connectionPool().evictAll();
private static void closeOkHttpClient(@NotNull OkHttpClient client) { client.dispatcher().executorService().shutdown(); client.connectionPool().evictAll(); final Cache cache = client.cache(); if (cache != null) { try { cache.close(); } catch (IOException ignored) { } } }
OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectionPool(new ConnectionPool());
private void close() { client.connectionPool().evictAll(); // Close any persistent connections. }
private void aggressivelyCloseClients() throws Exception { clients.forEach( client -> { client.dispatcher().executorService().shutdown(); Observable.interval(100, TimeUnit.MILLISECONDS) .takeUntil( i -> { boolean canEvict = client.connectionPool().idleConnectionCount() == client.connectionPool().connectionCount(); client.connectionPool().evictAll(); return canEvict; }) .timeout(15, TimeUnit.SECONDS) .blockingSubscribe(); }); }
public static void main(String... args) throws Exception { Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(20)); dispatcher.setMaxRequests(20); dispatcher.setMaxRequestsPerHost(1); OkHttpClient okHttpClient = new OkHttpClient.Builder() .dispatcher(dispatcher) .connectionPool(new ConnectionPool(100, 30, TimeUnit.SECONDS)) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(HttpUrl.get("https://example.com/")) .addConverterFactory(PageAdapter.FACTORY) .client(okHttpClient) .build(); PageService pageService = retrofit.create(PageService.class); Crawler crawler = new Crawler(pageService); crawler.crawlPage(HttpUrl.get(args[0])); }
private static void testClient(List<String> urls, OkHttpClient client) { try { for (String url : urls) { sendRequest(client, url); } } finally { client.dispatcher.executorService().shutdownNow(); client.connectionPool.evictAll(); } }
@Override public void put(ConnectionPool pool, RealConnection connection) { pool.put(connection); }
if (pruneAndGetAllocationCount(connection, now) > 0) { inUseConnectionCount++; continue;
private void postToSlack(String url, String payload) { RequestBody body = new FormBody.Builder() .add("payload", payload) .build(); Request request = new Request.Builder() .url(url) .post(body) .build(); Call call = singletonInstance.newCall(request); try (Response response = call.execute()) { if (!response.isSuccessful()) { String message = "status: " + response.code() + ", message: " + response.body().string(); throw new IOException(message); } } catch (IOException e) { e.printStackTrace(); } finally { singletonInstance.connectionPool().evictAll(); } } }
private static QueryId startQuery(String sql, DistributedQueryRunner queryRunner) OkHttpClient httpClient = new OkHttpClient(); try { ClientSession clientSession = new ClientSession( httpClient.dispatcher().executorService().shutdown(); httpClient.connectionPool().evictAll();
private static void shutdown(OkHttpClient client) throws IOException { client.dispatcher().executorService().shutdown(); client.connectionPool().evictAll(); final Cache cache = client.cache(); if (cache != null) { cache.close(); } } }
@Override public void shutdown() { executorService.shutdown(); client.connectionPool().evictAll(); }
.connectionPool(new ConnectionPool(0, 1, TimeUnit.SECONDS)) .dns(hostname -> { if (hostname.endsWith(SOCKET_SUFFIX)) {
@Override public void put(ConnectionPool pool, RealConnection connection) { pool.put(connection); }
if (pruneAndGetAllocationCount(connection, now) > 0) { inUseConnectionCount++; continue;