/** * <p>Returns the {@link Container} for which this Request was created.</p> * * @return The container instance. */ public Container container() { return parent != null ? parent.container() : container; }
/** * <p>Returns the time that this Request has existed so far. * * @param unit The unit to return the time in. * @return The number of time units elapsed since this Request was created. */ public long timeElapsed(TimeUnit unit) { return unit.convert(container().currentTimeMillis() - creationTime, TimeUnit.MILLISECONDS); }
/** * <p>Returns the time that this Request is allowed to exist. If no timeout has been set, this method will return * <em>null</em>.</p> * * @param unit The unit to return the time in. * @return The number of time units left until this Request times out, or <em>null</em>. */ public Long timeRemaining(TimeUnit unit) { if (timeout == null) { return null; } return unit.convert(timeout - (container().currentTimeMillis() - creationTime), TimeUnit.MILLISECONDS); }
this.parentReference = this.parent.refer(); container = null; creationTime = parent.container().currentTimeMillis(); serverRequest = false; setUri(uri);
/** * <p>Attempts to resolve and connect to the {@link RequestHandler} appropriate for the {@link URI} of this Request. * An exception is thrown if this operation fails at any point. This method is exception-safe.</p> * * @param responseHandler The handler to pass the corresponding {@link Response} to. * @return The {@link ContentChannel} to write the Request content to. * @throws NullPointerException If the {@link ResponseHandler} is null. * @throws BindingNotFoundException If the corresponding call to {@link Container#resolveHandler(Request)} returns * null. */ public ContentChannel connect(ResponseHandler responseHandler) { try { Objects.requireNonNull(responseHandler, "responseHandler"); RequestHandler requestHandler = container().resolveHandler(this); if (requestHandler == null) { throw new BindingNotFoundException(uri); } requestHandler = new ProxyRequestHandler(requestHandler); ContentChannel content = requestHandler.handleRequest(this, responseHandler); if (content == null) { throw new RequestDeniedException(this); } return content; } catch (Throwable t) { cancel(); throw t; } }
ResponseFilter responseFilter = responseFilters.resolve(request.getUri()); RequestHandler resolvedRequestHandler = request.container().resolveHandler(request);