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


Java AtmosphereResourceImpl类代码示例

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


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

示例1: sendNotificationAndDisconnect

import org.atmosphere.cpr.AtmosphereResourceImpl; //导入依赖的package包/类
/**
 * Tries to send a critical notification to the client and close the
 * connection. Does nothing if the connection is already closed.
 */
private static void sendNotificationAndDisconnect(
    AtmosphereResource resource, String notificationJson) {
    // TODO Implemented differently from sendRefreshAndDisconnect
    try {
        if (resource instanceof AtmosphereResourceImpl
            && !((AtmosphereResourceImpl) resource).isInScope()) {
            // The resource is no longer valid so we should not write
            // anything to it
            getLogger()
                .fine("sendNotificationAndDisconnect called for resource no longer in scope");
            return;
        }
        resource.getResponse().getWriter().write(notificationJson);
        resource.resume();
    } catch (Exception e) {
        getLogger().log(Level.FINEST,
            "Failed to send critical notification to client", e);
    }
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:24,代码来源:VertxPushHandler.java

示例2: route

import org.atmosphere.cpr.AtmosphereResourceImpl; //导入依赖的package包/类
public AtmosphereCoordinator route(AtmosphereRequest request, AtmosphereResponse response) throws IOException {
    final VertxAsyncIOWriter w = VertxAsyncIOWriter.class.cast(response.getAsyncIOWriter());
    try {

        Action a = framework.doCometSupport(request, response);
        final AtmosphereResourceImpl impl = (AtmosphereResourceImpl) request.getAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE);

        String transport = (String) request.getAttribute(FrameworkConfig.TRANSPORT_IN_USE);
        if (transport == null) {
            transport = request.getHeader(X_ATMOSPHERE_TRANSPORT);
        }

        logger.debug("Transport {} action {}", transport, a);
        final Action action = (Action) request.getAttribute(NettyCometSupport.SUSPEND);
        if (action != null && action.type() == Action.TYPE.SUSPEND && action.timeout() != -1) {
            final AtomicReference<Future<?>> f = new AtomicReference();
            f.set(suspendTimer.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    if (!w.isClosed() && (System.currentTimeMillis() - w.lastTick()) > action.timeout()) {
                        asynchronousProcessor.endRequest(impl, false);
                        f.get().cancel(true);
                    }
                }
            }, action.timeout(), action.timeout(), TimeUnit.MILLISECONDS));
        }
    } catch (Throwable e) {
        logger.error("Unable to process request", e);
    }
    return this;
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:32,代码来源:AtmosphereCoordinator.java


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