本文整理汇总了Java中javax.servlet.AsyncEvent.getAsyncContext方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncEvent.getAsyncContext方法的具体用法?Java AsyncEvent.getAsyncContext怎么用?Java AsyncEvent.getAsyncContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.AsyncEvent
的用法示例。
在下文中一共展示了AsyncEvent.getAsyncContext方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTimeout
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
/**
* Async operation timeout (AsyncListener interface)
*
* @param event Async event
*/
@Override
public void onTimeout(AsyncEvent event) {
AsyncContext context = event.getAsyncContext();
lock.lock();
try {
pendingWaits.remove(context);
JSONObject response = new JSONObject();
response.put("events", new JSONArray());
response.put("requestProcessingTime", System.currentTimeMillis()-timestamp);
try (Writer writer = context.getResponse().getWriter()) {
response.writeJSONString(writer);
} catch (IOException exc) {
Logger.logDebugMessage(String.format("Unable to return API response to %s: %s",
address, exc.toString()));
}
context.complete();
timestamp = System.currentTimeMillis();
} finally {
lock.unlock();
}
}
示例2: customizeEvent
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
private AsyncEvent customizeEvent(AsyncEvent event) {
if (servletRequest != null && servletResponse != null) {
return new AsyncEvent(event.getAsyncContext(), servletRequest, servletResponse,
event.getThrowable());
} else {
return event;
}
}
示例3: onComplete
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
@Override
public void onComplete(AsyncEvent event) throws IOException {
final AsyncContextState state = (AsyncContextState) event.getAsyncContext();
final HttpServletRequest request = (HttpServletRequest) state.getRequest();
final HttpServletResponse response = (HttpServletResponse) state.getResponse();
updateResponses(request, response, startTime);
}
示例4: customizeEvent
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
private AsyncEvent customizeEvent(AsyncEvent event) {
if (servletRequest != null && servletResponse != null) {
return new AsyncEvent(event.getAsyncContext(), servletRequest, servletResponse, event.getThrowable());
} else {
return event;
}
}
示例5: onStartAsync
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
// Another async event was started (e.g. via asyncContext.dispatch(...), which means this listener was
// removed and won't be called on completion unless we re-register (as per the javadocs for this
// method from the interface).
AsyncContext eventAsyncContext = event.getAsyncContext();
if (eventAsyncContext != null) {
eventAsyncContext.addListener(this);
}
}
示例6: onError
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
/**
* Async error detected (AsyncListener interface)
*
* @param event Async event
*/
@Override
public void onError(AsyncEvent event) {
AsyncContext context = event.getAsyncContext();
lock.lock();
try {
pendingWaits.remove(context);
context.complete();
timestamp = System.currentTimeMillis();
Logger.logDebugMessage("Error detected during event wait for "+address, event.getThrowable());
} finally {
lock.unlock();
}
}
示例7: finalizeAsyncContext
import javax.servlet.AsyncEvent; //导入方法依赖的package包/类
private void finalizeAsyncContext(AsyncEvent event, Reason reason) throws IOException {
AsyncContext asyncContext = event.getAsyncContext();
bean.asyncContextDestroyed(asyncContext, reason);
HANDLER.finalizeAsyncBean(bean, (HttpServletRequest) asyncContext.getRequest());
}