类 ConnectManager


  • public class ConnectManager
    extends Object
    链接管理类 Link Management Class
    作者:
    tag 2019/2/21
    • 字段详细资料

      • startService

        public static boolean startService
        本模块是否可以启动服务(所依赖模块是否可以连接) Can this module start the service? (Can the dependent modules be connected?)
      • LOCAL

        public static final RegisterApi LOCAL
        本模块所有对外提供的接口的详细信息 local module(io.nuls.rpc.RegisterApi) information
      • CMD_PRIORITY_MAP

        public static final Map<String,​Integer> CMD_PRIORITY_MAP
        本模块各个CMD优先级 Each CMD priority of this module
      • CONFIG_ITEM_MAP

        public static final Map<String,​ConfigItem> CONFIG_ITEM_MAP
        本模块配置信息 Configuration information of this module Key: The key Value: Config detail
      • ROLE_MAP

        public static final Map<String,​Map> ROLE_MAP
        Key: 角色,Value:角色的连接信息 Key: role, Value: Connection information of the role
      • INVOKE_MAP

        public static final Map<String,​BaseInvoke> INVOKE_MAP
        调用远程方法时,可以设置自动回调的本地方法。 Key:调用远程方法的messageId,Value:自动回调的本地方法

        When calling a remote method, you can set the local method for automatic callback Key: MessageId that calls remote methods, Value: Local method of automatic callback

      • CHANNEL_DATA_MAP

        public static final Map<io.netty.channel.Channel,​ConnectData> CHANNEL_DATA_MAP
        链接与链接数据的集合

        Key: Channel, Value: ConnectData

      • ROLE_CHANNEL_MAP

        public static final Map<String,​io.netty.channel.Channel> ROLE_CHANNEL_MAP
        角色与链接通道集合 KEY:ROLE VALUE:Channel
      • MSG_ID_KEY_CHANNEL_MAP

        public static final ConcurrentMap<String,​io.netty.channel.Channel> MSG_ID_KEY_CHANNEL_MAP
        messageId对应链接通道对象,用于取消订阅的Request Key:messageId, Value:链接通道

        key: messageId, value: channel

      • CMD_SUBSCRIBE_MESSAGE_MAP

        public static final Map<String,​CopyOnWriteArrayList<Message>> CMD_SUBSCRIBE_MESSAGE_MAP
        接口被那些Message订阅 Interfaces have been subscribed to by those Messages Key:cmd Value:订阅该接口的message队列/Subscribe to the message of the interface
      • MESSAGE_TO_CHANNEL_MAP

        public static final Map<Message,​ConnectData> MESSAGE_TO_CHANNEL_MAP
        订阅接口的Message对应的连接 Connection corresponding to Message of Subscription Interface Key:订阅消息/Subscribe message Value:该订阅消息所属连接
      • SUBSCRIBE_COUNT

        public static final Map<String,​Integer> SUBSCRIBE_COUNT
        接口被订阅次数(事件方式) Number of changes in the return value of the subscribed interface Key: Cmd Value: subscribe count
      • subRequestCount

        public static int subRequestCount
        当前正在处理的订阅请求数量 Number of subscription requests currently being processed
    • 构造器详细资料

      • ConnectManager

        public ConnectManager()
    • 方法详细资料

      • getLocalInvokeCmd

        public static CmdDetail getLocalInvokeCmd​(String cmd,
                                                  double minVersion)
        根据cmd命令和版本号获取本地方法 Getting local methods from CMD commands and version
        参数:
        cmd - Command of remote method
        minVersion - Version of remote method
        返回:
        CmdDetail
      • getLocalInvokeCmd

        public static CmdDetail getLocalInvokeCmd​(String cmd)
        根据cmd命令获取最高版本的方法,逻辑同上 Getting the highest version of local methods from CMD commands
        参数:
        cmd - Command of remote method
        返回:
        CmdDetail
      • scanPackage

        public static void scanPackage​(Set<String> packageName)
                                throws Exception
        扫描指定路径,得到所有接口的详细信息 Scan the specified path for details of all interfaces
        参数:
        packageName - Package full path
        抛出:
        Exception - Duplicate commands found
      • addCmdDetail

        public static void addCmdDetail​(Class<?> claszs)
      • addCmdChangeCount

        public static int addCmdChangeCount​(String cmd)
        返回值改变次数增加1 Increase the changes number of return value by 1
        参数:
        cmd - Command of remote method
      • getCmdChangeCount

        public static int getCmdChangeCount​(String cmd)
        得到返回值的改变数量 Get current changes number of return value
        参数:
        cmd - Command of remote method
        返回:
        long
      • subscribeCountMinus

        public static void subscribeCountMinus​(String cmd)
        Cmd订阅次数减1 Subscription times minus 1
        参数:
        cmd -
      • subscribeCountMinus

        public static void subscribeCountMinus​(Message message)
        取消订阅 Subscription times minus 1
        参数:
        message -
      • subscribeCountAdd

        public static void subscribeCountAdd​(String cmd)
        Cmd订阅次数加1 Subscription times add 1
        参数:
        cmd -
      • subscribeCountAdd

        public static void subscribeCountAdd​(Message message)
        订阅 Subscription times add 1
        参数:
        message -
      • subscribeByEvent

        public static void subscribeByEvent​(ConnectData connectData,
                                            Message message,
                                            Request request)
        订阅接口(按接口改变次数) Subscription interface (number of changes per interface)
        参数:
        connectData - 链接信息
        message - 订阅消息
      • unsubscribeByEvent

        public static void unsubscribeByEvent​(Message message)
        取消订阅接口(按接口改变次数) Unsubscribe interface (number of changes per interface)
        参数:
        message - 取消的订阅消息
      • eventTrigger

        public static void eventTrigger​(String cmd,
                                        Response response)
        订阅接口被调用,判断订阅该接口的事件是否触发
        参数:
        cmd - Command of remote method
        response - Response
      • getRealResponse

        public static Response getRealResponse​(String cmd,
                                               String messageId,
                                               Response response)
        封装真正的返回结果 Encapsulate the true return result
      • getSubscribeKey

        public static String getSubscribeKey​(String messageId,
                                             String cmd)
      • updateStatus

        public static void updateStatus()
        更新模块是否可启动状态 Update module bootAble status
      • isReady

        public static boolean isReady()
        本模块是否可以启动服务(所依赖模块是否可以连接) Can this module start the service? (Can the dependent modules be connected?)
      • getRemoteUri

        public static String getRemoteUri​(String role)
        根据角色返回角色的连接信息 Return the role's connection information based on the role
      • getRemoteUri

        public static String getRemoteUri​(io.netty.channel.socket.SocketChannel channel)
        根据channel的连接信息 Return the role's connection information based on the role
      • getConnectByRole

        public static io.netty.channel.Channel getConnectByRole​(String role)
                                                         throws Exception
        抛出:
        Exception
      • getConnectByUrl

        public static io.netty.channel.Channel getConnectByUrl​(String url)
                                                        throws Exception
        抛出:
        Exception
      • createConnect

        public static io.netty.channel.Channel createConnect​(String url)
                                                      throws Exception
        抛出:
        Exception
      • createConnectData

        public static void createConnectData​(io.netty.channel.Channel channel)
      • disConnect

        public static void disConnect​(io.netty.channel.socket.SocketChannel channel)
        停止或断开一个连接,清除该连接相关信息 Stop or disconnect a connection
      • isPureDigital

        public static boolean isPureDigital​(String string)
        判断是否为正整数 Determine whether it is a positive integer
        参数:
        string - 待验证的值,Value to be verified
        返回:
        boolean
      • sendMessage

        public static void sendMessage​(io.netty.channel.Channel channel,
                                       io.netty.buffer.ByteBuf message)
      • getRoleByChannel

        public static String getRoleByChannel​(io.netty.channel.Channel channel)
      • cacheConnect

        public static io.netty.channel.Channel cacheConnect​(String role,
                                                            io.netty.channel.Channel channel,
                                                            boolean isSender)
        缓存链接信息 Cache link information