本文整理匯總了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());
}