com.alibaba.dubbo.rpc
Class RpcContext

java.lang.Object
  extended by com.alibaba.dubbo.rpc.RpcContext

public class RpcContext
extends Object

Thread local context. (API, ThreadLocal, ThreadSafe)

注意:RpcContext是一个临时状态记录器,当接收到RPC请求,或发起RPC请求时,RpcContext的状态都会变化。 比如:A调B,B再调C,则B机器上,在B调C之前,RpcContext记录的是A调B的信息,在B调C之后,RpcContext记录的是B调C的信息。

Author:
qian.lei, william.liangf
See Also:
ContextFilter

Method Summary
<T> Future<T>
asyncCall(Callable<T> callable)
          异步调用 ,需要返回值,即使步调用Future.get方法,也会处理调用超时问题.
 void asyncCall(Runnable runable)
          oneway调用,只发送请求,不接收返回结果.
 void clearAttachments()
           
 Map<String,Object> get()
          get values.
 Object get(String key)
          get value.
 Object[] getArguments()
          get arguments.
 String getAttachment(String key)
          get attachment.
 Map<String,String> getAttachments()
          get attachments.
static RpcContext getContext()
          get context.
<T> Future<T>
getFuture()
          get future.
 Invocation getInvocation()
          Deprecated. Replace to getMethodName(), getParameterTypes(), getArguments()
 Invoker<?> getInvoker()
          Deprecated. Replace to getUrl()
 List<Invoker<?>> getInvokers()
          Deprecated. 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.
 Class<?>[] getParameterTypes()
          get parameter types.
 InetSocketAddress getRemoteAddress()
          get remote address.
 String getRemoteAddressString()
          get remote address string.
 String getRemoteHost()
          get remote host.
 String getRemoteHostName()
          get remote host name.
 int getRemotePort()
          get remote port.
 URL getUrl()
           
 List<URL> getUrls()
           
 boolean isClientSide()
          Deprecated. Replace to isConsumerSide()
 boolean isConsumerSide()
          is consumer side.
 boolean isProviderSide()
          is provider side.
 boolean isServerSide()
          Deprecated. Replace to isProviderSide()
 RpcContext remove(String key)
          remove value.
 RpcContext removeAttachment(String key)
          remove attachment.
static void removeContext()
          remove context.
 RpcContext set(String key, Object value)
          set value.
 void setArguments(Object[] arguments)
           
 RpcContext setAttachment(String key, String value)
          set attachment.
 RpcContext setAttachments(Map<String,String> attachment)
          set attachments
 void setFuture(Future<?> 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)
           
 void setParameterTypes(Class<?>[] parameterTypes)
           
 RpcContext setRemoteAddress(InetSocketAddress address)
          set remote address.
 RpcContext setRemoteAddress(String host, int port)
          set remote address.
 void setUrl(URL url)
           
 void setUrls(List<URL> urls)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContext

public static RpcContext getContext()
get context.

Returns:
context

removeContext

public static void removeContext()
remove context.

See Also:
ContextFilter

isProviderSide

public boolean isProviderSide()
is provider side.

Returns:
provider side.

isConsumerSide

public boolean isConsumerSide()
is consumer side.

Returns:
consumer side.

getFuture

public <T> Future<T> getFuture()
get future.

Type Parameters:
T -
Returns:
future

setFuture

public void setFuture(Future<?> future)
set future.

Parameters:
future -

getUrls

public List<URL> getUrls()

setUrls

public void setUrls(List<URL> urls)

getUrl

public URL getUrl()

setUrl

public void setUrl(URL url)

getMethodName

public String getMethodName()
get method name.

Returns:
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.

Returns:
arguments.

setArguments

public void setArguments(Object[] arguments)

setLocalAddress

public RpcContext setLocalAddress(String host,
                                  int port)
set local address.

Parameters:
host -
port -
Returns:
context

getLocalAddress

public InetSocketAddress getLocalAddress()
get local address.

Returns:
local address

setLocalAddress

public RpcContext setLocalAddress(InetSocketAddress address)
set local address.

Parameters:
address -
Returns:
context

getLocalAddressString

public String getLocalAddressString()

getLocalHostName

public String getLocalHostName()
get local host name.

Returns:
local host name

setRemoteAddress

public RpcContext setRemoteAddress(String host,
                                   int port)
set remote address.

Parameters:
host -
port -
Returns:
context

getRemoteAddress

public InetSocketAddress getRemoteAddress()
get remote address.

Returns:
remote address

setRemoteAddress

public RpcContext setRemoteAddress(InetSocketAddress address)
set remote address.

Parameters:
address -
Returns:
context

getRemoteAddressString

public String getRemoteAddressString()
get remote address string.

Returns:
remote address string.

getRemoteHostName

public String getRemoteHostName()
get remote host name.

Returns:
remote host name

getLocalHost

public String getLocalHost()
get local host.

Returns:
local host

getLocalPort

public int getLocalPort()
get local port.

Returns:
port

getRemoteHost

public String getRemoteHost()
get remote host.

Returns:
remote host

getRemotePort

public int getRemotePort()
get remote port.

Returns:
remote port

getAttachment

public String getAttachment(String key)
get attachment.

Parameters:
key -
Returns:
attachment

setAttachment

public RpcContext setAttachment(String key,
                                String value)
set attachment.

Parameters:
key -
value -
Returns:
context

removeAttachment

public RpcContext removeAttachment(String key)
remove attachment.

Parameters:
key -
Returns:
context

getAttachments

public Map<String,String> getAttachments()
get attachments.

Returns:
attachments

setAttachments

public RpcContext setAttachments(Map<String,String> attachment)
set attachments

Parameters:
attachment -
Returns:
context

clearAttachments

public void clearAttachments()

get

public Map<String,Object> get()
get values.

Returns:
values

set

public RpcContext set(String key,
                      Object value)
set value.

Parameters:
key -
value -
Returns:
context

remove

public RpcContext remove(String key)
remove value.

Parameters:
key -
Returns:
value

get

public Object get(String key)
get value.

Parameters:
key -
Returns:
value

isServerSide

@Deprecated
public boolean isServerSide()
Deprecated. Replace to isProviderSide()


isClientSide

@Deprecated
public boolean isClientSide()
Deprecated. Replace to isConsumerSide()


getInvokers

@Deprecated
public List<Invoker<?>> getInvokers()
Deprecated. Replace to getUrls()


setInvokers

public RpcContext setInvokers(List<Invoker<?>> invokers)

getInvoker

@Deprecated
public Invoker<?> getInvoker()
Deprecated. Replace to getUrl()


setInvoker

public RpcContext setInvoker(Invoker<?> invoker)

getInvocation

@Deprecated
public Invocation getInvocation()
Deprecated. Replace to getMethodName(), getParameterTypes(), getArguments()


setInvocation

public RpcContext setInvocation(Invocation invocation)

asyncCall

public <T> Future<T> asyncCall(Callable<T> callable)
异步调用 ,需要返回值,即使步调用Future.get方法,也会处理调用超时问题.

Parameters:
callable -
Returns:
通过future.get()获取返回结果.

asyncCall

public void asyncCall(Runnable runable)
oneway调用,只发送请求,不接收返回结果.

Parameters:
callable -


Copyright © 2012–2017 Alibaba. All rights reserved.