public abstract class RpcClient extends Object implements Closeable
| 限定符和类型 | 类和说明 |
|---|---|
static class |
RpcClient.ConnectionEvent |
static class |
RpcClient.ServerInfo |
| 限定符和类型 | 字段和说明 |
|---|---|
protected ScheduledExecutorService |
clientEventExecutor |
protected List<ConnectionEventListener> |
connectionEventListeners
listener called where connection's status changed.
|
protected Connection |
currentConnection |
protected BlockingQueue<RpcClient.ConnectionEvent> |
eventLinkedBlockingQueue |
protected ResourceLoader |
resourceLoader |
protected RpcClientConfig |
rpcClientConfig |
protected AtomicReference<RpcClientStatus> |
rpcClientStatus |
protected List<ServerRequestHandler> |
serverRequestHandlers
handlers to process server push request.
|
| 构造器和说明 |
|---|
RpcClient(RpcClientConfig rpcClientConfig) |
RpcClient(RpcClientConfig rpcClientConfig,
ServerListFactory serverListFactory) |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
afterReset(ConnectResetRequest request)
. invoke after receiving reset request
|
void |
asyncRequest(Request request,
RequestCallBack callback)
send async request.
|
abstract Connection |
connectToServer(RpcClient.ServerInfo serverInfo)
connect to server.
|
protected RpcClient.ServerInfo |
currentRpcServer() |
AbilityStatus |
getConnectionAbility(AbilityKey abilityKey)
Return ability of current connection.
|
abstract ConnectionType |
getConnectionType()
get connection type of this client.
|
RpcClient.ServerInfo |
getCurrentServer()
get current server.
|
Map<String,String> |
getLabels()
Getter method for property labels.
|
String |
getName()
Getter method for property name.
|
ServerListFactory |
getServerListFactory()
Getter method for property serverListFactory.
|
String |
getTenant() |
protected Response |
handleServerRequest(Request request)
handle server request.
|
protected void |
init() |
boolean |
isRunning()
check is this client is running.
|
boolean |
isShutdown()
check is this client is shutdown.
|
boolean |
isWaitInitiated()
check is this client is initiated.
|
protected RpcClient.ServerInfo |
nextRpcServer() |
protected void |
notifyConnected(Connection connection)
Notify when client new connected.
|
protected void |
notifyDisConnected(Connection connection)
Notify when client disconnected.
|
void |
onServerListChange()
check if current connected server is in server list, if not switch server.
|
protected void |
reconnect(RpcClient.ServerInfo recommendServerInfo,
boolean onRequestFail)
switch server .
|
void |
registerConnectionListener(ConnectionEventListener connectionEventListener)
Register connection handler.
|
void |
registerServerRequestHandler(ServerRequestHandler serverRequestHandler)
Register serverRequestHandler, the handler will handle the request from server side.
|
Response |
request(Request request)
send request.
|
Response |
request(Request request,
long timeoutMills)
send request.
|
RequestFuture |
requestFuture(Request request)
send async request.
|
abstract int |
rpcPortOffset()
increase offset of the nacos server port for the rpc server port.
|
RpcClient |
serverListFactory(ServerListFactory serverListFactory)
init server list factory. only can init once.
|
void |
setTenant(String tenant) |
void |
shutdown()
Shutdown the Resources, such as Thread Pool.
|
void |
start()
Start this client.
|
void |
switchServerAsync() |
protected void |
switchServerAsync(RpcClient.ServerInfo recommendServerInfo,
boolean onRequestFail) |
void |
switchServerAsyncOnRequestFail() |
protected BlockingQueue<RpcClient.ConnectionEvent> eventLinkedBlockingQueue
protected volatile AtomicReference<RpcClientStatus> rpcClientStatus
protected ScheduledExecutorService clientEventExecutor
protected volatile Connection currentConnection
protected List<ConnectionEventListener> connectionEventListeners
protected List<ServerRequestHandler> serverRequestHandlers
protected RpcClientConfig rpcClientConfig
protected final ResourceLoader resourceLoader
public RpcClient(RpcClientConfig rpcClientConfig)
public RpcClient(RpcClientConfig rpcClientConfig, ServerListFactory serverListFactory)
protected void init()
public RpcClient serverListFactory(ServerListFactory serverListFactory)
serverListFactory - serverListFactoryprotected void notifyDisConnected(Connection connection)
connection - connection has disconnectedprotected void notifyConnected(Connection connection)
connection - connection has connectedpublic boolean isWaitInitiated()
public boolean isRunning()
public boolean isShutdown()
public void onServerListChange()
public final void start()
throws NacosException
NacosExceptionprotected void afterReset(ConnectResetRequest request)
request - request for resettingpublic void shutdown()
throws NacosException
Closeableshutdown 在接口中 CloseableNacosException - exception.public void switchServerAsyncOnRequestFail()
public void switchServerAsync()
protected void switchServerAsync(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)
protected void reconnect(RpcClient.ServerInfo recommendServerInfo, boolean onRequestFail)
public abstract ConnectionType getConnectionType()
public abstract int rpcPortOffset()
public RpcClient.ServerInfo getCurrentServer()
public Response request(Request request) throws NacosException
request - request.NacosExceptionpublic Response request(Request request, long timeoutMills) throws NacosException
request - request.NacosExceptionpublic void asyncRequest(Request request, RequestCallBack callback) throws NacosException
request - request.NacosExceptionpublic RequestFuture requestFuture(Request request) throws NacosException
request - request.NacosExceptionpublic abstract Connection connectToServer(RpcClient.ServerInfo serverInfo) throws Exception
serverInfo - server address to connect.Exception - exception when fail to connect to server.protected Response handleServerRequest(Request request)
request - request.public void registerConnectionListener(ConnectionEventListener connectionEventListener)
connectionEventListener - connectionEventListenerpublic void registerServerRequestHandler(ServerRequestHandler serverRequestHandler)
serverRequestHandler - serverRequestHandlerpublic String getName()
public ServerListFactory getServerListFactory()
protected RpcClient.ServerInfo nextRpcServer()
protected RpcClient.ServerInfo currentRpcServer()
public Map<String,String> getLabels()
public String getTenant()
public void setTenant(String tenant)
public AbilityStatus getConnectionAbility(AbilityKey abilityKey)
abilityKey - ability keyCopyright © 2018–2024 Alibaba Group. All rights reserved.