♻️ Refactoring code. @SneakyThrows
This commit is contained in:
1 parent
f80d6d51e4
commit
271fefcdfc
37 files changed
+206
-171
No files matched your search
+4
-2
@@ -23,6 +23,7 @@ import com.pig4cloud.pigx.codegen.entity.GenConfig;
|
||||
import com.pig4cloud.pigx.codegen.service.SysGeneratorService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -55,13 +56,14 @@ public class SysGeneratorController {
|
||||
/**
|
||||
* 生成代码
|
||||
*/
|
||||
@SneakyThrows
|
||||
@PostMapping("/code")
|
||||
public void generatorCode(@RequestBody GenConfig genConfig, HttpServletResponse response) throws IOException {
|
||||
public void generatorCode(@RequestBody GenConfig genConfig, HttpServletResponse response) {
|
||||
byte[] data = sysGeneratorService.generatorCode(genConfig);
|
||||
|
||||
response.reset();
|
||||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s.zip", genConfig.getTableName()));
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
|
||||
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
|
||||
|
||||
+7
-3
@@ -25,6 +25,7 @@ import com.pig4cloud.pigx.manager.model.ModelInfo;
|
||||
import com.pig4cloud.pigx.manager.model.ModelName;
|
||||
import com.pig4cloud.pigx.manager.model.TxState;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -89,18 +90,21 @@ public class AdminController {
|
||||
return apiAdminService.modelInfos(path);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping(value = "/compensate", method = RequestMethod.GET)
|
||||
public boolean compensate(@RequestParam("path") String path) throws ServiceException {
|
||||
public boolean compensate(@RequestParam("path") String path) {
|
||||
return apiAdminService.compensate(path);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping(value = "/delCompensate", method = RequestMethod.GET)
|
||||
public boolean delCompensate(@RequestParam("path") String path) throws ServiceException {
|
||||
public boolean delCompensate(@RequestParam("path") String path) {
|
||||
return apiAdminService.delCompensate(path);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@RequestMapping(value = "/hasCompensate", method = RequestMethod.GET)
|
||||
public boolean hasCompensate() throws ServiceException {
|
||||
public boolean hasCompensate() {
|
||||
return apiAdminService.hasCompensate();
|
||||
}
|
||||
}
|
||||
+1
@@ -21,6 +21,7 @@ import com.lorne.core.framework.exception.ServiceException;
|
||||
import com.pig4cloud.pigx.manager.compensate.model.TxModel;
|
||||
import com.pig4cloud.pigx.manager.model.ModelName;
|
||||
import com.pig4cloud.pigx.manager.model.TxState;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
+3
-1
@@ -28,6 +28,7 @@ import com.pig4cloud.pigx.manager.model.ModelName;
|
||||
import com.pig4cloud.pigx.manager.model.TxState;
|
||||
import com.pig4cloud.pigx.manager.redis.RedisServerService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -108,7 +109,8 @@ public class ApiAdminServiceImpl implements ApiAdminService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compensate(String path) throws ServiceException {
|
||||
@SneakyThrows
|
||||
public boolean compensate(String path) {
|
||||
return compensateService.executeCompensate(path);
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -36,6 +36,7 @@ import com.pig4cloud.pigx.manager.model.ModelInfo;
|
||||
import com.pig4cloud.pigx.manager.model.ModelName;
|
||||
import com.pig4cloud.pigx.manager.netty.model.TxGroup;
|
||||
import com.pig4cloud.pigx.manager.netty.model.TxInfo;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -309,7 +310,8 @@ public class CompensateServiceImpl implements CompensateService {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean executeCompensate(String path) throws ServiceException {
|
||||
@SneakyThrows
|
||||
public boolean executeCompensate(String path) {
|
||||
|
||||
String json = compensateDao.getCompensate(path);
|
||||
if (json == null) {
|
||||
@@ -326,8 +328,8 @@ public class CompensateServiceImpl implements CompensateService {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean executeCompensateMethod(String json) throws ServiceException {
|
||||
@SneakyThrows
|
||||
private boolean executeCompensateMethod(String json) {
|
||||
JSONObject jsonObject = JSON.parseObject(json);
|
||||
|
||||
String model = jsonObject.getString("model");
|
||||
|
||||
+5
-13
@@ -301,19 +301,11 @@ public class TxManagerSenderServiceImpl implements TxManagerSenderService {
|
||||
|
||||
|
||||
private ScheduledFuture schedule(final String key, int delayTime) {
|
||||
ScheduledFuture future = executorService.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Task task = ConditionUtils.getInstance().getTask(key);
|
||||
if (task != null && !task.isNotify()) {
|
||||
task.setBack(new IBack() {
|
||||
@Override
|
||||
public Object doing(Object... objs) throws Throwable {
|
||||
return "-2";
|
||||
}
|
||||
});
|
||||
task.signalTask();
|
||||
}
|
||||
ScheduledFuture future = executorService.schedule(() -> {
|
||||
Task task = ConditionUtils.getInstance().getTask(key);
|
||||
if (task != null && !task.isNotify()) {
|
||||
task.setBack(objs -> "-2");
|
||||
task.signalTask();
|
||||
}
|
||||
}, delayTime, TimeUnit.SECONDS);
|
||||
|
||||
|
||||
+2
-12
@@ -64,22 +64,12 @@ public class ChannelSender {
|
||||
final String res = HttpUtils.post(url, "msg=" + msg + "&model=" + modelName);
|
||||
if (StringUtils.isNotEmpty(res)) {
|
||||
if (task != null) {
|
||||
task.setBack(new IBack() {
|
||||
@Override
|
||||
public Object doing(Object... objs) throws Throwable {
|
||||
return res;
|
||||
}
|
||||
});
|
||||
task.setBack(objs -> res);
|
||||
task.signalTask();
|
||||
}
|
||||
} else {
|
||||
if (task != null) {
|
||||
task.setBack(new IBack() {
|
||||
@Override
|
||||
public Object doing(Object... objs) throws Throwable {
|
||||
return "-2";
|
||||
}
|
||||
});
|
||||
task.setBack(objs -> "-2");
|
||||
task.signalTask();
|
||||
}
|
||||
}
|
||||
|
||||
+10
-12
@@ -32,6 +32,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -62,15 +63,10 @@ public class TxCoreServerHandler extends ChannelInboundHandlerAdapter { // (1)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
|
||||
final String json = SocketUtils.getJson(msg);
|
||||
logger.debug("request->" + json);
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
service(json, ctx);
|
||||
}
|
||||
});
|
||||
threadPool.execute(() -> service(json, ctx));
|
||||
}
|
||||
|
||||
private void service(String json, ChannelHandlerContext ctx) {
|
||||
@@ -95,7 +91,8 @@ public class TxCoreServerHandler extends ChannelInboundHandlerAdapter { // (1)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||
@SneakyThrows
|
||||
public void channelRegistered(ChannelHandlerContext ctx) {
|
||||
|
||||
//是否到达最大上线连接数
|
||||
if (SocketManager.getInstance().isAllowConnection()) {
|
||||
@@ -107,7 +104,8 @@ public class TxCoreServerHandler extends ChannelInboundHandlerAdapter { // (1)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
||||
@SneakyThrows
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) {
|
||||
|
||||
SocketManager.getInstance().removeClient(ctx.channel());
|
||||
String modelName = ctx.channel().remoteAddress().toString();
|
||||
@@ -118,18 +116,18 @@ public class TxCoreServerHandler extends ChannelInboundHandlerAdapter { // (1)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
//ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
//心跳配置
|
||||
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
|
||||
+1
-6
@@ -32,12 +32,7 @@ public class BaseSignalTaskService {
|
||||
final String data = params.getString("d");
|
||||
Task task = ConditionUtils.getInstance().getTask(key);
|
||||
if (task != null) {
|
||||
task.setBack(new IBack() {
|
||||
@Override
|
||||
public Object doing(Object... objs) throws Throwable {
|
||||
return data;
|
||||
}
|
||||
});
|
||||
task.setBack(objs -> data);
|
||||
task.signalTask();
|
||||
}
|
||||
return res;
|
||||
|
||||
+2
-2
@@ -81,7 +81,7 @@ public class NettyServerServiceImpl implements NettyServerService, DisposableBea
|
||||
.handler(new LoggingHandler(LogLevel.INFO))
|
||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) throws Exception {
|
||||
public void initChannel(SocketChannel ch) {
|
||||
ch.pipeline().addLast("timeout", new IdleStateHandler(heartTime, heartTime, heartTime, TimeUnit.SECONDS));
|
||||
|
||||
ch.pipeline().addLast(new LengthFieldPrepender(4, false));
|
||||
@@ -113,7 +113,7 @@ public class NettyServerServiceImpl implements NettyServerService, DisposableBea
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
public void destroy() {
|
||||
close();
|
||||
threadPool.shutdown();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user