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