类 AbstractClient<T>


  • public abstract class AbstractClient<T>
    extends Object
    作者:
    iotos
    • 字段详细资料

      • LOCK

        public final Object LOCK
      • result

        public T result
      • enableNetLog

        protected boolean enableNetLog
      • eventLoop

        protected io.netty.channel.EventLoopGroup eventLoop
      • channel

        protected volatile io.netty.channel.Channel channel
      • timeout

        protected int timeout
        命令回复超时时间,毫秒
      • connectTimeout

        protected int connectTimeout
        连接超时,毫秒
      • sync

        protected boolean sync
        是不是同步;true 同步模式,即发送消息后等待数据返回

        参考 AbstractClient#setTimeout(int) 超时时间

      • bindPort

        protected int bindPort
      • port

        protected int port
      • channelClass

        protected Class<? extends io.netty.channel.Channel> channelClass
    • 构造器详细资料

      • AbstractClient

        public AbstractClient​(Class<? extends io.netty.channel.Channel> channelClass)
      • AbstractClient

        public AbstractClient​(Class<? extends io.netty.channel.Channel> channelClass,
                              int maxDatagramSize)
    • 方法详细资料

      • setPacketCoder

        public abstract void setPacketCoder​(PacketCoder<T> packetCoder)
        设置编解码器
        参数:
        packetCoder - 包编解码器
      • init

        protected void init()
        初始化工作
      • close

        public void close()
      • preDestroy

        protected void preDestroy()
        准备关闭
      • start

        public void start()
        启动
      • send

        public T send​(T t)
        发送数据

        如果设置sync 为 true,会等待返回数据

        参数:
        t - 消息

        sync 为 true,等待超时,超时会抛出 TimeoutException

        返回:
        sync 为 true 返回 response 数据,否则 null
      • signalAll

        public void signalAll()
      • setEventListener

        public void setEventListener​(EventListener<T> eventListener)
      • loopConnect

        protected void loopConnect()
        直到连接成功
      • isConnected

        public boolean isConnected()
      • connect

        protected void connect()