public abstract class AbstractClient<T> extends Object
Abstract AbstractClient class.
| 限定符和类型 | 字段和说明 |
|---|---|
protected int |
bindPort |
protected io.netty.channel.Channel |
channel |
protected Class<? extends io.netty.channel.Channel> |
channelClass |
protected ClientMessageHandler<T> |
clientMessageHandler |
protected int |
connectTimeout
连接超时,毫秒
|
protected boolean |
enableNetLog |
protected io.netty.channel.EventLoopGroup |
eventLoop |
protected int |
heartbeatTime
心跳超时毫秒,小于0不设置触发
|
protected String |
host |
Object |
LOCK |
protected CommonMessageListener<T> |
messageListener |
protected PacketCoderHandlerFactory |
packetCoderHandlerFactory
实现类传递
|
protected int |
port |
protected int |
reconnectWait
重连等待时间毫秒
|
T |
result |
protected boolean |
sync
是不是同步;true 同步模式,即发送消息后等待数据返回
参考
AbstractClient#setTimeout(int) 超时时间 |
protected int |
timeout
命令回复超时时间,毫秒
|
| 构造器和说明 |
|---|
AbstractClient(Class<? extends io.netty.channel.Channel> channelClass)
Constructor for AbstractClient.
|
AbstractClient(Class<? extends io.netty.channel.Channel> channelClass,
int maxDatagramSize)
Constructor for AbstractClient.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
await(long timeout)
await.
|
void |
close()
close.
|
protected void |
connect()
connect.
|
protected T |
doSend(InternalPacket<T> internalPacket)
doSend.
|
protected void |
init()
初始化工作
|
boolean |
isConnected()
isConnected.
|
protected void |
loopConnect()
直到连接成功
|
protected void |
preDestroy()
准备关闭
|
T |
send(T t)
发送数据
如果设置sync 为 true,会等待返回数据
|
void |
setEventListener(EventListener<T> eventListener)
Setter for the field
eventListener. |
abstract void |
setPacketCoder(PacketCoder<T> packetCoder)
设置编解码器
|
void |
signalAll()
signalAll.
|
void |
start()
启动
|
public final Object LOCK
public T result
protected boolean enableNetLog
protected io.netty.channel.EventLoopGroup eventLoop
protected CommonMessageListener<T> messageListener
protected ClientMessageHandler<T> clientMessageHandler
protected volatile io.netty.channel.Channel channel
protected int timeout
protected int heartbeatTime
protected int connectTimeout
protected int reconnectWait
protected boolean sync
参考 AbstractClient#setTimeout(int) 超时时间
protected int bindPort
protected String host
protected int port
protected Class<? extends io.netty.channel.Channel> channelClass
protected PacketCoderHandlerFactory packetCoderHandlerFactory
public AbstractClient(Class<? extends io.netty.channel.Channel> channelClass)
Constructor for AbstractClient.
channelClass - a Class object.public abstract void setPacketCoder(PacketCoder<T> packetCoder)
packetCoder - 包编解码器protected void init()
public void close()
close.
protected void preDestroy()
public void start()
public T send(T t)
如果设置sync 为 true,会等待返回数据
t - 消息
sync 为 true,等待超时,超时会抛出 TimeoutException
protected T doSend(InternalPacket<T> internalPacket) throws InterruptedException, TimeoutException
doSend.
internalPacket - a InternalPacket object.InterruptedException - if any.TimeoutException - if any.public void signalAll()
signalAll.
public void await(long timeout)
throws InterruptedException
await.
timeout - a long.InterruptedException - if any.public void setEventListener(EventListener<T> eventListener)
Setter for the field eventListener.
eventListener - a EventListener object.protected void loopConnect()
public boolean isConnected()
isConnected.
protected void connect()
connect.
Copyright © 2023. All rights reserved.