本文整理汇总了Java中org.atmosphere.cpr.AtmosphereResource.suspend方法的典型用法代码示例。如果您正苦于以下问题:Java AtmosphereResource.suspend方法的具体用法?Java AtmosphereResource.suspend怎么用?Java AtmosphereResource.suspend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.atmosphere.cpr.AtmosphereResource
的用法示例。
在下文中一共展示了AtmosphereResource.suspend方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequest
import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
@Override
public void onRequest(AtmosphereResource resource) throws IOException {
// if (LOG.isTraceEnabled()) {
// LOG.trace(String.format("onRequest() starts... for resource %s.", resource.uuid()));
// }
AtmosphereRequest request = resource.getRequest();
String method = request.getMethod();
if ("get".equalsIgnoreCase(method)) {
// if (LOG.isTraceEnabled()) {
// LOG.trace("Suspending request after GET call.");
// }
UserSession session = null;//sessionsPool.getSessionBySessionId(resource.uuid());
if (session == null) {
session = sessionsPool.createSession(resource);
resource.suspend();
resource.getResponse().setContentType("application/json");
getMessageHandler().handleMessage(new MessageContext(sessionsPool, session, null, resource.getRequest().getLocale()));
}
} else if ("post".equalsIgnoreCase(method)) {
// if (LOG.isTraceEnabled()) {
// LOG.trace("Processing POST message.");
// }
HubMessage msg = parseMessage(request);
if (msg == null) {
return;
}
getMessageHandler().handleMessage(new MessageContext(
sessionsPool, sessionsPool.getSessionBySessionId(resource.uuid()), msg, resource.getRequest().getLocale()));
}
}
示例2: suspend
import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
/**
* Suspends the given resource
*
* @param resource the resource to suspend
* @since 7.6
*/
protected void suspend(AtmosphereResource resource) {
if (resource.transport() == TRANSPORT.LONG_POLLING) {
resource.suspend(getLongPollingSuspendTimeout());
} else {
resource.suspend(-1);
}
}
示例3: handleMessagesApi
import org.atmosphere.cpr.AtmosphereResource; //导入方法依赖的package包/类
/**
* handleMessagesApi handles all requests sent to /api/messages It
* suspends/upgrades the connection to a websocket It is a asynchronous
* protocol - and all messages are wrapped in a message wrapper.
*
* The ApiFactory will handle the details of de-serializing but its necessary
* to setup some protocol details here for websockets and session management
* which the ApiFactory should not be concerned with.
*
* @param r - request and response objects from Atmosphere server
*/
public void handleMessagesApi(AtmosphereResource r) {
try {
AtmosphereResponse response = r.getResponse();
AtmosphereRequest request = r.getRequest();
OutputStream out = response.getOutputStream();
if (!r.isSuspended()) {
r.suspend();
}
response.addHeader("Content-Type", CodecUtils.MIME_TYPE_JSON);
api.process(this, out, r.getRequest().getRequestURI(), request.body().asString());
/*
* // FIXME - GET or POST should work - so this "should" be unnecessary ..
* if ("GET".equals(httpMethod)) { // if post and parts.length < 3 ?? //
* respond(r, apiKey, "getPlatform", new Hello(Runtime.getId()));
* HashMap<URI, ServiceEnvironment> env = Runtime.getEnvironments();
* respond(r, apiKey, "getLocalServices", env); } else {
* doNotUseThisProcessMessageAPI(codec, request.body()); // FIXME data is
* double encoded .. can't put '1st' encoded json // api.process(this,
* out, r.getRequest().getRequestURI(), request.body().asString()); }
*/
} catch (Exception e) {
log.error("handleMessagesApi -", e);
}
}