类 RpcClient
- java.lang.Object
-
- com.alibaba.nacos.common.remote.client.RpcClient
-
- 所有已实现的接口:
Closeable
- 直接已知子类:
GrpcClient
public abstract class RpcClient extends java.lang.Object implements Closeable
abstract remote client to connect to server.- 版本:
- $Id: RpcClient.java, v 0.1 2020年07月13日 9:15 PM liuzunfei Exp $
- 作者:
- liuzunfei
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 classRpcClient.ConnectionEvent(专用程序包) classRpcClient.ConnectResetRequestHandler(专用程序包) classRpcClient.ReconnectContextstatic classRpcClient.ServerInfo
-
字段概要
字段 修饰符和类型 字段 说明 protected com.alibaba.nacos.api.ability.ClientAbilitiesclientAbilitiesprotected java.util.concurrent.ScheduledExecutorServiceclientEventExecutorprotected java.util.List<ConnectionEventListener>connectionEventListenerslistener called where connection's status changed.protected ConnectioncurrentConnectionprotected java.util.concurrent.BlockingQueue<RpcClient.ConnectionEvent>eventLinkedBlockingQueueprivate static java.util.regex.PatternEXCLUDE_PROTOCOL_PATTERNprivate longlastActiveTimeStampprivate static org.slf4j.LoggerLOGGERprivate java.util.concurrent.BlockingQueue<RpcClient.ReconnectContext>reconnectionSignalprotected RpcClientConfigrpcClientConfigprotected java.util.concurrent.atomic.AtomicReference<RpcClientStatus>rpcClientStatusprivate ServerListFactoryserverListFactoryprotected java.util.List<ServerRequestHandler>serverRequestHandlershandlers to process server push request.private java.lang.Stringtenant
-
构造器概要
构造器 构造器 说明 RpcClient(RpcClientConfig rpcClientConfig)RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory)
-
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 voidasyncRequest(com.alibaba.nacos.api.remote.request.Request request, com.alibaba.nacos.api.remote.RequestCallBack callback)send async request.RpcClientclientAbilities(com.alibaba.nacos.api.ability.ClientAbilities clientAbilities)init client abilities.private voidcloseConnection(Connection connection)abstract ConnectionconnectToServer(RpcClient.ServerInfo serverInfo)connect to server.protected RpcClient.ServerInfocurrentRpcServer()abstract ConnectionTypegetConnectionType()get connection type of this client.RpcClient.ServerInfogetCurrentServer()get current server.java.util.Map<java.lang.String,java.lang.String>getLabels()Getter method for property labels.java.lang.StringgetName()Getter method for property name.ServerListFactorygetServerListFactory()Getter method for property serverListFactory.java.lang.StringgetTenant()protected com.alibaba.nacos.api.remote.response.ResponsehandleServerRequest(com.alibaba.nacos.api.remote.request.Request request)handle server request.private booleanhealthCheck()protected voidinit()booleanisRunning()check is this client is running.booleanisShutdown()check is this client is shutdown.booleanisWaitInitiated()check is this client is initiated.java.util.Map<java.lang.String,java.lang.String>labels()protected RpcClient.ServerInfonextRpcServer()protected voidnotifyConnected()Notify when client new connected.protected voidnotifyDisConnected()Notify when client disconnected.voidonServerListChange()check if current connected server is in server list, if not switch server.protected voidreconnect(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)switch server .voidregisterConnectionListener(ConnectionEventListener connectionEventListener)Register connection handler.voidregisterServerRequestHandler(ServerRequestHandler serverRequestHandler)Register serverRequestHandler, the handler will handle the request from server side.com.alibaba.nacos.api.remote.response.Responserequest(com.alibaba.nacos.api.remote.request.Request request)send request.com.alibaba.nacos.api.remote.response.Responserequest(com.alibaba.nacos.api.remote.request.Request request, long timeoutMills)send request.com.alibaba.nacos.api.remote.RequestFuturerequestFuture(com.alibaba.nacos.api.remote.request.Request request)send async request.private RpcClient.ServerInforesolveServerInfo(java.lang.String serverAddress)resolve server info.abstract intrpcPortOffset()increase offset of the nacos server port for the rpc server port.RpcClientserverListFactory(ServerListFactory serverListFactory)init server list factory. only can init once.voidsetTenant(java.lang.String tenant)voidshutdown()Shutdown the Resources, such as Thread Pool.voidstart()Start this client.voidswitchServerAsync()protected voidswitchServerAsync(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)voidswitchServerAsyncOnRequestFail()
-
-
-
字段详细资料
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
serverListFactory
private ServerListFactory serverListFactory
-
eventLinkedBlockingQueue
protected java.util.concurrent.BlockingQueue<RpcClient.ConnectionEvent> eventLinkedBlockingQueue
-
rpcClientStatus
protected volatile java.util.concurrent.atomic.AtomicReference<RpcClientStatus> rpcClientStatus
-
clientEventExecutor
protected java.util.concurrent.ScheduledExecutorService clientEventExecutor
-
reconnectionSignal
private final java.util.concurrent.BlockingQueue<RpcClient.ReconnectContext> reconnectionSignal
-
currentConnection
protected volatile Connection currentConnection
-
tenant
private java.lang.String tenant
-
clientAbilities
protected com.alibaba.nacos.api.ability.ClientAbilities clientAbilities
-
lastActiveTimeStamp
private long lastActiveTimeStamp
-
connectionEventListeners
protected java.util.List<ConnectionEventListener> connectionEventListeners
listener called where connection's status changed.
-
serverRequestHandlers
protected java.util.List<ServerRequestHandler> serverRequestHandlers
handlers to process server push request.
-
EXCLUDE_PROTOCOL_PATTERN
private static final java.util.regex.Pattern EXCLUDE_PROTOCOL_PATTERN
-
rpcClientConfig
protected RpcClientConfig rpcClientConfig
-
-
构造器详细资料
-
RpcClient
public RpcClient(RpcClientConfig rpcClientConfig)
-
RpcClient
public RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory)
-
-
方法详细资料
-
init
protected void init()
-
labels
public java.util.Map<java.lang.String,java.lang.String> labels()
-
clientAbilities
public RpcClient clientAbilities(com.alibaba.nacos.api.ability.ClientAbilities clientAbilities)
init client abilities.- 参数:
clientAbilities- clientAbilities.
-
serverListFactory
public RpcClient serverListFactory(ServerListFactory serverListFactory)
init server list factory. only can init once.- 参数:
serverListFactory- serverListFactory
-
notifyDisConnected
protected void notifyDisConnected()
Notify when client disconnected.
-
notifyConnected
protected void notifyConnected()
Notify when client new connected.
-
isWaitInitiated
public boolean isWaitInitiated()
check is this client is initiated.- 返回:
- is wait initiated or not.
-
isRunning
public boolean isRunning()
check is this client is running.- 返回:
- is running or not.
-
isShutdown
public boolean isShutdown()
check is this client is shutdown.- 返回:
- is shutdown or not.
-
onServerListChange
public void onServerListChange()
check if current connected server is in server list, if not switch server.
-
start
public final void start() throws com.alibaba.nacos.api.exception.NacosExceptionStart this client.- 抛出:
com.alibaba.nacos.api.exception.NacosException
-
shutdown
public void shutdown() throws com.alibaba.nacos.api.exception.NacosException从接口复制的说明:CloseableShutdown the Resources, such as Thread Pool.
-
healthCheck
private boolean healthCheck()
-
switchServerAsyncOnRequestFail
public void switchServerAsyncOnRequestFail()
-
switchServerAsync
public void switchServerAsync()
-
switchServerAsync
protected void switchServerAsync(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)
-
reconnect
protected void reconnect(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)
switch server .
-
closeConnection
private void closeConnection(Connection connection)
-
getConnectionType
public abstract ConnectionType getConnectionType()
get connection type of this client.- 返回:
- ConnectionType.
-
rpcPortOffset
public abstract int rpcPortOffset()
increase offset of the nacos server port for the rpc server port.- 返回:
- rpc port offset
-
getCurrentServer
public RpcClient.ServerInfo getCurrentServer()
get current server.- 返回:
- server info.
-
request
public com.alibaba.nacos.api.remote.response.Response request(com.alibaba.nacos.api.remote.request.Request request) throws com.alibaba.nacos.api.exception.NacosExceptionsend request.- 参数:
request- request.- 返回:
- response from server.
- 抛出:
com.alibaba.nacos.api.exception.NacosException
-
request
public com.alibaba.nacos.api.remote.response.Response request(com.alibaba.nacos.api.remote.request.Request request, long timeoutMills) throws com.alibaba.nacos.api.exception.NacosExceptionsend request.- 参数:
request- request.- 返回:
- response from server.
- 抛出:
com.alibaba.nacos.api.exception.NacosException
-
asyncRequest
public void asyncRequest(com.alibaba.nacos.api.remote.request.Request request, com.alibaba.nacos.api.remote.RequestCallBack callback) throws com.alibaba.nacos.api.exception.NacosExceptionsend async request.- 参数:
request- request.- 抛出:
com.alibaba.nacos.api.exception.NacosException
-
requestFuture
public com.alibaba.nacos.api.remote.RequestFuture requestFuture(com.alibaba.nacos.api.remote.request.Request request) throws com.alibaba.nacos.api.exception.NacosExceptionsend async request.- 参数:
request- request.- 返回:
- request future.
- 抛出:
com.alibaba.nacos.api.exception.NacosException
-
connectToServer
public abstract Connection connectToServer(RpcClient.ServerInfo serverInfo) throws java.lang.Exception
connect to server.- 参数:
serverInfo- server address to connect.- 返回:
- return connection when successfully connect to server, or null if failed.
- 抛出:
java.lang.Exception- exception when fail to connect to server.
-
handleServerRequest
protected com.alibaba.nacos.api.remote.response.Response handleServerRequest(com.alibaba.nacos.api.remote.request.Request request)
handle server request.- 参数:
request- request.- 返回:
- response.
-
registerConnectionListener
public void registerConnectionListener(ConnectionEventListener connectionEventListener)
Register connection handler. Will be notified when inner connection's state changed.- 参数:
connectionEventListener- connectionEventListener
-
registerServerRequestHandler
public void registerServerRequestHandler(ServerRequestHandler serverRequestHandler)
Register serverRequestHandler, the handler will handle the request from server side.- 参数:
serverRequestHandler- serverRequestHandler
-
getName
public java.lang.String getName()
Getter method for property name.- 返回:
- property value of name
-
getServerListFactory
public ServerListFactory getServerListFactory()
Getter method for property serverListFactory.- 返回:
- property value of serverListFactory
-
nextRpcServer
protected RpcClient.ServerInfo nextRpcServer()
-
currentRpcServer
protected RpcClient.ServerInfo currentRpcServer()
-
resolveServerInfo
private RpcClient.ServerInfo resolveServerInfo(java.lang.String serverAddress)
resolve server info.- 参数:
serverAddress- address.- 返回:
-
getLabels
public java.util.Map<java.lang.String,java.lang.String> getLabels()
Getter method for property labels.- 返回:
- property value of labels
-
getTenant
public java.lang.String getTenant()
-
setTenant
public void setTenant(java.lang.String tenant)
-
-