接口 AsyncContext
-
- 所有已知实现类:
AsyncContextImpl
public interface AsyncContextAsyncContext works like {@see javax.servlet.AsyncContext} in the Servlet 3.0. An AsyncContext is stated by a call toRpcContext.startAsync().The demo is {@see com.alibaba.dubbo.examples.async.AsyncConsumer} and {@see com.alibaba.dubbo.examples.async.AsyncProvider}
-
-
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 booleanisAsyncStarted()voidsignalContextSwitch()Signal RpcContext switch.voidstart()change the context state to startbooleanstop()change the context state to stopvoidwrite(Object value)write value and complete the async context.
-
-
-
方法详细资料
-
write
void write(Object value)
write value and complete the async context.- 参数:
value- invoke result
-
isAsyncStarted
boolean isAsyncStarted()
- 返回:
- true if the async context is started
-
stop
boolean stop()
change the context state to stop
-
start
void start()
change the context state to start
-
signalContextSwitch
void signalContextSwitch()
Signal RpcContext switch. Use this method to switch RpcContext from a Dubbo thread to a new thread created by the user. Note that you should use it in a new thread like this:public class AsyncServiceImpl implements AsyncService { public String sayHello(String name) { final AsyncContext asyncContext = RpcContext.startAsync(); new Thread(() -> { // right place to use this method asyncContext.signalContextSwitch(); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } asyncContext.write("Hello " + name + ", response from provider."); }).start(); return null; } }
-
-