本文整理汇总了Java中javax.servlet.AsyncListener类的典型用法代码示例。如果您正苦于以下问题:Java AsyncListener类的具体用法?Java AsyncListener怎么用?Java AsyncListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncListener类属于javax.servlet包,在下文中一共展示了AsyncListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupTracingCompletionWhenAsyncRequestCompletes_should_add_WingtipsRequestSpanCompletionAsyncListener
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Test
public void setupTracingCompletionWhenAsyncRequestCompletes_should_add_WingtipsRequestSpanCompletionAsyncListener(
) throws ServletException, IOException {
// given
AsyncContext asyncContextMock = mock(AsyncContext.class);
doReturn(asyncContextMock).when(requestMock).getAsyncContext();
TracingState tracingStateMock = mock(TracingState.class);
ArgumentCaptor<AsyncListener> listenerCaptor = ArgumentCaptor.forClass(AsyncListener.class);
// when
servlet3Runtime.setupTracingCompletionWhenAsyncRequestCompletes(requestMock, tracingStateMock);
// then
verify(asyncContextMock).addListener(listenerCaptor.capture());
List<AsyncListener> addedListeners = listenerCaptor.getAllValues();
assertThat(addedListeners).hasSize(1);
assertThat(addedListeners.get(0)).isInstanceOf(WingtipsRequestSpanCompletionAsyncListener.class);
WingtipsRequestSpanCompletionAsyncListener listener =
(WingtipsRequestSpanCompletionAsyncListener)addedListeners.get(0);
assertThat(listener.originalRequestTracingState).isSameAs(tracingStateMock);
}
示例2: destroy
import javax.servlet.AsyncListener; //导入依赖的package包/类
public static void destroy() {
if (es == null) {
return;
}
es.shutdownNow();
for (final OpenEJBAsyncContext ctx : new ArrayList<>(INITIALIZED)) {
if (ctx.lastTouch + ctx.getTimeout() < System.currentTimeMillis()) {
for (final AsyncListener listener : ctx.listeners) {
try {
listener.onTimeout(ctx.event);
} catch (final IOException t) {
throw new OpenEJBRuntimeException(t);
}
}
ctx.complete();
}
}
INITIALIZED.clear();
}
示例3: init
import javax.servlet.AsyncListener; //导入依赖的package包/类
public static void init() {
if (!"true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.http.async.eviction", "true"))) {
return;
}
es = Executors.newScheduledThreadPool(1, new DaemonThreadFactory(OpenEJBAsyncContext.class));
es.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
for (final OpenEJBAsyncContext ctx : new ArrayList<>(INITIALIZED)) {
if (ctx.lastTouch + ctx.getTimeout() < System.currentTimeMillis()) {
INITIALIZED.remove(ctx);
for (final AsyncListener listener : ctx.listeners) {
try {
listener.onTimeout(ctx.event);
} catch (final IOException t) {
throw new OpenEJBRuntimeException(t);
}
}
ctx.complete();
}
}
}
}, 1, 1, TimeUnit.MINUTES);
}
示例4: complete
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void complete() {
for (final AsyncListener listener : listeners) {
try {
listener.onComplete(event);
} catch (final IOException t) {
throw new OpenEJBRuntimeException(t);
}
}
try {
commit();
} finally {
INITIALIZED.remove(this);
}
}
示例5: addListener
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void addListener(AsyncListener listener) {
check();
AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
wrapper.setListener(listener);
listeners.add(wrapper);
}
示例6: complete
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void complete() {
for (AsyncListener listener : this.listeners) {
try {
listener.onComplete(new AsyncEvent(this, this.request, this.response));
} catch (IOException e) {
throw new IllegalStateException("AsyncListener failure", e);
}
}
}
示例7: complete
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void complete() {
try {
servletResponse.flushBuffer();
} catch (IOException e1) {
e1.printStackTrace();
}
for (AsyncListener asyncListener : getAsyncListeners()) {
try {
asyncListener.onComplete(new AsyncEvent(this));
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例8: addListener
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void addListener(AsyncListener listener) {
check();
AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
wrapper.setListener(listener);
listeners.add(wrapper);
}
示例9: complete
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void complete() {
MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class);
if (mockRequest != null) {
mockRequest.setAsyncStarted(false);
}
for (AsyncListener listener : this.listeners) {
try {
listener.onComplete(new AsyncEvent(this, this.request, this.response));
}
catch (IOException e) {
throw new IllegalStateException("AsyncListener failure", e);
}
}
}
示例10: determineServletRuntime_returns_ServletRuntime_based_on_arguments
import javax.servlet.AsyncListener; //导入依赖的package包/类
@DataProvider(value = {
"true | true | true",
"true | false | false",
"false | true | false",
"false | false | false"
}, splitBy = "\\|")
@Test
public void determineServletRuntime_returns_ServletRuntime_based_on_arguments(
boolean classHasServlet3Method, boolean useAsyncListenerClassThatExists, boolean expectServlet3Runtime
) {
// given
Class<?> servletRequestClass = (classHasServlet3Method)
? GoodFakeServletRequest.class
: BadFakeServletRequest.class;
String asyncListenerClassname = (useAsyncListenerClassThatExists)
? AsyncListener.class.getName()
: "does.not.exist.AsyncListener" + UUID.randomUUID().toString();
// when
ServletRuntime result = ServletRuntime.determineServletRuntime(servletRequestClass, asyncListenerClassname);
// then
if (expectServlet3Runtime) {
assertThat(result).isInstanceOf(Servlet3Runtime.class);
}
else {
assertThat(result).isInstanceOf(Servlet2Runtime.class);
}
}
示例11: setupAsyncContextWorkflow
import javax.servlet.AsyncListener; //导入依赖的package包/类
private void setupAsyncContextWorkflow() {
listenerCapturingAsyncContext = mock(AsyncContext.class);
capturedAsyncListeners = new ArrayList<>();
doReturn(listenerCapturingAsyncContext).when(requestMock).getAsyncContext();
doReturn(true).when(requestMock).isAsyncStarted();
doAnswer(invocation -> {
capturedAsyncListeners.add((AsyncListener) invocation.getArguments()[0]);
return null;
}).when(listenerCapturingAsyncContext).addListener(any(AsyncListener.class));
}
示例12: complete
import javax.servlet.AsyncListener; //导入依赖的package包/类
public void complete() {
Servlet3MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, Servlet3MockHttpServletRequest.class);
if (mockRequest != null) {
mockRequest.setAsyncStarted(false);
}
for (AsyncListener listener : this.listeners) {
try {
listener.onComplete(new AsyncEvent(this, this.request, this.response));
}
catch (IOException e) {
throw new IllegalStateException("AsyncListener failure", e);
}
}
}
示例13: addListener
import javax.servlet.AsyncListener; //导入依赖的package包/类
@Override
public void addListener(AsyncListener l) {
if (!isContextActive) {
throw new IllegalStateException("Listener can only be added when the asynchronous context is active.");
}
pal.addListener(l);
}
示例14: createListener
import javax.servlet.AsyncListener; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends AsyncListener> T createListener(Class<T> cls) throws ServletException {
T obj = null;
try {
obj = (T) createInstance(cls);
} catch (Throwable t) {
throw new ServletException(t);
}
return obj;
}
示例15: onError
import javax.servlet.AsyncListener; //导入依赖的package包/类
private void onError(final Throwable ignored) {
for (final AsyncListener listener : listeners) {
try {
listener.onError(event);
} catch (final IOException t) {
throw new OpenEJBRuntimeException(t);
}
}
try {
HttpServletResponse.class.cast(response).sendError(HttpURLConnection.HTTP_INTERNAL_ERROR);
commit();
} catch (final IOException e) {
// no-op
}
}