public abstract class RpcClient extends Object implements Closeable
| 限定符和类型 | 类和说明 |
|---|---|
class |
RpcClient.ConnectionEvent |
static class |
RpcClient.ServerInfo |
| 限定符和类型 | 字段和说明 |
|---|---|
protected ClientAbilities |
clientAbilities |
protected ScheduledExecutorService |
clientEventExecutor |
protected List<ConnectionEventListener> |
connectionEventListeners
listener called where connection's status changed.
|
protected Connection |
currentConnection |
protected LinkedBlockingQueue<RpcClient.ConnectionEvent> |
eventLinkedBlockingQueue |
protected Map<String,String> |
labels |
protected AtomicReference<RpcClientStatus> |
rpcClientStatus |
protected List<ServerRequestHandler> |
serverRequestHandlers
handlers to process server push request.
|
| 构造器和说明 |
|---|
RpcClient(ServerListFactory serverListFactory) |
RpcClient(String name) |
RpcClient(String name,
ServerListFactory serverListFactory) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
asyncRequest(Request request,
RequestCallBack callback)
send async request.
|
RpcClient |
clientAbilities(ClientAbilities clientAbilities)
init client abilities.
|
abstract Connection |
connectToServer(RpcClient.ServerInfo serverInfo)
connect to server.
|
protected RpcClient.ServerInfo |
currentRpcServer() |
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.
|
boolean |
isRunning()
check is this client is running.
|
boolean |
isShutdown()
check is this client is shutdown.
|
boolean |
isWaitInitiated()
check is this client is initiated.
|
RpcClient |
keepAlive(long keepAliveTime,
TimeUnit timeUnit)
init keepalive time.
|
RpcClient |
labels(Map<String,String> labels)
init labels.
|
protected RpcClient.ServerInfo |
nextRpcServer() |
protected void |
notifyConnected()
Notify when client new connected.
|
protected void |
notifyDisConnected()
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 |
setName(String name)
Setter method for property name.
|
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 LinkedBlockingQueue<RpcClient.ConnectionEvent> eventLinkedBlockingQueue
protected volatile AtomicReference<RpcClientStatus> rpcClientStatus
protected ScheduledExecutorService clientEventExecutor
protected volatile Connection currentConnection
protected ClientAbilities clientAbilities
protected List<ConnectionEventListener> connectionEventListeners
protected List<ServerRequestHandler> serverRequestHandlers
public RpcClient(String name)
public RpcClient(ServerListFactory serverListFactory)
public RpcClient(String name, ServerListFactory serverListFactory)
public RpcClient clientAbilities(ClientAbilities clientAbilities)
clientAbilities - clientAbilities.public RpcClient serverListFactory(ServerListFactory serverListFactory)
serverListFactory - serverListFactorypublic RpcClient keepAlive(long keepAliveTime, TimeUnit timeUnit)
keepAliveTime - keepAliveTimetimeUnit - timeUnitprotected void notifyDisConnected()
protected void notifyConnected()
public boolean isWaitInitiated()
public boolean isRunning()
public boolean isShutdown()
public void onServerListChange()
public final void start()
throws NacosException
NacosExceptionpublic 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 void setName(String name)
name - value to be assigned to property namepublic ServerListFactory getServerListFactory()
protected RpcClient.ServerInfo nextRpcServer()
protected RpcClient.ServerInfo currentRpcServer()
public Map<String,String> getLabels()
public String getTenant()
public void setTenant(String tenant)
Copyright © 2018–2022 Alibaba Group. All rights reserved.