类 AbstractClient<T>
- java.lang.Object
-
- me.hekr.iotos.softgateway.network.common.client.AbstractClient<T>
-
public abstract class AbstractClient<T> extends Object
- 作者:
- iotos
-
-
字段概要
字段 修饰符和类型 字段 说明 protected intbindPortprotected io.netty.channel.Channelchannelprotected Class<? extends io.netty.channel.Channel>channelClassprotected ClientMessageHandler<T>clientMessageHandlerprotected intconnectTimeout连接超时,毫秒protected booleanenableNetLogprotected io.netty.channel.EventLoopGroupeventLoopprotected StringhostObjectLOCKprotected CommonMessageListener<T>messageListenerprotected PacketCoderHandlerFactorypacketCoderHandlerFactory实现类传递protected intportTresultprotected booleansync是不是同步;true 同步模式,即发送消息后等待数据返回protected inttimeout命令回复超时时间,毫秒
-
构造器概要
构造器 构造器 说明 AbstractClient(Class<? extends io.netty.channel.Channel> channelClass)AbstractClient(Class<? extends io.netty.channel.Channel> channelClass, int maxDatagramSize)
-
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 voidawait(long timeout)voidclose()protected voidconnect()protected TdoSend(InternalPacket<T> internalPacket)protected voidinit()初始化工作booleanisConnected()protected voidloopConnect()直到连接成功protected voidpreDestroy()准备关闭Tsend(T t)发送数据voidsetEventListener(EventListener<T> eventListener)abstract voidsetPacketCoder(PacketCoder<T> packetCoder)设置编解码器voidsignalAll()voidstart()启动
-
-
-
字段详细资料
-
LOCK
public final Object LOCK
-
result
public T result
-
enableNetLog
protected boolean enableNetLog
-
eventLoop
protected io.netty.channel.EventLoopGroup eventLoop
-
messageListener
protected CommonMessageListener<T> messageListener
-
clientMessageHandler
protected ClientMessageHandler<T> clientMessageHandler
-
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
-
host
protected String host
-
port
protected int port
-
channelClass
protected Class<? extends io.netty.channel.Channel> channelClass
-
packetCoderHandlerFactory
protected PacketCoderHandlerFactory packetCoderHandlerFactory
实现类传递
-
-
方法详细资料
-
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
-
doSend
protected T doSend(InternalPacket<T> internalPacket) throws InterruptedException, TimeoutException
-
signalAll
public void signalAll()
-
await
public void await(long timeout) throws InterruptedException
-
setEventListener
public void setEventListener(EventListener<T> eventListener)
-
loopConnect
protected void loopConnect()
直到连接成功
-
isConnected
public boolean isConnected()
-
connect
protected void connect()
-
-