public class RpcContext extends Object
Note: RpcContext is a temporary state holder. States in RpcContext changes every time when request is sent or received.
There are four kinds of RpcContext, which are ServerContext, ClientAttachment, ServerAttachment and ServiceContext. ServiceContext: Using to pass environment parameters in the whole invocation. For example, `remotingApplicationName`, `remoteAddress`, etc.RpcServiceContext
ClientAttachment, ServerAttachment and ServiceContext are using to transfer attachments.
Imaging a situation like this, A is calling B, and B will call C, after that, B wants to return some attachments back to A.
ClientAttachment is using to pass attachments to next hop as a consumer. ( A --> B , in A side)
ServerAttachment is using to fetch attachments from previous hop as a provider. ( A --> B , in B side)
ServerContext is using to return some attachments back to client as a provider. ( A <-- B , in B side)
The reason why using `ServiceContext` is to make API compatible with previous.ContextFilter| 限定符和类型 | 类和说明 |
|---|---|
static class |
RpcContext.RestoreContext
Used to temporarily store and restore all kinds of contexts of current thread.
|
static class |
RpcContext.RestoreServiceContext |
| 限定符和类型 | 方法和说明 |
|---|---|
<T> CompletableFuture<T> |
asyncCall(Callable<T> callable)
Async invocation.
|
void |
asyncCall(Runnable runnable)
one way async call, send request only, and result is not required
|
boolean |
canRemove() |
void |
clearAfterEachInvoke(boolean remove) |
void |
clearAttachments() |
Map<String,Object> |
get()
已过时。
|
Object |
get(String key)
已过时。
|
Object[] |
getArguments()
get arguments.
|
AsyncContext |
getAsyncContext() |
String |
getAttachment(String key)
also see
getObjectAttachment(String). |
Map<String,String> |
getAttachments()
已过时。
|
static CancellationContext |
getCancellationContext() |
static RpcContextAttachment |
getClientAttachment()
get consumer side attachment ( A --> B , in A side)
|
static RpcContextAttachment |
getClientResponseContext()
remove server side context.
|
<T> CompletableFuture<T> |
getCompletableFuture()
get CompletableFuture.
|
URL |
getConsumerUrl() |
static RpcContext |
getContext()
已过时。
|
static RpcServiceContext |
getCurrentServiceContext() |
<T> Future<T> |
getFuture()
get future.
|
String |
getGroup() |
String |
getInterfaceName() |
Invocation |
getInvocation()
已过时。
Replace to getMethodName(), getParameterTypes(), getArguments()
|
Invoker<?> |
getInvoker()
已过时。
Replace to getUrl()
|
List<Invoker<?>> |
getInvokers()
已过时。
Replace to getUrls()
|
InetSocketAddress |
getLocalAddress()
get local address.
|
String |
getLocalAddressString() |
String |
getLocalHost()
get local host.
|
String |
getLocalHostName()
get local host name.
|
int |
getLocalPort()
get local port.
|
String |
getMethodName()
get method name.
|
Object |
getObjectAttachment(String key)
get attachment.
|
Map<String,Object> |
getObjectAttachments()
get attachments.
|
Class<?>[] |
getParameterTypes()
get parameter types.
|
String |
getProtocol() |
String |
getProtocolServiceKey() |
InetSocketAddress |
getRemoteAddress()
get remote address.
|
String |
getRemoteAddressString()
get remote address string.
|
String |
getRemoteApplicationName() |
String |
getRemoteHost()
get remote host.
|
String |
getRemoteHostName()
get remote host name.
|
int |
getRemotePort()
get remote port.
|
Object |
getRequest()
Get the request object of the underlying RPC protocol, e.g.
|
<T> T |
getRequest(Class<T> clazz)
Get the request object of the underlying RPC protocol, e.g.
|
Object |
getResponse()
Get the response object of the underlying RPC protocol, e.g.
|
<T> T |
getResponse(Class<T> clazz)
Get the response object of the underlying RPC protocol, e.g.
|
static RpcContextAttachment |
getServerAttachment()
get provider side attachment from consumer ( A --> B , in B side)
|
static RpcContextAttachment |
getServerContext()
get server side context. ( A <-- B , in B side)
|
static RpcContextAttachment |
getServerResponseContext() |
static RpcServiceContext |
getServiceContext()
Using to pass environment parameters in the whole invocation.
|
String |
getServiceKey() |
URL |
getUrl() |
List<URL> |
getUrls() |
String |
getVersion() |
boolean |
isAsyncStarted() |
boolean |
isClientSide()
已过时。
Replace to isConsumerSide()
|
boolean |
isConsumerSide()
is consumer side.
|
boolean |
isProviderSide()
is provider side.
|
boolean |
isServerSide()
已过时。
Replace to isProviderSide()
|
RpcContext |
remove(String key)
已过时。
|
RpcContext |
removeAttachment(String key)
remove attachment.
|
static void |
removeCancellationContext() |
static void |
removeClientAttachment() |
static void |
removeClientResponseContext() |
static void |
removeContext()
customized for internal use.
|
static void |
removeServerAttachment() |
static void |
removeServerContext() |
static void |
removeServerResponseContext() |
static void |
removeServiceContext() |
static void |
restoreCancellationContext(CancellationContext oldContext) |
static void |
restoreServiceContext(RpcContext.RestoreServiceContext restoreServiceContext) |
RpcContext |
set(String key,
Object value)
已过时。
|
void |
setArguments(Object[] arguments) |
RpcContext |
setAttachment(String key,
Object value) |
RpcContext |
setAttachment(String key,
String value)
set attachment.
|
RpcContext |
setAttachments(Map<String,String> attachment)
set attachments
|
void |
setConsumerUrl(URL consumerUrl) |
void |
setFuture(CompletableFuture<?> future)
set future.
|
RpcContext |
setInvocation(Invocation invocation) |
RpcContext |
setInvoker(Invoker<?> invoker) |
RpcContext |
setInvokers(List<Invoker<?>> invokers) |
RpcContext |
setLocalAddress(InetSocketAddress address)
set local address.
|
RpcContext |
setLocalAddress(String host,
int port)
set local address.
|
void |
setMethodName(String methodName) |
RpcContext |
setObjectAttachment(String key,
Object value) |
RpcContext |
setObjectAttachments(Map<String,Object> attachment)
set attachments
|
void |
setParameterTypes(Class<?>[] parameterTypes) |
RpcContext |
setRemoteAddress(InetSocketAddress address)
set remote address.
|
RpcContext |
setRemoteAddress(String host,
int port)
set remote address.
|
RpcContext |
setRemoteApplicationName(String remoteApplicationName) |
void |
setRequest(Object request) |
void |
setResponse(Object response) |
static void |
setRpcContext(URL url)
已过时。
|
void |
setUrl(URL url) |
void |
setUrls(List<URL> urls) |
static AsyncContext |
startAsync() |
boolean |
stopAsync() |
static RpcContext.RestoreServiceContext |
storeServiceContext() |
public static CancellationContext getCancellationContext()
public static void removeCancellationContext()
public static void restoreCancellationContext(CancellationContext oldContext)
public static RpcContextAttachment getServerContext()
public static RpcContextAttachment getClientResponseContext()
ContextFilterpublic static RpcContextAttachment getServerResponseContext()
public static void removeClientResponseContext()
public static void removeServerResponseContext()
@Deprecated public static RpcContext getContext()
public static RpcContextAttachment getClientAttachment()
public static RpcContextAttachment getServerAttachment()
public static void removeServerContext()
public boolean canRemove()
public void clearAfterEachInvoke(boolean remove)
public static RpcServiceContext getServiceContext()
RpcServiceContextpublic static RpcServiceContext getCurrentServiceContext()
public static void removeServiceContext()
public static void removeClientAttachment()
public static void removeServerAttachment()
public static void removeContext()
public Object getRequest()
public void setRequest(Object request)
public <T> T getRequest(Class<T> clazz)
public Object getResponse()
public void setResponse(Object response)
public <T> T getResponse(Class<T> clazz)
public boolean isProviderSide()
public boolean isConsumerSide()
public <T> CompletableFuture<T> getCompletableFuture()
T - public <T> Future<T> getFuture()
T - public void setFuture(CompletableFuture<?> future)
future - public URL getUrl()
public void setUrl(URL url)
public String getMethodName()
public void setMethodName(String methodName)
public Class<?>[] getParameterTypes()
public void setParameterTypes(Class<?>[] parameterTypes)
public Object[] getArguments()
public void setArguments(Object[] arguments)
public RpcContext setLocalAddress(String host, int port)
host - port - public InetSocketAddress getLocalAddress()
public RpcContext setLocalAddress(InetSocketAddress address)
address - public String getLocalAddressString()
public String getLocalHostName()
public RpcContext setRemoteAddress(String host, int port)
host - port - public InetSocketAddress getRemoteAddress()
public RpcContext setRemoteAddress(InetSocketAddress address)
address - public String getRemoteApplicationName()
public RpcContext setRemoteApplicationName(String remoteApplicationName)
public String getRemoteAddressString()
public String getRemoteHostName()
public String getLocalHost()
public int getLocalPort()
public String getRemoteHost()
public int getRemotePort()
public String getAttachment(String key)
getObjectAttachment(String).key - public Object getObjectAttachment(String key)
key - public RpcContext setAttachment(String key, String value)
key - value - public RpcContext setAttachment(String key, Object value)
public RpcContext setObjectAttachment(String key, Object value)
public RpcContext removeAttachment(String key)
key - @Deprecated public Map<String,String> getAttachments()
public Map<String,Object> getObjectAttachments()
public RpcContext setAttachments(Map<String,String> attachment)
attachment - public RpcContext setObjectAttachments(Map<String,Object> attachment)
attachment - public void clearAttachments()
@Deprecated public Map<String,Object> get()
@Deprecated public RpcContext set(String key, Object value)
key - value - @Deprecated public RpcContext remove(String key)
key - @Deprecated public Object get(String key)
key - @Deprecated public boolean isServerSide()
@Deprecated public boolean isClientSide()
@Deprecated public List<Invoker<?>> getInvokers()
public RpcContext setInvokers(List<Invoker<?>> invokers)
@Deprecated public Invoker<?> getInvoker()
public RpcContext setInvoker(Invoker<?> invoker)
@Deprecated public Invocation getInvocation()
public RpcContext setInvocation(Invocation invocation)
public <T> CompletableFuture<T> asyncCall(Callable<T> callable)
Future.get() is not called.callable - future.get()public void asyncCall(Runnable runnable)
runnable - public static AsyncContext startAsync() throws IllegalStateException
IllegalStateExceptionpublic boolean isAsyncStarted()
public boolean stopAsync()
public AsyncContext getAsyncContext()
public String getGroup()
public String getVersion()
public String getInterfaceName()
public String getProtocol()
public String getServiceKey()
public String getProtocolServiceKey()
public URL getConsumerUrl()
public void setConsumerUrl(URL consumerUrl)
@Deprecated public static void setRpcContext(URL url)
public static RpcContext.RestoreServiceContext storeServiceContext()
public static void restoreServiceContext(RpcContext.RestoreServiceContext restoreServiceContext)
Copyright © 2011–2020 The Apache Software Foundation. All rights reserved.