@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
GrizzlyResponseFuture(final AsyncHandler asyncHandler) { this.asyncHandler = asyncHandler; delegate = Futures.<V>createSafeFuture(); delegate.addCompletionHandler(this); }
private Charset getCharset(final String charset) { String charsetLocal = charset; if (charsetLocal == null) { charsetLocal = httpResponsePacket.getCharacterEncoding(); } return charsetLocal == null ? Charsets.ASCII_CHARSET : Charsets.lookupCharset(charsetLocal); } }
public IdleTimeoutFilter(final DelayedExecutor executor, final long timeout, final TimeUnit timeUnit, final TimeoutHandler handler) { this(executor, new DefaultWorker(handler), new IdleTimeoutResolver(convertToMillis(timeout, timeUnit))); }
delay = timeout - 10; timeoutExecutor = IdleTimeoutFilter.createDefaultIdleDelayedExecutor(delay, TimeUnit.MILLISECONDS); timeoutExecutor.start(); final IdleTimeoutFilter.TimeoutResolver timeoutResolver = new IdleTimeoutFilter.TimeoutResolver() { final IdleTimeoutFilter timeoutFilter = new IdleTimeoutFilter(timeoutExecutor, timeoutResolver, new IdleTimeoutFilter.TimeoutHandler() { resolver = timeoutFilter.getResolver();
@Override public void onError(Throwable t) { future.failure(makeIOException(t)); } });
@Override public void close() { try { connectionManager.destroy(); clientTransport.shutdownNow(); final ExecutorService service = clientConfig.executorService(); if (service != null) { service.shutdown(); } if (timeoutExecutor != null) { timeoutExecutor.stop(); timeoutExecutor.getThreadPool().shutdownNow(); } } catch (IOException ignored) { } }
void touchConnection(final Connection c, final Request request) { final long timeOut = request.getRequestTimeout() > 0 ? request.getRequestTimeout() : clientConfig.getRequestTimeout(); if (timeOut > 0) { if (resolver != null) { resolver.setTimeoutMillis(c, System.currentTimeMillis() + timeOut); } } }
((WebSocketUpgradeHandler) context.getAsyncHandler()).onSuccess(context.webSocket); final int wsTimeout = provider.getClientConfig().getWebSocketTimeout(); IdleTimeoutFilter.setCustomTimeout(ctx.getConnection(), (wsTimeout <= 0) ? IdleTimeoutFilter.FOREVER : wsTimeout, TimeUnit.MILLISECONDS);
public IdleTimeoutFilter(final DelayedExecutor executor, final long timeout, final TimeUnit timeUnit, final TimeoutHandler handler) { this(executor, new DefaultWorker(handler), new IdleTimeoutResolver(convertToMillis(timeout, timeUnit))); }
@Override public void onFailure(final Connection connection, final Throwable t) { connection.closeWithReason(Exceptions.makeIOException(t)); }
/** * This method will block if the async write queue is currently larger * than the configured maximum. The amount of time that this method * will block is dependent on the write timeout of the transport * associated with the specified connection. */ private static void blockUntilQueueFree(final Connection c) { if (!c.canWrite()) { final FutureImpl<Boolean> future = Futures.createSafeFuture(); // Connection may be obtained by calling FilterChainContext.getConnection(). c.notifyCanWrite(new WriteHandler() { @Override public void onWritePossible() throws Exception { future.result(TRUE); } @Override public void onError(Throwable t) { future.failure(makeIOException(t)); } }); block(c, future); } }
public IdleTimeoutFilter(final DelayedExecutor executor, final long timeout, final TimeUnit timeUnit, final TimeoutHandler handler) { this(executor, new DefaultWorker(handler), new IdleTimeoutResolver(convertToMillis(timeout, timeUnit))); }
@Override public void onError(Throwable t) { c.setMaxAsyncWriteQueueSize(feedableBodyGenerator.origMaxPendingBytes); c.closeWithReason(Exceptions.makeIOException(t)); }
public IdleTimeoutFilter(final DelayedExecutor executor, final long timeout, final TimeUnit timeUnit, final TimeoutHandler handler) { this(executor, new DefaultWorker(handler), new IdleTimeoutResolver(convertToMillis(timeout, timeUnit))); }
@Override public void exceptionOccurred(final FilterChainContext ctx, final Throwable error) { ctx.getCloseable().closeWithReason(Exceptions.makeIOException(error)); }
public IdleTimeoutFilter(final DelayedExecutor executor, final long timeout, final TimeUnit timeUnit, final TimeoutHandler handler) { this(executor, new DefaultWorker(handler), new IdleTimeoutResolver(convertToMillis(timeout, timeUnit))); }
private static void block(final Connection c, final FutureImpl<Boolean> future) { try { final long writeTimeout = c.getTransport().getWriteTimeout(MILLISECONDS); if (writeTimeout != -1) { future.get(writeTimeout, MILLISECONDS); } else { future.get(); } } catch (ExecutionException e) { c.closeWithReason(Exceptions.makeIOException(e.getCause())); } catch (Exception e) { c.closeWithReason(Exceptions.makeIOException(e)); } }
@Override public void ready() { try { flush(); } catch (IOException e) { final Connection c = feedableBodyGenerator.context.getConnection(); c.setMaxAsyncWriteQueueSize(feedableBodyGenerator.origMaxPendingBytes); c.closeWithReason(Exceptions.makeIOException(e)); } }
: future.get(); } catch (ExecutionException ee) { throw Exceptions.makeIOException(ee.getCause()); } catch (Exception e) { throw Exceptions.makeIOException(e); } finally { future.cancel(false);