当前位置: 首页>>代码示例>>Java>>正文


Java ManagedAsync类代码示例

本文整理汇总了Java中org.glassfish.jersey.server.ManagedAsync的典型用法代码示例。如果您正苦于以下问题:Java ManagedAsync类的具体用法?Java ManagedAsync怎么用?Java ManagedAsync使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ManagedAsync类属于org.glassfish.jersey.server包,在下文中一共展示了ManagedAsync类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStatus

import org.glassfish.jersey.server.ManagedAsync; //导入依赖的package包/类
@GET
@Path("/{name}/status")
@ManagedAsync
public void getStatus(
    @PathParam("name") final String name,
    @Suspended final AsyncResponse response) {

    Optional<CassandraDaemonTask> taskOption =
        Optional.ofNullable(state.getDaemons().get(name));
    if (!taskOption.isPresent()) {
        response.resume(
            Response.status(Response.Status.NOT_FOUND).build());
    } else {
        CassandraDaemonTask task = taskOption.get();
        client.status(task.getHostname(), task.getExecutor().getApiPort()
        ).whenCompleteAsync((status, error) -> {
            if (status != null) {
                response.resume(status);
            } else {
                response.resume(Response.serverError());
            }
        });
    }
}
 
开发者ID:mesosphere,项目名称:dcos-cassandra-service,代码行数:25,代码来源:TasksResource.java

示例2: getBook

import org.glassfish.jersey.server.ManagedAsync; //导入依赖的package包/类
@RolesAllowed({"user", "admin"})
@Path("/{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ManagedAsync
public void getBook(@PathParam("id") String id, @Suspended final AsyncResponse asyncResponse) {
    // asyncResponse.resume( dao.getBookAsync(id) );
    ListenableFuture<Book> bookFutures = dao.getBookAsync(id);
    Futures.addCallback(bookFutures, new FutureCallback<Book>() {
        @Override
        public void onSuccess(Book result) {
            EntityTag entityTag = generateEntityTag(result);
            Response.ResponseBuilder rb = request.evaluatePreconditions(entityTag);
            if (rb != null) {
                asyncResponse.resume(rb.build());
            } else {
                asyncResponse.resume(Response.ok().tag(entityTag).entity(result).build());
            }
        }

        @Override
        public void onFailure(Throwable t) {
            // we cound throw Jersey's WebApplicationException.
            asyncResponse.resume(t);
        }
    });
}
 
开发者ID:psenger,项目名称:Jersey2-Security-JWT,代码行数:28,代码来源:BookResource.java

示例3: sayAsyncHello

import org.glassfish.jersey.server.ManagedAsync; //导入依赖的package包/类
@GET
@ManagedAsync
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public void sayAsyncHello(@Suspended final AsyncResponse response) {
  (new Thread() {
    @Override
    public void run() {
      response.resume(String.format(RESPONSE, value));
    }
  }).start();
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:13,代码来源:MyAsyncResource.java

示例4: getLives

import org.glassfish.jersey.server.ManagedAsync; //导入依赖的package包/类
@GET
@ManagedAsync
@Produces(MediaType.APPLICATION_JSON)
public void getLives(@Suspended final AsyncResponse asyncResponse,
                     @DefaultValue("0") @QueryParam("newestid") final int newestId,
                     @QueryParam("oldestid") final Integer oldestId) {

    asyncResponse.setTimeoutHandler(asyncResponse1 -> {
        logger.info("reached timeout");
        asyncResponse1.resume(Response.ok().build());
    });

    asyncResponse.setTimeout(5, TimeUnit.MINUTES);

    try {
        List<Life> lives = oldestId == null ?
                           Lifes.getLastLives(newestId) : Lifes.getOlderLives(oldestId);

        if (lives.size() > 0) {
            final GenericEntity<List<Life>> entity = new GenericEntity<List<Life>>(lives) {
            };
            asyncResponse.resume(entity);
        } else {
            LifeProvider.suspend(asyncResponse);
        }

    } catch (SQLException e) {
        logger.error(e, e);
        asyncResponse
                .resume(new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR));
    }

}
 
开发者ID:anycook,项目名称:anycook-api,代码行数:34,代码来源:LifeApi.java

示例5: ping

import org.glassfish.jersey.server.ManagedAsync; //导入依赖的package包/类
@GET
@ManagedAsync
public void ping(@Suspended final AsyncResponse response) {
	response.resume(Response.status(Response.Status.OK).entity("pong").build());
}
 
开发者ID:kafka101,项目名称:clickstream-rest-proxy,代码行数:6,代码来源:PingService.java


注:本文中的org.glassfish.jersey.server.ManagedAsync类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。