javax.ws.rs.container.AsyncResponse.resume()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(280)

本文整理了Java中javax.ws.rs.container.AsyncResponse.resume()方法的一些代码示例,展示了AsyncResponse.resume()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AsyncResponse.resume()方法的具体详情如下:
包路径:javax.ws.rs.container.AsyncResponse
类名称:AsyncResponse
方法名:resume

AsyncResponse.resume介绍

[英]Resume the suspended request processing using the provided response data. The provided response data can be of any Java type that can be returned from a javax.ws.rs.HttpMethod.

The asynchronous response must be still in a #isSuspended() state for this method to succeed.

By executing this method, the request is guaranteed to complete either successfully or with an error. The data processing by the JAX-RS runtime follows the same path as it would for the response data returned synchronously by a JAX-RS resource, except that unmapped exceptions are not re-thrown by JAX-RS runtime to be handled by a hosting I/O container. Instead, any unmapped exceptions are propagated to the hosting I/O container via a container-specific callback mechanism. Depending on the container implementation, propagated unmapped exceptions typically result in an error status being sent to the client and/or the connection being closed.
[中]使用提供的响应数据恢复挂起的请求处理。提供的响应数据可以是可以从javax返回的任何Java类型。ws。rs.HttpMethod。
异步响应必须仍处于#isSuspended()状态,此方法才能成功。
通过执行此方法,可以保证请求成功完成或出现错误。JAX-RS运行时的数据处理遵循与JAX-RS资源同步返回的响应数据相同的路径,只是JAX-RS运行时不会重新抛出未映射的异常以由宿主I/O容器处理。相反,任何未映射的异常都会通过特定于容器的回调机制传播到宿主I/O容器。根据容器实现,传播的未映射异常通常会导致向客户端发送错误状态和/或关闭连接。

代码示例

代码示例来源:origin: jersey/jersey

@GET
  @ManagedAsync
  public void longGet(@Suspended final AsyncResponse ar, @QueryParam("id") int requestId) {
    try {
      Thread.sleep(SLEEP_TIME_IN_MILLIS);
    } catch (InterruptedException ex) {
      LOGGER.log(Level.SEVERE, "Response processing interrupted", ex);
    }
    ar.resume(requestId + " - " + NOTIFICATION_RESPONSE);
  }
}

代码示例来源:origin: prestodb/presto

@GET
@Path("{queryId}/{token}")
@Produces(MediaType.APPLICATION_JSON)
public void getQueryResults(
    @PathParam("queryId") QueryId queryId,
    @PathParam("token") long token,
    @QueryParam("maxWait") Duration maxWait,
    @QueryParam("targetResultSize") DataSize targetResultSize,
    @HeaderParam(X_FORWARDED_PROTO) String proto,
    @Context UriInfo uriInfo,
    @Suspended AsyncResponse asyncResponse)
{
  Query query = queries.get(queryId);
  if (query == null) {
    asyncResponse.resume(Response.status(Status.NOT_FOUND).build());
    return;
  }
  if (isNullOrEmpty(proto)) {
    proto = uriInfo.getRequestUri().getScheme();
  }
  asyncQueryResults(query, OptionalLong.of(token), maxWait, targetResultSize, uriInfo, proto, asyncResponse);
}

代码示例来源:origin: atomix/atomix

@DELETE
 @Path("/{name}/lock")
 public void unlock(@PathParam("name") String name, @Suspended AsyncResponse response) {
  getPrimitive(name).thenCompose(lock -> lock.unlock()).whenComplete((result, error) -> {
   if (error == null) {
    response.resume(Response.ok().build());
   } else {
    LOGGER.warn("{}", error);
    response.resume(Response.serverError().build());
   }
  });
 }
}

代码示例来源:origin: aol/micro-server

@GET
@Produces("application/json")
public void mainfest(@Suspended AsyncResponse asyncResponse, @Context ServletContext context) {
  
  ReactiveSeq.of("/META-INF/MANIFEST.MF")
        .map(url->context.getResourceAsStream(url))
        .map(this::getManifest)
      .foldFuture(WorkerThreads.ioExecutor.get(),
        s->s.forEach(Long.MAX_VALUE,result->asyncResponse.resume(result)));
        
  
}

代码示例来源:origin: atomix/atomix

@DELETE
 @Path("/{name}/lock")
 public void unlock(@PathParam("name") String name, @Suspended AsyncResponse response) {
  getPrimitive(name).thenCompose(lock -> lock.unlock()).whenComplete((result, error) -> {
   if (error == null) {
    response.resume(Response.ok().build());
   } else {
    LOGGER.warn("{}", error);
    response.resume(Response.serverError().build());
   }
  });
 }
}

代码示例来源:origin: graphhopper/graphhopper

@POST
@Timed
@ManagedAsync
public void changeGraph(JsonFeatureCollection collection, @Suspended AsyncResponse response) {
  response.resume(graphHopper.changeGraph(collection.getFeatures()));
}

代码示例来源:origin: atomix/atomix

