本文整理汇总了Java中org.glassfish.grizzly.http.server.Response.suspend方法的典型用法代码示例。如果您正苦于以下问题:Java Response.suspend方法的具体用法?Java Response.suspend怎么用?Java Response.suspend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.Response
的用法示例。
在下文中一共展示了Response.suspend方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: GrizzlyServerHttpExchange
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
this.request = request;
this.response = response;
request.getContext().getConnection().addCloseListener(new CloseListener<Closeable,
ICloseType>() {
@Override
public void onClosed(Closeable closeable, ICloseType type) throws
IOException {
closeActions.fire();
}
});
// To detect closed connection
// From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java
// /org/glassfish/grizzly/comet/CometContext.java#L250
request.getInputBuffer().initiateAsyncronousDataReceiving();
response.suspend();
}
示例2: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
try {
int port = request.getRemotePort();
String address = request.getRemoteAddr();
String holdConn = request.getParameter("hold");
if ("false".equals(holdConn)) {
logger.info("recv short request:[{}:{}]", address, port);
String messageJson = request.getParameter("data");
IMessage msg = context.getCodec().decode(messageJson);
context.getMessageCenter().send(msg);
} else {
logger.info("recv long-poll request:[{}:{}]", address, port);
PushError erro = context.beAddSub(request.getParameterMap());
if (erro != null) {
writeInfo(response, erro);
return;
}
long timeout = context.getConfig().getConnTimeout();
IRemoteSubcriber sub = new PollSubcriber(response, context);
response.suspend(timeout, TimeUnit.MILLISECONDS, handler, this);
context.getMessageCenter().addSubscriber(sub);
request.setAttribute("sub", sub);
logger.info("create long-poll client:[{}:{}]", address, port);
}
} catch (Exception e) {
logger.error("occur error when process request", e);
}
}
示例3: GrizzlyServerHttpExchange
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public GrizzlyServerHttpExchange(Request request, Response response) {
this.request = request;
this.response = response;
request.getContext().getConnection().addCloseListener(new CloseListener<Closeable, org.glassfish.grizzly.ICloseType>() {
@Override
public void onClosed(Closeable closeable, org.glassfish.grizzly.ICloseType type) throws IOException {
closeActions.fire();
}
});
// To detect closed connection
// From https://github.com/GrizzlyNIO/grizzly-mirror/blob/2_3_17/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java#L250
request.getInputBuffer().initiateAsyncronousDataReceiving();
response.suspend();
}
示例4: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
public void service(final Request req, final Response resp) throws Exception {
// suspend the response, allowing for async processing
resp.suspend();
LogManager.getLogger(this).info(String.format("Request: %s, IP %s", req.getRequestURI(), req.getRemoteAddr()));
int length = req.getContentLength();
if (length > Server.MAX_POST_SIZE || length < Server.MIN_POST_SIZE){
m_errorHandler.handleInvalidPost(null, resp, new IllegalArgumentException("Invalid content-length of " + length));
return; // FIXME- this probably wants to be handled using an error-handling mechanism.
}
final ByteBuffer postBytes = ByteBuffer.allocate(req.getContentLength());
final NIOInputStream in = req.getNIOInputStream();
in.notifyAvailable(new ReadHandler() {
public void onError(Throwable t) {
try {
m_errorHandler.handleInvalidPost(postBytes, resp, t);
} catch (IOException e) {
e.printStackTrace(); // FIXME
}
resp.resume();
}
public void onDataAvailable() throws Exception {
addToBuffer(in, postBytes);
in.notifyAvailable(this);
}
public void onAllDataRead() throws Exception {
addToBuffer(in, postBytes);
postBytes.flip();
m_successHandler.handlePost(postBytes, req, resp);
}
});
}
示例5: service
import org.glassfish.grizzly.http.server.Response; //导入方法依赖的package包/类
@Override
@Suspendable
public void service(final Request request, final Response response) throws CharConversionException {
final ResponseWriter responseWriter = new ResponseWriter(response, configSetStatusOverSendError);
try {
logger.debugLog("GrizzlyHttpContainer.service(...) started");
final URI baseUri = getBaseUri(request);
final URI requestUri = getRequestUri(request);
final ContainerRequest requestContext = new ameba.container.server.Request(baseUri,
requestUri, request.getMethod().getMethodString(),
getSecurityContext(request), new GrizzlyRequestPropertiesDelegate(request)) {
@Override
public String getRemoteAddr() {
return request.getRemoteAddr();
}
@Override
public String getRemoteHost() {
return request.getRemoteHost();
}
@Override
public int getRemotePort() {
return request.getRemotePort();
}
@Override
public String getLocalAddr() {
return request.getLocalAddr();
}
@Override
public String getLocalName() {
return request.getLocalName();
}
@Override
public int getLocalPort() {
return request.getLocalPort();
}
@Override
public URI getRawReqeustUri() {
return UriBuilder.fromUri(requestUri).build();
}
};
requestContext.setEntityStream(request.getInputStream());
for (final String headerName : request.getHeaderNames()) {
requestContext.headers(headerName, request.getHeaders(headerName));
}
requestContext.setWriter(responseWriter);
response.suspend();
HttpFiber.start(() -> {
requestContext.setRequestScopedInitializer(injectionManager -> {
injectionManager.<Ref<Request>>getInstance(RequestType).set(request);
injectionManager.<Ref<Response>>getInstance(ResponseType).set(response);
});
appHandler.handle(requestContext);
});
} finally {
logger.debugLog("GrizzlyHttpContainer.service(...) finished");
}
}