public abstract class AbstractClient<T> extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
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 String |
host |
Object |
LOCK |
protected CommonMessageListener<T> |
messageListener |
protected io.netty.channel.ChannelDuplexHandler |
packetCoderHandler
实现类传递
|
protected int |
port |
T |
result |
protected boolean |
sync
是不是同步;true 同步模式,即发送消息后等待数据返回
参考
AbstractClient#setTimeout(int) 超时时间 |
protected int |
timeout
命令回复超时时间,毫秒
|
| 构造器和说明 |
|---|
AbstractClient(Class<? extends io.netty.channel.Channel> channelClass) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
await(long timeout) |
void |
close() |
protected void |
connect() |
protected T |
doSend(InternalPacket<T> internalPacket) |
protected void |
init()
初始化工作
|
boolean |
isConnected() |
protected void |
loopConnect()
直到连接成功
|
protected void |
preDestroy()
准备关闭
|
T |
send(T t)
发送数据
如果设置sync 为 true,会等待返回数据
|
void |
setEventListener(EventListener<T> eventListener) |
abstract void |
setPacketCoder(PacketCoder<T> packetCoder)
设置编解码器
|
void |
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 connectTimeout
protected boolean sync
参考 AbstractClient#setTimeout(int) 超时时间
protected int bindPort
protected String host
protected int port
protected Class<? extends io.netty.channel.Channel> channelClass
protected io.netty.channel.ChannelDuplexHandler packetCoderHandler
public AbstractClient(Class<? extends io.netty.channel.Channel> channelClass)
public abstract void setPacketCoder(PacketCoder<T> packetCoder)
packetCoder - 包编解码器protected void init()
public void 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
public void signalAll()
public void await(long timeout)
throws InterruptedException
public void setEventListener(EventListener<T> eventListener)
protected void loopConnect()
public boolean isConnected()
protected void connect()
Copyright © 2021. All rights reserved.