当前位置: 首页>>代码示例>>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;未经允许,请勿转载。