5
0
mirror of https://github.com/scxwhite/hera.git synced 2025-05-02 22:10:44 +08:00

增加异常日志

This commit is contained in:
苏承祥 2022-11-15 20:39:10 +08:00
parent f8035f4009
commit fb534b03e2
5 changed files with 9 additions and 8 deletions

View File

@ -18,7 +18,7 @@ public class ErrorLog {
log.error(format, arguments); log.error(format, arguments);
} }
public static void error(String msg, Exception e) { public static void error(String msg, Throwable e) {
log.error(msg, e); log.error(msg, e);
} }

View File

@ -42,9 +42,6 @@ public class DistributeLock {
@PostConstruct @PostConstruct
public void init() { public void init() {
workClient.workSchedule.scheduleAtFixedRate(this::checkLock, 10, 60, TimeUnit.SECONDS); workClient.workSchedule.scheduleAtFixedRate(this::checkLock, 10, 60, TimeUnit.SECONDS);
} }
@ -66,8 +63,8 @@ public class DistributeLock {
return; return;
} }
} }
isMaster = WorkContext.host.equals(heraLock.getHost().trim());
if (isMaster = WorkContext.host.equals(heraLock.getHost().trim())) { if (isMaster) {
heraLock.setServerUpdate(new Date()); heraLock.setServerUpdate(new Date());
heraLockService.update(heraLock); heraLockService.update(heraLock);
HeraLog.info("hold lock and update time"); HeraLog.info("hold lock and update time");

View File

@ -43,7 +43,7 @@ public class MasterServer {
//服务端接受客户端的连接 Reactor线程组 //服务端接受客户端的连接 Reactor线程组
bossGroup = new NioEventLoopGroup(1); bossGroup = new NioEventLoopGroup(1);
//SocketChannel的网络读写 //SocketChannel的网络读写
workGroup = new NioEventLoopGroup(1); workGroup = new NioEventLoopGroup(4);
this.handler = handler; this.handler = handler;
serverBootstrap.group(bossGroup, workGroup) serverBootstrap.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class) .channel(NioServerSocketChannel.class)

View File

@ -19,6 +19,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
@ -171,7 +172,7 @@ public class WorkHandler extends SimpleChannelInboundHandler<SocketMessage> {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ErrorLog.error("work exception: " + ctx.channel().remoteAddress(), cause.toString()); ErrorLog.error("work exception: " + ctx.channel().remoteAddress(), cause);
} }
private class ChannelResponse { private class ChannelResponse {

View File

@ -85,6 +85,9 @@ public class WorkerHandleWebRequest {
} }
private static Future<WebResponse> buildMessage(WebRequest request, WorkContext workContext, String errorMsg) { private static Future<WebResponse> buildMessage(WebRequest request, WorkContext workContext, String errorMsg) {
if (workContext.getServerChannel() == null) {
throw new RuntimeException("未连接到master节点请确认master服务已启动。");
}
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
WorkResponseListener responseListener = new WorkResponseListener(request, false, latch, null); WorkResponseListener responseListener = new WorkResponseListener(request, false, latch, null);
workContext.getHandler().addListener(responseListener); workContext.getHandler().addListener(responseListener);