@POST
@Path("{name}")
@Consumes(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
public void create(
  @PathParam("name") String name,
  C config,
  @Suspended AsyncResponse response) {
 primitives.getPrimitiveAsync(name, type, config).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok().build());
  } else {
   response.resume(error);
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{name}/lock")
@Produces(MediaType.APPLICATION_JSON)
public void lock(@PathParam("name") String name, @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(lock -> lock.lock()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok().build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@GET
@Path("/{name}/value")
@Produces(MediaType.APPLICATION_JSON)
public void get(@PathParam("name") String name, @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(value -> value.get()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{subject}/{node}")
@Consumes(MediaType.TEXT_PLAIN)
public void send(@PathParam("subject") String subject, @PathParam("node") String node, @Context ClusterCommunicationService communicationService, String body, @Suspended AsyncResponse response) {
 communicationService.unicast(subject, body, MemberId.from(node)).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok().build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{name}/clear")
public void clear(
  @PathParam("name") String name,
  @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(map -> map.clear()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.noContent().build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: apache/incubator-pinot

@POST
@ManagedAsync
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/segments")
@ApiOperation(value = "Upload a segment", notes = "Upload a segment as binary")
// For the multipart endpoint, we will always move segment to final location regardless of the segment endpoint.
public void uploadSegmentAsMultiPart(FormDataMultiPart multiPart,
  @ApiParam(value = "Whether to enable parallel push protection") @DefaultValue("false") @QueryParam(FileUploadDownloadClient.QueryParameters.ENABLE_PARALLEL_PUSH_PROTECTION) boolean enableParallelPushProtection,
  @Context HttpHeaders headers, @Context Request request, @Suspended final AsyncResponse asyncResponse) {
 try {
  asyncResponse.resume(uploadSegment(multiPart, enableParallelPushProtection, headers, request, true));
 } catch (Throwable t) {
  asyncResponse.resume(t);
 }
}

代码示例来源:origin: atomix/atomix

@POST
 @Path("/{name}/value")
 @Consumes(MediaType.TEXT_PLAIN)
 public void set(@PathParam("name") String name, String body, @Suspended AsyncResponse response) {
  getPrimitive(name).thenCompose(value -> value.set(body)).whenComplete((result, error) -> {
   if (error == null) {
    response.resume(Response.ok().build());
   } else {
    LOGGER.warn("{}", error);
    response.resume(Response.serverError().build());
   }
  });
 }
}

代码示例来源:origin: apache/incubator-pinot

@POST
@ManagedAsync
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/v2/segments")
@ApiOperation(value = "Upload a segment", notes = "Upload a segment as binary")
// This behavior does not differ from v1 of the same endpoint.
public void uploadSegmentAsMultiPartV2(FormDataMultiPart multiPart,
  @ApiParam(value = "Whether to enable parallel push protection") @DefaultValue("false") @QueryParam(FileUploadDownloadClient.QueryParameters.ENABLE_PARALLEL_PUSH_PROTECTION) boolean enableParallelPushProtection,
  @Context HttpHeaders headers, @Context Request request, @Suspended final AsyncResponse asyncResponse) {
 try {
  asyncResponse.resume(uploadSegment(multiPart, enableParallelPushProtection, headers, request, true));
 } catch (Throwable t) {
  asyncResponse.resume(t);
 }
}

代码示例来源:origin: atomix/atomix

@GET
@Path("/{name}/size")
@Produces(MediaType.APPLICATION_JSON)
public void size(
  @PathParam("name") String name,
  @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(map -> map.size()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{name}/element")
@Produces(MediaType.APPLICATION_JSON)
public void element(
  @PathParam("name") String name,
  @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(queue -> queue.element()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{name}/poll")
@Produces(MediaType.APPLICATION_JSON)
public void poll(
  @PathParam("name") String name,
  @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(queue -> queue.poll()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@POST
@Path("/{name}/lock")
@Produces(MediaType.APPLICATION_JSON)
public void lock(@PathParam("name") String name, @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(lock -> lock.lock()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result.value()).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

代码示例来源:origin: atomix/atomix

@DELETE
 @Path("/{name}")
 public void clear(
   @PathParam("name") String name,
   @Suspended AsyncResponse response) {
  getPrimitive(name).thenCompose(collection -> collection.clear()).whenComplete((result, error) -> {
   if (error == null) {
    response.resume(Response.ok().build());
   } else {
    log.warn("{}", error);
    response.resume(Response.serverError().build());
   }
  });
 }
}

代码示例来源:origin: atomix/atomix

@GET
@Path("/{name}")
@Produces(MediaType.APPLICATION_JSON)
public void get(
  @PathParam("name") String name,
  @Suspended AsyncResponse response) {
 getPrimitive(name).thenCompose(counter -> counter.get()).whenComplete((result, error) -> {
  if (error == null) {
   response.resume(Response.ok(result).build());
  } else {
   LOGGER.warn("{}", error);
   response.resume(Response.serverError().build());
  }
 });
}

相关文章