类 RpcContext
- java.lang.Object
-
- org.apache.dubbo.rpc.RpcContext
-
public class RpcContext extends Object
Thread local context. (API, ThreadLocal, ThreadSafe)Note: RpcContext is a temporary state holder. States in RpcContext changes every time when request is sent or received. For example: A invokes B, then B invokes C. On service B, RpcContext saves invocation info from A to B before B starts invoking C, and saves invocation info from B to C after B invokes C.
- 另请参阅:
ContextFilter
-
-
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 voidasyncCall(Runnable runnable)one way async call, send request only, and result is not required<T> CompletableFuture<T>asyncCall(Callable<T> callable)Async invocation.booleancanRemove()voidclearAfterEachInvoke(boolean remove)voidclearAttachments()Map<String,Object>get()get values.Objectget(String key)get value.Object[]getArguments()get arguments.AsyncContextgetAsyncContext()StringgetAttachment(String key)also seegetObjectAttachment(String).Map<String,String>getAttachments()已过时。<T> CompletableFuture<T>getCompletableFuture()get CompletableFuture.URLgetConsumerUrl()static RpcContextgetContext()get context.<T> Future<T>getFuture()get future.StringgetGroup()StringgetInterfaceName()InvocationgetInvocation()已过时。Replace to getMethodName(), getParameterTypes(), getArguments()Invoker<?>getInvoker()已过时。Replace to getUrl()List<Invoker<?>>getInvokers()已过时。Replace to getUrls()InetSocketAddressgetLocalAddress()get local address.StringgetLocalAddressString()StringgetLocalHost()get local host.StringgetLocalHostName()get local host name.intgetLocalPort()get local port.StringgetMethodName()get method name.ObjectgetObjectAttachment(String key)get attachment.Map<String,Object>getObjectAttachments()get attachments.Class<?>[]getParameterTypes()get parameter types.StringgetProtocol()StringgetProtocolServiceKey()InetSocketAddressgetRemoteAddress()get remote address.StringgetRemoteAddressString()get remote address string.StringgetRemoteApplicationName()StringgetRemoteHost()get remote host.StringgetRemoteHostName()get remote host name.intgetRemotePort()get remote port.ObjectgetRequest()Get the request object of the underlying RPC protocol, e.g.<T> TgetRequest(Class<T> clazz)Get the request object of the underlying RPC protocol, e.g.ObjectgetResponse()Get the response object of the underlying RPC protocol, e.g.<T> TgetResponse(Class<T> clazz)Get the response object of the underlying RPC protocol, e.g.static RpcContextgetServerContext()get server side context.StringgetServiceKey()URLgetUrl()List<URL>getUrls()StringgetVersion()booleanisAsyncStarted()booleanisClientSide()已过时。Replace to isConsumerSide()booleanisConsumerSide()is consumer side.booleanisProviderSide()is provider side.booleanisServerSide()已过时。Replace to isProviderSide()RpcContextremove(String key)remove value.RpcContextremoveAttachment(String key)remove attachment.static voidremoveContext()remove context.static voidremoveContext(boolean checkCanRemove)customized for internal use.static voidremoveServerContext()remove server side context.static voidrestoreContext(RpcContext oldContext)static voidrestoreServerContext(RpcContext oldServerContext)RpcContextset(String key, Object value)set value.voidsetArguments(Object[] arguments)RpcContextsetAttachment(String key, Object value)RpcContextsetAttachment(String key, String value)set attachment.RpcContextsetAttachments(Map<String,String> attachment)set attachmentsvoidsetConsumerUrl(URL consumerUrl)voidsetFuture(CompletableFuture<?> future)set future.RpcContextsetInvocation(Invocation invocation)RpcContextsetInvoker(Invoker<?> invoker)RpcContextsetInvokers(List<Invoker<?>> invokers)RpcContextsetLocalAddress(String host, int port)set local address.RpcContextsetLocalAddress(InetSocketAddress address)set local address.voidsetMethodName(String methodName)RpcContextsetObjectAttachment(String key, Object value)RpcContextsetObjectAttachments(Map<String,Object> attachment)set attachmentsvoidsetParameterTypes(Class<?>[] parameterTypes)RpcContextsetRemoteAddress(String host, int port)set remote address.RpcContextsetRemoteAddress(InetSocketAddress address)set remote address.RpcContextsetRemoteApplicationName(String remoteApplicationName)voidsetRequest(Object request)voidsetResponse(Object response)static voidsetRpcContext(URL url)voidsetUrl(URL url)voidsetUrls(List<URL> urls)static AsyncContextstartAsync()booleanstopAsync()
-
-
-
方法详细资料
-
getServerContext
public static RpcContext getServerContext()
get server side context.- 返回:
- server context
-
restoreServerContext
public static void restoreServerContext(RpcContext oldServerContext)
-
removeServerContext
public static void removeServerContext()
remove server side context.- 另请参阅:
ContextFilter
-
getContext
public static RpcContext getContext()
get context.- 返回:
- context
-
canRemove
public boolean canRemove()
-
clearAfterEachInvoke
public void clearAfterEachInvoke(boolean remove)
-
restoreContext
public static void restoreContext(RpcContext oldContext)
-
removeContext
public static void removeContext()
remove context.- 另请参阅:
ContextFilter
-
removeContext
public static void removeContext(boolean checkCanRemove)
customized for internal use.- 参数:
checkCanRemove- if need check before remove
-
getRequest
public Object getRequest()
Get the request object of the underlying RPC protocol, e.g. HttpServletRequest- 返回:
- null if the underlying protocol doesn't provide support for getting request
-
setRequest
public void setRequest(Object request)
-
getRequest
public <T> T getRequest(Class<T> clazz)
Get the request object of the underlying RPC protocol, e.g. HttpServletRequest- 返回:
- null if the underlying protocol doesn't provide support for getting request or the request is not of the specified type
-
getResponse
public Object getResponse()
Get the response object of the underlying RPC protocol, e.g. HttpServletResponse- 返回:
- null if the underlying protocol doesn't provide support for getting response
-
setResponse
public void setResponse(Object response)
-
getResponse
public <T> T getResponse(Class<T> clazz)
Get the response object of the underlying RPC protocol, e.g. HttpServletResponse- 返回:
- null if the underlying protocol doesn't provide support for getting response or the response is not of the specified type
-
isProviderSide
public boolean isProviderSide()
is provider side.- 返回:
- provider side.
-
isConsumerSide
public boolean isConsumerSide()
is consumer side.- 返回:
- consumer side.
-
getCompletableFuture
public <T> CompletableFuture<T> getCompletableFuture()
get CompletableFuture.- 类型参数:
T-- 返回:
- future
-
getFuture
public <T> Future<T> getFuture()
get future.- 类型参数:
T-- 返回:
- future
-
setFuture
public void setFuture(CompletableFuture<?> future)
set future.- 参数:
future-
-
getUrl
public URL getUrl()
-
setUrl
public void setUrl(URL url)
-
getMethodName
public String getMethodName()
get method name.- 返回:
- method name.
-
setMethodName
public void setMethodName(String methodName)
-
getParameterTypes
public Class<?>[] getParameterTypes()
get parameter types.
-
setParameterTypes
public void setParameterTypes(Class<?>[] parameterTypes)
-
getArguments
public Object[] getArguments()
get arguments.- 返回:
- arguments.
-
setArguments
public void setArguments(Object[] arguments)
-
setLocalAddress
public RpcContext setLocalAddress(String host, int port)
set local address.- 参数:
host-port-- 返回:
- context
-
getLocalAddress
public InetSocketAddress getLocalAddress()
get local address.- 返回:
- local address
-
setLocalAddress
public RpcContext setLocalAddress(InetSocketAddress address)
set local address.- 参数:
address-- 返回:
- context
-
getLocalAddressString
public String getLocalAddressString()
-
getLocalHostName
public String getLocalHostName()
get local host name.- 返回:
- local host name
-
setRemoteAddress
public RpcContext setRemoteAddress(String host, int port)
set remote address.- 参数:
host-port-- 返回:
- context
-
getRemoteAddress
public InetSocketAddress getRemoteAddress()
get remote address.- 返回:
- remote address
-
setRemoteAddress
public RpcContext setRemoteAddress(InetSocketAddress address)
set remote address.- 参数:
address-- 返回:
- context
-
getRemoteApplicationName
public String getRemoteApplicationName()
-
setRemoteApplicationName
public RpcContext setRemoteApplicationName(String remoteApplicationName)
-
getRemoteAddressString
public String getRemoteAddressString()
get remote address string.- 返回:
- remote address string.
-
getRemoteHostName
public String getRemoteHostName()
get remote host name.- 返回:
- remote host name
-
getLocalHost
public String getLocalHost()
get local host.- 返回:
- local host
-
getLocalPort
public int getLocalPort()
get local port.- 返回:
- port
-
getRemoteHost
public String getRemoteHost()
get remote host.- 返回:
- remote host
-
getRemotePort
public int getRemotePort()
get remote port.- 返回:
- remote port
-
getAttachment
public String getAttachment(String key)
also seegetObjectAttachment(String).- 参数:
key-- 返回:
- attachment
-
getObjectAttachment
public Object getObjectAttachment(String key)
get attachment.- 参数:
key-- 返回:
- attachment
-
setAttachment
public RpcContext setAttachment(String key, String value)
set attachment.- 参数:
key-value-- 返回:
- context
-
setAttachment
public RpcContext setAttachment(String key, Object value)
-
setObjectAttachment
public RpcContext setObjectAttachment(String key, Object value)
-
removeAttachment
public RpcContext removeAttachment(String key)
remove attachment.- 参数:
key-- 返回:
- context
-
getAttachments
@Deprecated public Map<String,String> getAttachments()
已过时。get attachments.- 返回:
- attachments
-
getObjectAttachments
public Map<String,Object> getObjectAttachments()
get attachments.- 返回:
- attachments
-
setAttachments
public RpcContext setAttachments(Map<String,String> attachment)
set attachments- 参数:
attachment-- 返回:
- context
-
setObjectAttachments
public RpcContext setObjectAttachments(Map<String,Object> attachment)
set attachments- 参数:
attachment-- 返回:
- context
-
clearAttachments
public void clearAttachments()
-
set
public RpcContext set(String key, Object value)
set value.- 参数:
key-value-- 返回:
- context
-
remove
public RpcContext remove(String key)
remove value.- 参数:
key-- 返回:
- value
-
isServerSide
@Deprecated public boolean isServerSide()
已过时。Replace to isProviderSide()
-
isClientSide
@Deprecated public boolean isClientSide()
已过时。Replace to isConsumerSide()
-
getInvokers
@Deprecated public List<Invoker<?>> getInvokers()
已过时。Replace to getUrls()
-
setInvokers
public RpcContext setInvokers(List<Invoker<?>> invokers)
-
getInvoker
@Deprecated public Invoker<?> getInvoker()
已过时。Replace to getUrl()
-
setInvoker
public RpcContext setInvoker(Invoker<?> invoker)
-
getInvocation
@Deprecated public Invocation getInvocation()
已过时。Replace to getMethodName(), getParameterTypes(), getArguments()
-
setInvocation
public RpcContext setInvocation(Invocation invocation)
-
asyncCall
public <T> CompletableFuture<T> asyncCall(Callable<T> callable)
Async invocation. Timeout will be handled even ifFuture.get()is not called.- 参数:
callable-- 返回:
- get the return result from
future.get()
-
asyncCall
public void asyncCall(Runnable runnable)
one way async call, send request only, and result is not required- 参数:
runnable-
-
startAsync
public static AsyncContext startAsync() throws IllegalStateException
- 返回:
- 抛出:
IllegalStateException
-
isAsyncStarted
public boolean isAsyncStarted()
-
stopAsync
public boolean stopAsync()
-
getAsyncContext
public AsyncContext getAsyncContext()
-
getGroup
public String getGroup()
-
getVersion
public String getVersion()
-
getInterfaceName
public String getInterfaceName()
-
getProtocol
public String getProtocol()
-
getServiceKey
public String getServiceKey()
-
getProtocolServiceKey
public String getProtocolServiceKey()
-
getConsumerUrl
public URL getConsumerUrl()
-
setConsumerUrl
public void setConsumerUrl(URL consumerUrl)
-
setRpcContext
public static void setRpcContext(URL url)
-
-