本文整理汇总了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);
}
}
示例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;
}