當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncListener類代碼示例

本文整理匯總了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);
}
 
開發者ID:Nike-Inc,項目名稱:wingtips,代碼行數:23,代碼來源:ServletRuntimeTest.java

示例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();
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:20,代碼來源:OpenEJBAsyncContext.java

示例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);
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:25,代碼來源:OpenEJBAsyncContext.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:17,代碼來源:OpenEJBAsyncContext.java

示例5: addListener

import javax.servlet.AsyncListener; //導入依賴的package包/類
@Override
public void addListener(AsyncListener listener) {
    check();
    AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
    wrapper.setListener(listener);
    listeners.add(wrapper);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:8,代碼來源:AsyncContextImpl.java

示例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);
        }
    }
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:11,代碼來源:AsyncContextImpl.java

示例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();
        }
    }
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:16,代碼來源:NettyAsyncContext1.java

示例8: addListener

import javax.servlet.AsyncListener; //導入依賴的package包/類
@Override
public void addListener(AsyncListener listener) {
	check();
	AsyncListenerWrapper wrapper = new AsyncListenerWrapper();
	wrapper.setListener(listener);
	listeners.add(wrapper);
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:8,代碼來源:AsyncContextImpl.java

示例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);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:16,代碼來源:MockAsyncContext.java

示例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);
    }
}
 
開發者ID:Nike-Inc,項目名稱:wingtips,代碼行數:31,代碼來源:ServletRuntimeTest.java

示例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));
}
 
開發者ID:Nike-Inc,項目名稱:wingtips,代碼行數:13,代碼來源:RequestTracingFilterTest.java

示例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);
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:15,代碼來源:MockAsyncContext.java

示例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);
}
 
開發者ID:apache,項目名稱:portals-pluto,代碼行數:8,代碼來源:PortletAsyncContextImpl.java

示例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;
}
 
開發者ID:apache,項目名稱:portals-pluto,代碼行數:12,代碼來源:PortletAsyncContextImpl.java

示例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
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:16,代碼來源:OpenEJBAsyncContext.java


注:本文中的javax.servlet.AsyncListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。