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) {
|
if (!enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ public abstract class BallAPI {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
channel = null;
|
channel = null;
|
||||||
if (ttl <= 0) {
|
if (tryCount <= 0) {
|
||||||
for (BallListener listener : getListeners()) {
|
for (BallListener listener : getListeners()) {
|
||||||
try {
|
try {
|
||||||
listener.onServiceDead();
|
listener.onServiceDead();
|
||||||
@@ -292,7 +292,7 @@ public abstract class BallAPI {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
reconnect(ttl - 1);
|
reconnect(tryCount - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void disable() throws SQLException, InterruptedException {
|
protected void disable() throws SQLException, InterruptedException {
|
||||||
|
@@ -12,6 +12,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
@@ -180,12 +181,13 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
public void channelInactive(@NotNull ChannelHandlerContext context) {
|
public void channelInactive(@NotNull ChannelHandlerContext context) {
|
||||||
context.close();
|
context.close();
|
||||||
BallAPI.getInstance().getLogger().warning("与服务器 " + context.channel().remoteAddress() + " 的连接已断开.");
|
BallAPI.getInstance().getLogger().warning("与服务器 " + context.channel().remoteAddress() + " 的连接已断开.");
|
||||||
BallAPI.getInstance().reconnect(5);
|
CoreUtils.WORKER_EXECUTOR.submit(() -> BallAPI.getInstance().reconnect(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
|
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()) {
|
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||||
try {
|
try {
|
||||||
listener.onConnectException(cause);
|
listener.onConnectException(cause);
|
||||||
|
Reference in New Issue
Block a user