类 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
    • 字段详细资料

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • rpcClientStatus

        protected volatile java.util.concurrent.atomic.AtomicReference<RpcClientStatus> rpcClientStatus
      • clientEventExecutor

        protected java.util.concurrent.ScheduledExecutorService clientEventExecutor
      • 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
    • 方法详细资料

      • 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.NacosException
        Start this client.
        抛出:
        com.alibaba.nacos.api.exception.NacosException
      • shutdown

        public void shutdown()
                      throws com.alibaba.nacos.api.exception.NacosException
        从接口复制的说明: Closeable
        Shutdown the Resources, such as Thread Pool.
        指定者:
        shutdown 在接口中 Closeable
        抛出:
        com.alibaba.nacos.api.exception.NacosException - exception.
      • 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.NacosException
        send 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.NacosException
        send 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.NacosException
        send 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.NacosException
        send 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
      • 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)