perf: 重写部分代码
This commit is contained in:
@@ -261,7 +261,7 @@ public abstract class BallAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public void reconnect(int ttl) {
|
||||
public void reconnect(int tryCount) {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public abstract class BallAPI {
|
||||
return;
|
||||
}
|
||||
channel = null;
|
||||
if (ttl <= 0) {
|
||||
if (tryCount <= 0) {
|
||||
for (BallListener listener : getListeners()) {
|
||||
try {
|
||||
listener.onServiceDead();
|
||||
@@ -292,7 +292,7 @@ public abstract class BallAPI {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
reconnect(ttl - 1);
|
||||
reconnect(tryCount - 1);
|
||||
}
|
||||
|
||||
protected void disable() throws SQLException, InterruptedException {
|
||||
|
@@ -12,6 +12,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
@@ -180,12 +181,13 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
public void channelInactive(@NotNull ChannelHandlerContext context) {
|
||||
context.close();
|
||||
BallAPI.getInstance().getLogger().warning("与服务器 " + context.channel().remoteAddress() + " 的连接已断开.");
|
||||
BallAPI.getInstance().reconnect(5);
|
||||
CoreUtils.WORKER_EXECUTOR.submit(() -> BallAPI.getInstance().reconnect(5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
|
||||
BallAPI.getInstance().getLogger().log(Level.WARNING, "与服务器 " + context.channel().remoteAddress() + " 通信时出现了一个错误: ", cause);
|
||||
SocketAddress address = context.channel().remoteAddress();
|
||||
BallAPI.getInstance().getLogger().log(Level.WARNING, "与服务器 " + address + " 通信时出现了一个错误: ", cause);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onConnectException(cause);
|
||||
|
Reference in New Issue
Block a user