@Override public void run() { try { HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor(); IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, sslContext, connectionConfig); ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } } }, "jsonrpc4j HTTP IOReactor");
public void shutdown(long waitMs) throws IOException { ioReactor.shutdown(waitMs); }
public IOReactorStatus getStatus() { return ioReactor.getStatus(); }
public HttpRequestFuture executeRequest(InetSocketAddress address, HttpRequest request) { HttpRequestFutureImpl future = new HttpRequestFutureImpl(request, params); ioReactor.connect(address, null, future, sesionRequestHandler); return future; }
public boolean process(Exchange exchange, AsyncCallback callback) { if (LOG.isDebugEnabled()) { LOG.debug("processAsync: " + exchange); } SocketAddress addr = new InetSocketAddress(getEndpoint().getHost(), getEndpoint().getPort()); exchange.setProperty(AsyncCallback.class.getName(), callback); SessionRequest req = ioReactor.connect(addr, null, exchange, new MySessionRequestCallback()); return false; }
public void shutdown() throws IOException { ioReactor.shutdown(); }
public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.error("event=failed_to_initialize_async_http_client action=exiting", ex); } catch (IOException ex) { logger.error("event=failed_to_initialize_async_http_client action=exiting", ex); } }
public void handleRedirect(HttpRequestFutureImpl state, HttpContext context) throws IOException { NHttpClientConnection connection = (NHttpClientConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION); List<HttpRequest> redirects = state.getRedirects(); HttpRequest initial = redirects.size() > 1 ? redirects.get(redirects.size() - 2) : state.getRequest(); HttpRequest redirect = redirects.get(redirects.size() - 1); HttpHost initialHost = getHost(initial); HttpHost redirectHost = getHost(redirect); log.debug("Redirected to {} from {}", redirectHost, initial); if (initialHost.equals(redirectHost) || haveSameAddress(initialHost, redirectHost)) { try { connection.submitRequest(redirect); } catch (HttpException e) { state.failed(e); } } else { state.setActiveConnection(null); connection.close(); ioReactor.connect(new InetSocketAddress(redirectHost.getHostName(), redirectHost.getPort()), null, state, sesionRequestHandler); } }
protected void requestCancelled(final SessionRequest request) { if (this.isShutDown.get()) { return; } @SuppressWarnings("unchecked") final T route = (T) request.getAttachment(); this.lock.lock(); try { this.pending.remove(request); final RouteSpecificPool<T, C, E> pool = getPool(route); pool.cancelled(request); if (this.ioreactor.getStatus().compareTo(IOReactorStatus.ACTIVE) <= 0) { processNextPendingRequest(); } } finally { this.lock.unlock(); } fireCallbacks(); }
@Override protected void doStop() throws Exception { ioReactor.shutdown(); runner.join(); super.doStop(); }
public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { log.error("Web thread interrupted.", ex); } catch (IOException e) { log.error("I/O error in web thread.", e); } log.debug("Shutdown web thread."); } });
/** * Return a connection to the host:port pair. If a connection is not available * return <code>null</code>. If the particular host:port allows to create more connections * this method will try to connect asynchronously. If the connection is successful it will * be notified in a separate thread. * * @param route Http route * @return Either returns a connection if already available or returns null and notifies * the delivery agent when the connection is available */ public NHttpClientConnection getConnection(HttpRoute route) { if (log.isDebugEnabled()) { log.debug("Trying to get a connection " + route); } HostConnections pool = getConnectionPool(route); // trying to get an existing connection NHttpClientConnection connection = pool.getConnection(); if (connection == null) { if (pool.canHaveMoreConnections()) { HttpHost host = route.getProxyHost() != null ? route.getProxyHost() : route.getTargetHost(); ioReactor.connect(new InetSocketAddress(host.getHostName(), host.getPort()), null, pool, callback); } else { log.warn("Connection pool reached maximum allowed connections for route " + route + ". Target server may have become slow"); } } else { return connection; } return null; }
protected void requestCancelled(final SessionRequest request) { if (this.isShutDown.get()) { return; } @SuppressWarnings("unchecked") final T route = (T) request.getAttachment(); this.lock.lock(); try { this.pending.remove(request); final RouteSpecificPool<T, C, E> pool = getPool(route); pool.cancelled(request); if (this.ioreactor.getStatus().compareTo(IOReactorStatus.ACTIVE) <= 0) { processNextPendingRequest(); } } finally { this.lock.unlock(); } fireCallbacks(); }
public void shutdown(final long waitMs) throws IOException { if (this.isShutDown.compareAndSet(false, true)) { fireCallbacks(); this.lock.lock(); try { for (final SessionRequest sessionRequest: this.pending) { sessionRequest.cancel(); } for (final E entry: this.available) { entry.close(); } for (final E entry: this.leased) { entry.close(); } for (final RouteSpecificPool<T, C, E> pool: this.routeToPool.values()) { pool.shutdown(); } this.routeToPool.clear(); this.leased.clear(); this.pending.clear(); this.available.clear(); this.leasingRequests.clear(); this.ioreactor.shutdown(waitMs); } finally { this.lock.unlock(); } } }
public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { LOG.info("Interrupted"); } catch (IOException e) { LOG.warn("I/O error: " + e.getMessage()); } LOG.debug("Shutdown"); }
final SessionRequest sessionRequest = this.ioreactor.connect( remoteAddress, localAddress, route, this.sessionRequestCallback); final int timout = request.getConnectTimeout() < Integer.MAX_VALUE ?
public void shutdown(final long waitMs) throws IOException { if (this.isShutDown.compareAndSet(false, true)) { fireCallbacks(); this.lock.lock(); try { for (final SessionRequest sessionRequest: this.pending) { sessionRequest.cancel(); } for (final E entry: this.available) { entry.close(); } for (final E entry: this.leased) { entry.close(); } for (final RouteSpecificPool<T, C, E> pool: this.routeToPool.values()) { pool.shutdown(); } this.routeToPool.clear(); this.leased.clear(); this.pending.clear(); this.available.clear(); this.leasingRequests.clear(); this.ioreactor.shutdown(waitMs); } finally { this.lock.unlock(); } } }
@Override public void run() { try { ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { getLogger().error("I/O reactor Interrupted", ex); } catch (IOException e) { getLogger().error("I/O error: " + e.getMessage(), e); } getLogger().info("I/O reactor terminated"); } }, "Couchbase View Thread");
final SessionRequest sessionRequest = this.ioreactor.connect( remoteAddress, localAddress, route, this.sessionRequestCallback); final int timout = request.getConnectTimeout() < Integer.MAX_VALUE ?