示例#1
0
 public ContainerResponse call(ContainerRequest containerRequest) {
   ByteBuffer byteBuf = ByteBuffer.allocate(BUFFER_CAPACITY);
   ContainerResponse response;
   try {
     response = handler.apply(containerRequest, new ByteBufferOutputStream(byteBuf)).get();
   } catch (Exception e) {
     logger.debug("Failed while handling the request - " + containerRequest, e);
     response = new ContainerResponse(containerRequest, Response.serverError().build());
   }
   ContainerResponseWriter responseWriter = containerRequest.getResponseWriter();
   OutputStream os = responseWriter.writeResponseStatusAndHeaders(response.getLength(), response);
   response.setEntityStream(os);
   return response;
 }
  /**
   * Suspend the request/response processing.
   *
   * @param timeOut time-out value. Value less or equal to 0, indicates that the processing is
   *     suspended indefinitely.
   * @param unit time-out time unit.
   * @param handler time-out handler to process a time-out event if it occurs.
   * @return {@code true} if the suspend operation completed successfully, {@code false} otherwise.
   * @see ContainerResponseWriter#suspend(long, TimeUnit, ContainerResponseWriter.TimeoutHandler)
   */
  public boolean suspend(long timeOut, TimeUnit unit, final TimeoutHandler handler) {
    synchronized (runtimeLock) {
      if (suspended) {
        return false;
      }

      suspended = true;
      timeoutHandler = handler;

      containerResponseWriter.setSuspendTimeout(timeOut, unit);
      return true;
    }
  }