Thread 이슈 및 클라이언트 종료 조건 수정
@4bc5fbcc262eb29eafdc36688b9043ae372eed53
--- build.gradle
+++ build.gradle
... | ... | @@ -50,6 +50,10 @@ |
| 50 | 50 |
// https://mvnrepository.com/artifact/org.jdom/jdom2 |
| 51 | 51 |
implementation 'org.jdom:jdom2:2.0.6.1' |
| 52 | 52 |
|
| 53 |
+ implementation("com.slack.api:bolt:1.40.3")
|
|
| 54 |
+ implementation("com.slack.api:bolt-servlet:1.40.3")
|
|
| 55 |
+ implementation("com.slack.api:bolt-jetty:1.40.3")
|
|
| 56 |
+ |
|
| 53 | 57 |
testCompileOnly 'org.projectlombok:lombok' |
| 54 | 58 |
testAnnotationProcessor 'org.projectlombok:lombok' |
| 55 | 59 |
} |
--- src/main/java/com/munjaon/server/queue/pool/ReportQueue.java
+++ src/main/java/com/munjaon/server/queue/pool/ReportQueue.java
... | ... | @@ -88,24 +88,18 @@ |
| 88 | 88 |
} |
| 89 | 89 |
} |
| 90 | 90 |
|
| 91 |
- public boolean isTruncateQueue(int maxWriteCount) {
|
|
| 91 |
+ public boolean isTruncateQueue(int maxQueueCount) {
|
|
| 92 | 92 |
synchronized (lockObject) {
|
| 93 |
- if (this.writeCounter >= maxWriteCount) {
|
|
| 94 |
- if (this.writeCounter == this.readCounter) {
|
|
| 95 |
- return true; |
|
| 96 |
- } |
|
| 97 |
- return false; |
|
| 93 |
+ if (this.writeCounter > 0 && this.writeCounter >= maxQueueCount) {
|
|
| 94 |
+ return this.writeCounter == this.readCounter; |
|
| 98 | 95 |
} |
| 99 | 96 |
return false; |
| 100 | 97 |
} |
| 101 | 98 |
} |
| 102 | 99 |
|
| 103 |
- public boolean isWriteLimit(int maxWriteCount) {
|
|
| 100 |
+ public boolean isWriteLimit(int maxQueueCount) {
|
|
| 104 | 101 |
synchronized (lockObject) {
|
| 105 |
- if (this.writeCounter >= maxWriteCount) {
|
|
| 106 |
- return true; |
|
| 107 |
- } |
|
| 108 |
- return false; |
|
| 102 |
+ return this.writeCounter > 0 && this.writeCounter >= maxQueueCount; |
|
| 109 | 103 |
} |
| 110 | 104 |
} |
| 111 | 105 |
|
--- src/main/java/com/munjaon/server/server/config/ServerConfig.java
+++ src/main/java/com/munjaon/server/server/config/ServerConfig.java
... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 |
/* 사용자 정보 조회 체크 시간 */ |
| 14 | 14 |
public static final long USER_STATUS_CYCLE_TIME = 60000; |
| 15 | 15 |
/* Deliver Thread 실행 시간 */ |
| 16 |
- public static final long DELIVER_EXEC_CYCLE_TIME = 5000; |
|
| 16 |
+ public static final long DELIVER_EXEC_CYCLE_TIME = 3000; |
|
| 17 | 17 |
/* Report Thread 실행 시간 */ |
| 18 |
- public static final long REPORT_EXEC_CYCLE_TIME = 5000; |
|
| 18 |
+ public static final long REPORT_EXEC_CYCLE_TIME = 3000; |
|
| 19 | 19 |
} |
--- src/main/java/com/munjaon/server/server/dto/ReportUserDto.java
+++ src/main/java/com/munjaon/server/server/dto/ReportUserDto.java
... | ... | @@ -21,7 +21,8 @@ |
| 21 | 21 |
private ReportQueue reportQueue; //ReportQueue |
| 22 | 22 |
private MemberDto memberDto; //사용자 정보 |
| 23 | 23 |
private int command; //요청 command |
| 24 |
- private int maxWriteCount; //요청 command |
|
| 24 |
+ private int maxWriteCount; //건당 Report 개수 |
|
| 25 |
+ private int maxQueueCount; //Report Queue에 유지할 건수 |
|
| 25 | 26 |
/* 요청을 처리중인지 여부 */ |
| 26 | 27 |
private boolean isRunningMode; |
| 27 | 28 |
|
--- src/main/java/com/munjaon/server/server/packet/Bind.java
+++ src/main/java/com/munjaon/server/server/packet/common/Bind.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import java.nio.ByteBuffer; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/CommonMessage.java
+++ src/main/java/com/munjaon/server/server/packet/common/CommonMessage.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.CommonUtil; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/Header.java
+++ src/main/java/com/munjaon/server/server/packet/common/Header.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.ByteUtil; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/KakaoMessage.java
+++ src/main/java/com/munjaon/server/server/packet/common/KakaoMessage.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.CommonUtil; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/LinkCheck.java
+++ src/main/java/com/munjaon/server/server/packet/common/LinkCheck.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import java.nio.ByteBuffer; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/LmsMessage.java
+++ src/main/java/com/munjaon/server/server/packet/common/LmsMessage.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.CommonUtil; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/MmsMessage.java
+++ src/main/java/com/munjaon/server/server/packet/common/MmsMessage.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.CommonUtil; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/Packet.java
+++ src/main/java/com/munjaon/server/server/packet/common/Packet.java
... | ... | @@ -1,10 +1,13 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import java.nio.ByteBuffer; |
| 4 | 4 |
|
| 5 | 5 |
public final class Packet {
|
| 6 | 6 |
public static final byte SET_DEFAULT_BYTE = (byte) 0x00; |
| 7 |
- public static final long LINK_CHECK_CYCLE = 30000L; |
|
| 7 |
+ /* LinkCheck 전송 체크 시간 간격 */ |
|
| 8 |
+ public static final long LINK_CHECK_CYCLE = 10000L; |
|
| 9 |
+ /* 패킷 만료 시간 체크 */ |
|
| 10 |
+ public static final long LIMIT_PACKET_TIMEOUT = 25000L; |
|
| 8 | 11 |
public static void setDefaultByte(ByteBuffer buffer) {
|
| 9 | 12 |
if (buffer == null) {
|
| 10 | 13 |
return; |
--- src/main/java/com/munjaon/server/server/packet/Report.java
+++ src/main/java/com/munjaon/server/server/packet/common/Report.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.server.dto.ReportDto; |
| 4 | 4 |
|
--- src/main/java/com/munjaon/server/server/packet/SmsMessage.java
+++ src/main/java/com/munjaon/server/server/packet/common/SmsMessage.java
... | ... | @@ -1,4 +1,4 @@ |
| 1 |
-package com.munjaon.server.server.packet; |
|
| 1 |
+package com.munjaon.server.server.packet.common; |
|
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.util.CommonUtil; |
| 4 | 4 |
|
+++ src/main/java/com/munjaon/server/server/packet/deliver/DeliverBind.java
... | ... | @@ -0,0 +1,49 @@ |
| 1 | +package com.munjaon.server.server.packet.deliver; | |
| 2 | + | |
| 3 | +import com.munjaon.server.cache.dto.MemberDto; | |
| 4 | +import com.munjaon.server.server.queue.CollectUserQueue; | |
| 5 | + | |
| 6 | +public final class DeliverBind { | |
| 7 | + | |
| 8 | + public static String checkDuplicate(CollectUserQueue collectUserQueue, String serviceType, String id) { | |
| 9 | + if (collectUserQueue == null || serviceType == null || id == null) { | |
| 10 | + return "60"; | |
| 11 | + } | |
| 12 | + if (collectUserQueue.isExist(serviceType, id)) { | |
| 13 | + return "60"; | |
| 14 | + } | |
| 15 | + | |
| 16 | + return "00"; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public static String checkService(MemberDto memberDto, String serviceType, String id, String pwd) { | |
| 20 | + if (id == null || pwd == null) { | |
| 21 | + return "50"; | |
| 22 | + } | |
| 23 | + if (memberDto == null || !pwd.equals(memberDto.getAccessKey())) { | |
| 24 | + return "20"; | |
| 25 | + } | |
| 26 | + /* 회원 사용 상태 */ | |
| 27 | + if (memberDto.getMberSttus() == null || "N".equals(memberDto.getMberSttus())) { | |
| 28 | + return "30"; | |
| 29 | + } | |
| 30 | + /* 서비스 이용 상태 */ | |
| 31 | + if ("SMS".equals(serviceType) && "N".equals(memberDto.getSmsUseYn())) { | |
| 32 | + return "30"; | |
| 33 | + } | |
| 34 | + if ("LMS".equals(serviceType) && "N".equals(memberDto.getLmsUseYn())) { | |
| 35 | + return "30"; | |
| 36 | + } | |
| 37 | + if ("MMS".equals(serviceType) && "N".equals(memberDto.getMmsUseYn())) { | |
| 38 | + return "30"; | |
| 39 | + } | |
| 40 | + if ("KAT".equals(serviceType) && "N".equals(memberDto.getKakaoAtUseYn())) { | |
| 41 | + return "30"; | |
| 42 | + } | |
| 43 | + if ("KFT".equals(serviceType) && "N".equals(memberDto.getKakaoFtUseYn())) { | |
| 44 | + return "30"; | |
| 45 | + } | |
| 46 | + | |
| 47 | + return "00"; | |
| 48 | + } | |
| 49 | +} |
+++ src/main/java/com/munjaon/server/server/sample/SlackTest.java
... | ... | @@ -0,0 +1,32 @@ |
| 1 | +package com.munjaon.server.server.sample; | |
| 2 | + | |
| 3 | +import com.slack.api.Slack; | |
| 4 | +import com.slack.api.methods.MethodsClient; | |
| 5 | +import com.slack.api.methods.SlackApiException; | |
| 6 | +import com.slack.api.methods.request.chat.ChatPostMessageRequest; | |
| 7 | + | |
| 8 | +import java.io.IOException; | |
| 9 | + | |
| 10 | +public class SlackTest { | |
| 11 | + public static void main(final String[] args) { | |
| 12 | + String token = "xoxb-7591405602163-7594011803524-gKJQfJbhRSmOFr1XFcwujWDr"; | |
| 13 | + String channelAddress = "#프로젝트"; | |
| 14 | + String message = "test"; | |
| 15 | + try{ | |
| 16 | + | |
| 17 | + MethodsClient methods = Slack.getInstance().methods(token); | |
| 18 | + | |
| 19 | + ChatPostMessageRequest request = ChatPostMessageRequest.builder() | |
| 20 | + .channel(channelAddress) | |
| 21 | + .text(message) | |
| 22 | + .build(); | |
| 23 | + | |
| 24 | + methods.chatPostMessage(request); | |
| 25 | + | |
| 26 | +// log.info("Slack " + channel + " 에 메시지 보냄"); | |
| 27 | + } catch (SlackApiException | IOException e) { | |
| 28 | + e.printStackTrace(); | |
| 29 | +// log.error(e.getMessage()); | |
| 30 | + } | |
| 31 | + } | |
| 32 | +} |
--- src/main/java/com/munjaon/server/server/service/CollectBackServerService.java
+++ src/main/java/com/munjaon/server/server/service/CollectBackServerService.java
... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 |
import com.munjaon.server.queue.enums.QueueTypeWorker; |
| 8 | 8 |
import com.munjaon.server.server.dto.ConnectUserDto; |
| 9 | 9 |
import com.munjaon.server.server.dto.HeaderDto; |
| 10 |
-import com.munjaon.server.server.packet.*; |
|
| 10 |
+import com.munjaon.server.server.packet.common.*; |
|
| 11 | 11 |
import com.munjaon.server.util.LogUtil; |
| 12 | 12 |
import lombok.Getter; |
| 13 | 13 |
import org.json.simple.JSONObject; |
--- src/main/java/com/munjaon/server/server/service/CollectServer.java
+++ src/main/java/com/munjaon/server/server/service/CollectServer.java
... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 |
|
| 21 | 21 |
public class CollectServer extends Service {
|
| 22 | 22 |
private final InetSocketAddress listenAddress; |
| 23 |
- private CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 23 |
+ private final CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 24 | 24 |
|
| 25 | 25 |
private Selector selector; |
| 26 | 26 |
private final String serviceType; |
... | ... | @@ -58,8 +58,7 @@ |
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
private void initCollectChannel() throws IOException {
|
| 61 |
- saveSystemLog("COLLECT_SERVER_SERVICE : SERVER SOCKET INITIALIZING ... ...");
|
|
| 62 |
- saveSystemLog("COLLECT_SERVER_SERVICE : SERVER PORT [" + listenAddress.getPort() + "]");
|
|
| 61 |
+ saveSystemLog("COLLECT_SERVER_SERVICE INITIALIZING : SERVER PORT [" + listenAddress.getPort() + "]");
|
|
| 63 | 62 |
selector = Selector.open(); |
| 64 | 63 |
/* 채널 생성 */ |
| 65 | 64 |
ServerSocketChannel serverChannel = ServerSocketChannel.open(); |
... | ... | @@ -94,9 +93,11 @@ |
| 94 | 93 |
while (isRun()) {
|
| 95 | 94 |
try {
|
| 96 | 95 |
execInterest(); |
| 96 |
+ checkInterest(); |
|
| 97 | 97 |
execUserStatus(); |
| 98 | 98 |
} catch (Exception e) {
|
| 99 |
- throw new RuntimeException(e); |
|
| 99 |
+ saveSystemLog(e); |
|
| 100 |
+// throw new RuntimeException(e); |
|
| 100 | 101 |
} |
| 101 | 102 |
} |
| 102 | 103 |
saveSystemLog("COLLECT_SERVER_SERVICE : SERVER SERVICE STOPPED ... ...");
|
... | ... | @@ -122,7 +123,30 @@ |
| 122 | 123 |
continue; |
| 123 | 124 |
} |
| 124 | 125 |
/* 사용자별 Collect Thread 실행 */ |
| 125 |
- new CollectServerTask(selector, key, getName(), this.serviceType, logger).run(); |
|
| 126 |
+ new CollectServerTask(selector, key, getName(), this.serviceType, logger).start(); |
|
| 127 |
+ } |
|
| 128 |
+ } else {
|
|
| 129 |
+ expireConnectUser(key); |
|
| 130 |
+ } |
|
| 131 |
+ } |
|
| 132 |
+ } |
|
| 133 |
+ |
|
| 134 |
+ private void checkInterest() {
|
|
| 135 |
+ for (SelectionKey key : selector.keys()) {
|
|
| 136 |
+ if (key.isValid()) {
|
|
| 137 |
+ ConnectUserDto connectUserDto = (ConnectUserDto) key.attachment(); |
|
| 138 |
+ if (connectUserDto == null) {
|
|
| 139 |
+ continue; |
|
| 140 |
+ } |
|
| 141 |
+ if (connectUserDto.isAlive() == 1) { // 로그인이 완료되지 않은 경우
|
|
| 142 |
+ expireConnectUser(key); |
|
| 143 |
+ } else {
|
|
| 144 |
+ if (connectUserDto.isRunningMode()) {
|
|
| 145 |
+ continue; |
|
| 146 |
+ } |
|
| 147 |
+ connectUserDto.setRunningMode(true); |
|
| 148 |
+ /* 사용자별 Collect Thread 실행 */ |
|
| 149 |
+ new CollectServerTask(selector, key, getName(), this.serviceType, logger).start(); |
|
| 126 | 150 |
} |
| 127 | 151 |
} else {
|
| 128 | 152 |
expireConnectUser(key); |
... | ... | @@ -151,6 +175,7 @@ |
| 151 | 175 |
// Socket 채널을 channel에 수신 등록한다 |
| 152 | 176 |
channel.register(selector, SelectionKey.OP_READ, ConnectUserDto.builder().serviceType(this.serviceType).lastTrafficTime(System.currentTimeMillis()).remoteIP(inetAddress.getHostAddress()).build()); |
| 153 | 177 |
} catch (Exception e) {
|
| 178 |
+ saveSystemLog(e.toString()); |
|
| 154 | 179 |
throw new RuntimeException(e); |
| 155 | 180 |
} |
| 156 | 181 |
} |
... | ... | @@ -165,7 +190,6 @@ |
| 165 | 190 |
if (userDto != null && userDto.getUserId() != null) {
|
| 166 | 191 |
saveSystemLog("[CLIENT USER IS DISCONNECT : " + userDto.toString() + "]");
|
| 167 | 192 |
collectUserQueue.removeUser(this.serviceType, userDto.getUserId()); |
| 168 |
-// connectUserMap.remove(userDto.getUserId()); |
|
| 169 | 193 |
key.attach(null); |
| 170 | 194 |
} |
| 171 | 195 |
// 소켓 채널 닫기 |
... | ... | @@ -173,6 +197,7 @@ |
| 173 | 197 |
// 키 닫기 |
| 174 | 198 |
key.cancel(); |
| 175 | 199 |
} catch (IOException e) {
|
| 200 |
+ saveSystemLog(e.toString()); |
|
| 176 | 201 |
e.printStackTrace(); |
| 177 | 202 |
} |
| 178 | 203 |
} |
--- src/main/java/com/munjaon/server/server/service/QueueServerService.java
+++ src/main/java/com/munjaon/server/server/service/QueueServerService.java
... | ... | @@ -79,6 +79,7 @@ |
| 79 | 79 |
loadMemoryQueue(); |
| 80 | 80 |
} |
| 81 | 81 |
} catch (Exception e) {
|
| 82 |
+ saveSystemLog(e.toString()); |
|
| 82 | 83 |
throw new RuntimeException(e); |
| 83 | 84 |
} |
| 84 | 85 |
} |
--- src/main/java/com/munjaon/server/server/service/ReportQueueServerService.java
+++ src/main/java/com/munjaon/server/server/service/ReportQueueServerService.java
... | ... | @@ -16,13 +16,15 @@ |
| 16 | 16 |
public class ReportQueueServerService extends Service {
|
| 17 | 17 |
private final ReportUserQueue reportUserQueue = ReportUserQueue.getInstance(); |
| 18 | 18 |
private QueueThreadService threadService; |
| 19 |
- private int queueMaxCore; |
|
| 20 |
- private int maxWriteCount; |
|
| 19 |
+ private final int queueMaxCore; |
|
| 20 |
+ private final int maxWriteCount; |
|
| 21 |
+ private final int maxQueueCount; |
|
| 21 | 22 |
|
| 22 | 23 |
public ReportQueueServerService(String serviceName) {
|
| 23 | 24 |
super(serviceName); |
| 24 | 25 |
this.queueMaxCore = Integer.parseInt(getProp("QUEUE_MAX_CORE").trim());
|
| 25 | 26 |
this.maxWriteCount = Integer.parseInt(getProp("MAX_WRITE_COUNT").trim());
|
| 27 |
+ this.maxQueueCount = Integer.parseInt(getProp("MAX_QUEUE_COUNT").trim());
|
|
| 26 | 28 |
} |
| 27 | 29 |
|
| 28 | 30 |
@Override |
... | ... | @@ -32,16 +34,21 @@ |
| 32 | 34 |
|
| 33 | 35 |
@Override |
| 34 | 36 |
public void initResources() {
|
| 37 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : RESOURCES INITIALIZING ... ...");
|
|
| 35 | 38 |
threadService = new QueueThreadService(queueMaxCore, logger); |
| 39 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : RESOURCES INITIALIZED ... ...");
|
|
| 36 | 40 |
} |
| 37 | 41 |
|
| 38 | 42 |
@Override |
| 39 | 43 |
public void releaseResources() {
|
| 44 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : SERVER RESOURCE RELEASING ... ...");
|
|
| 40 | 45 |
threadService.close(); |
| 46 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : SERVER RESOURCE RELEASED ... ...");
|
|
| 41 | 47 |
} |
| 42 | 48 |
|
| 43 | 49 |
@Override |
| 44 | 50 |
public void doService() {
|
| 51 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : SERVER SERVICE STARTED ... ...");
|
|
| 45 | 52 |
while (isRun()) {
|
| 46 | 53 |
try {
|
| 47 | 54 |
doQueueService(); |
... | ... | @@ -50,16 +57,18 @@ |
| 50 | 57 |
throw new RuntimeException(e); |
| 51 | 58 |
} |
| 52 | 59 |
} |
| 60 |
+ saveSystemLog("REPORT_QUEUE_SERVICE : SERVER SERVICE STOPPED ... ...");
|
|
| 53 | 61 |
} |
| 54 | 62 |
|
| 55 | 63 |
private void doQueueService() {
|
| 56 | 64 |
List<ReportUserDto> reportUserList = reportUserQueue.getUsers(); |
| 57 |
- if (reportUserList == null || reportUserList.size() == 0) {
|
|
| 65 |
+ if (reportUserList == null || reportUserList.isEmpty()) {
|
|
| 58 | 66 |
return; |
| 59 | 67 |
} |
| 60 | 68 |
|
| 61 | 69 |
for (ReportUserDto reportUserDto : reportUserList) {
|
| 62 | 70 |
reportUserDto.setMaxWriteCount(this.maxWriteCount); |
| 71 |
+ reportUserDto.setMaxQueueCount(this.maxQueueCount); |
|
| 63 | 72 |
threadService.execute(new ReportQueueTask(reportUserDto, logger)); |
| 64 | 73 |
} |
| 65 | 74 |
} |
--- src/main/java/com/munjaon/server/server/service/ReportServer.java
+++ src/main/java/com/munjaon/server/server/service/ReportServer.java
... | ... | @@ -6,7 +6,6 @@ |
| 6 | 6 |
import com.munjaon.server.server.task.ReportServerTask; |
| 7 | 7 |
import org.json.simple.JSONObject; |
| 8 | 8 |
|
| 9 |
-import java.io.File; |
|
| 10 | 9 |
import java.io.IOException; |
| 11 | 10 |
import java.net.InetSocketAddress; |
| 12 | 11 |
import java.net.Socket; |
... | ... | @@ -38,7 +37,9 @@ |
| 38 | 37 |
@Override |
| 39 | 38 |
public void initResources() {
|
| 40 | 39 |
try {
|
| 40 |
+ saveSystemLog("REPORT_SERVER : RESOURCES INITIALIZING ... ...");
|
|
| 41 | 41 |
initReportChannel(); |
| 42 |
+ saveSystemLog("REPORT_SERVER : RESOURCES INITIALIZED ... ...");
|
|
| 42 | 43 |
} catch (IOException e) {
|
| 43 | 44 |
saveSystemLog(e); |
| 44 | 45 |
throw new RuntimeException(e); |
... | ... | @@ -46,6 +47,7 @@ |
| 46 | 47 |
} |
| 47 | 48 |
|
| 48 | 49 |
private void initReportChannel() throws IOException {
|
| 50 |
+ saveSystemLog("REPORT_SERVER INITIALIZING : SERVER PORT [" + listenAddress.getPort() + "]");
|
|
| 49 | 51 |
selector = Selector.open(); |
| 50 | 52 |
/* 채널 생성 */ |
| 51 | 53 |
ServerSocketChannel serverChannel = ServerSocketChannel.open(); |
... | ... | @@ -55,6 +57,7 @@ |
| 55 | 57 |
serverChannel.socket().bind(listenAddress); |
| 56 | 58 |
/* 채널에 accept 대기 설정 */ |
| 57 | 59 |
serverChannel.register(selector, SelectionKey.OP_ACCEPT); |
| 60 |
+ saveSystemLog("REPORT_SERVER : SERVER SOCKET INITIALIZED ... ...");
|
|
| 58 | 61 |
} |
| 59 | 62 |
|
| 60 | 63 |
private void closeReportChannel() throws IOException {
|
... | ... | @@ -63,17 +66,19 @@ |
| 63 | 66 |
|
| 64 | 67 |
@Override |
| 65 | 68 |
public void releaseResources() {
|
| 69 |
+ saveSystemLog("REPORT_SERVER : SERVER RESOURCE RELEASING ... ...");
|
|
| 66 | 70 |
try {
|
| 67 | 71 |
closeReportChannel(); |
| 68 | 72 |
} catch (IOException e) {
|
| 69 | 73 |
saveSystemLog(e); |
| 70 | 74 |
throw new RuntimeException(e); |
| 71 | 75 |
} |
| 76 |
+ saveSystemLog("REPORT_SERVER : SERVER RESOURCE RELEASED ... ...");
|
|
| 72 | 77 |
} |
| 73 | 78 |
|
| 74 | 79 |
@Override |
| 75 | 80 |
public void doService() {
|
| 76 |
- |
|
| 81 |
+ saveSystemLog("REPORT_SERVER : SERVER SERVICE STARTED ... ...");
|
|
| 77 | 82 |
while (isRun()) {
|
| 78 | 83 |
try {
|
| 79 | 84 |
execInterest(); |
... | ... | @@ -82,6 +87,7 @@ |
| 82 | 87 |
saveSystemLog(e.toString()); |
| 83 | 88 |
} |
| 84 | 89 |
} |
| 90 |
+ saveSystemLog("REPORT_SERVER : SERVER SERVICE STOPPED ... ...");
|
|
| 85 | 91 |
} |
| 86 | 92 |
|
| 87 | 93 |
private void checkInterest() throws IOException, InterruptedException {
|
... | ... | @@ -93,13 +99,13 @@ |
| 93 | 99 |
if (reportUserDto == null) {
|
| 94 | 100 |
continue; |
| 95 | 101 |
} |
| 96 |
- SocketChannel channel = (SocketChannel) key.channel(); // 키 채널을 가져온다. |
|
| 97 | 102 |
if (reportUserDto.isAlive() == 1) { // 로그인이 완료되지 않은 경우
|
| 98 | 103 |
expireConnectUser(key); |
| 99 | 104 |
} else if (reportUserDto.isAlive() == 2) {
|
| 100 |
- if (reportUserDto == null || reportUserDto.isRunningMode()) {
|
|
| 105 |
+ if (reportUserDto.isRunningMode()) {
|
|
| 101 | 106 |
continue; |
| 102 | 107 |
} |
| 108 |
+ reportUserDto.setRunningMode(true); |
|
| 103 | 109 |
/* 사용자별 Report Thread 실행 */ |
| 104 | 110 |
new ReportServerTask(selector, key, getName(), logger).run(); |
| 105 | 111 |
} else {
|
... | ... | @@ -108,8 +114,9 @@ |
| 108 | 114 |
if (reportUserDto.isRunningMode()) {
|
| 109 | 115 |
continue; |
| 110 | 116 |
} |
| 117 |
+ reportUserDto.setRunningMode(true); |
|
| 111 | 118 |
/* 사용자별 Report Thread 실행 */ |
| 112 |
- new ReportServerTask(selector, key, getName(), logger).run(); |
|
| 119 |
+ new ReportServerTask(selector, key, getName(), logger).start(); |
|
| 113 | 120 |
} |
| 114 | 121 |
} |
| 115 | 122 |
} else {
|
... | ... | @@ -138,14 +145,9 @@ |
| 138 | 145 |
if (reportUserDto == null || reportUserDto.isRunningMode()) {
|
| 139 | 146 |
continue; |
| 140 | 147 |
} |
| 141 |
- if (reportUserDto.isLogin()) {
|
|
| 142 |
- saveSystemLog("[REPORT SERVER READ] [ID : " + reportUserDto.getUserId() + "]");
|
|
| 143 |
- } else {
|
|
| 144 |
- saveSystemLog("[REPORT SERVER READ] [FIRST CONNECTION ... ... ... ... ... ... ...]");
|
|
| 145 |
- } |
|
| 146 | 148 |
reportUserDto.setRunningMode(true); |
| 147 | 149 |
/* 사용자별 Report Thread 실행 */ |
| 148 |
- new ReportServerTask(selector, key, getName(), logger).run(); |
|
| 150 |
+ new ReportServerTask(selector, key, getName(), logger).start(); |
|
| 149 | 151 |
} |
| 150 | 152 |
} else {
|
| 151 | 153 |
expireConnectUser(key); |
... | ... | @@ -165,8 +167,9 @@ |
| 165 | 167 |
SocketAddress remoteAddr = socket.getRemoteSocketAddress(); |
| 166 | 168 |
saveSystemLog("Connected to: " + remoteAddr);
|
| 167 | 169 |
// Socket 채널을 channel에 수신 등록한다 |
| 168 |
- channel.register(selector, SelectionKey.OP_READ, ReportUserDto.builder().lastTrafficTime(System.currentTimeMillis()).remoteIP(remoteAddr.toString()).queuePath(System.getProperty("ROOTPATH") + File.separator + getProp("QUEUE_PATH")).build());
|
|
| 170 |
+ channel.register(selector, SelectionKey.OP_READ, ReportUserDto.builder().lastTrafficTime(System.currentTimeMillis()).remoteIP(remoteAddr.toString()).queuePath(System.getProperty("ROOTPATH") + getProp("QUEUE_PATH")).build());
|
|
| 169 | 171 |
} catch (Exception e) {
|
| 172 |
+ saveSystemLog(e.toString()); |
|
| 170 | 173 |
throw new RuntimeException(e); |
| 171 | 174 |
} |
| 172 | 175 |
} |
... | ... | @@ -189,6 +192,7 @@ |
| 189 | 192 |
// 키 닫기 |
| 190 | 193 |
key.cancel(); |
| 191 | 194 |
} catch (IOException e) {
|
| 195 |
+ saveSystemLog(e.toString()); |
|
| 192 | 196 |
e.printStackTrace(); |
| 193 | 197 |
} |
| 194 | 198 |
} |
--- src/main/java/com/munjaon/server/server/service/ReportServerService.java
+++ src/main/java/com/munjaon/server/server/service/ReportServerService.java
... | ... | @@ -4,10 +4,10 @@ |
| 4 | 4 |
import com.munjaon.server.server.dto.ConnectUserDto; |
| 5 | 5 |
import com.munjaon.server.server.dto.ReportDto; |
| 6 | 6 |
import com.munjaon.server.server.dto.ReportUserDto; |
| 7 |
-import com.munjaon.server.server.packet.Header; |
|
| 8 |
-import com.munjaon.server.server.packet.LinkCheck; |
|
| 9 |
-import com.munjaon.server.server.packet.Packet; |
|
| 10 |
-import com.munjaon.server.server.packet.Report; |
|
| 7 |
+import com.munjaon.server.server.packet.common.Header; |
|
| 8 |
+import com.munjaon.server.server.packet.common.LinkCheck; |
|
| 9 |
+import com.munjaon.server.server.packet.common.Packet; |
|
| 10 |
+import com.munjaon.server.server.packet.common.Report; |
|
| 11 | 11 |
import com.munjaon.server.server.queue.ReportUserQueue; |
| 12 | 12 |
import com.munjaon.server.server.task.ReportReadTask; |
| 13 | 13 |
import com.munjaon.server.util.LogUtil; |
--- src/main/java/com/munjaon/server/server/service/Service.java
+++ src/main/java/com/munjaon/server/server/service/Service.java
... | ... | @@ -93,7 +93,6 @@ |
| 93 | 93 |
|
| 94 | 94 |
protected void initLogFile() {
|
| 95 | 95 |
LOG_FILE = System.getProperty("ROOTPATH") + getProp("LOG_FILE");
|
| 96 |
- System.out.println("LOG_FILE: " + LOG_FILE);
|
|
| 97 | 96 |
setLogFile( LOG_FILE ); |
| 98 | 97 |
saveSystemLog("Service Log Initializing ... ...");
|
| 99 | 98 |
} |
--- src/main/java/com/munjaon/server/server/task/CollectReadTask.java
+++ src/main/java/com/munjaon/server/server/task/CollectReadTask.java
... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 7 | 7 |
import com.munjaon.server.queue.enums.QueueTypeWorker; |
| 8 | 8 |
import com.munjaon.server.server.dto.ConnectUserDto; |
| 9 |
-import com.munjaon.server.server.packet.*; |
|
| 9 |
+import com.munjaon.server.server.packet.common.*; |
|
| 10 | 10 |
import com.munjaon.server.server.queue.CollectUserQueue; |
| 11 | 11 |
import com.munjaon.server.util.*; |
| 12 | 12 |
|
--- src/main/java/com/munjaon/server/server/task/CollectServerTask.java
+++ src/main/java/com/munjaon/server/server/task/CollectServerTask.java
... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 |
import com.munjaon.server.queue.enums.QueueTypeWorker; |
| 8 | 8 |
import com.munjaon.server.server.config.ServerConfig; |
| 9 | 9 |
import com.munjaon.server.server.dto.ConnectUserDto; |
| 10 |
-import com.munjaon.server.server.packet.*; |
|
| 10 |
+import com.munjaon.server.server.packet.common.*; |
|
| 11 | 11 |
import com.munjaon.server.server.queue.CollectUserQueue; |
| 12 | 12 |
import com.munjaon.server.server.service.PropertyLoader; |
| 13 | 13 |
import com.munjaon.server.util.*; |
... | ... | @@ -22,25 +22,27 @@ |
| 22 | 22 |
import java.time.LocalDateTime; |
| 23 | 23 |
import java.time.format.DateTimeFormatter; |
| 24 | 24 |
|
| 25 |
-public class CollectServerTask implements Runnable {
|
|
| 25 |
+public class CollectServerTask extends Thread {
|
|
| 26 | 26 |
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
| 27 | 27 |
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]"; |
| 28 | 28 |
|
| 29 | 29 |
private Selector selector; |
| 30 |
- private SelectionKey key; |
|
| 31 |
- private SocketChannel channel; |
|
| 32 |
- private CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 33 |
- private ConnectUserDto connectUserDto; |
|
| 34 |
- private String serviceName; |
|
| 35 |
- private String serviceType; |
|
| 30 |
+ private final SelectionKey key; |
|
| 31 |
+ private final SocketChannel channel; |
|
| 32 |
+ private final CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 33 |
+ private final ConnectUserDto connectUserDto; |
|
| 34 |
+ private final String serviceName; |
|
| 35 |
+ private final String serviceType; |
|
| 36 | 36 |
private final LogUtil logger; |
| 37 | 37 |
|
| 38 | 38 |
private boolean IS_SERVER_RUN; // 서버가 구동중인지 여부 |
| 39 | 39 |
private boolean IS_RUN_YN; |
| 40 | 40 |
private long RUN_FLAG_CHECK_TIME; |
| 41 |
+ private long LAST_PACKET_SEND_TIME = System.currentTimeMillis(); // 패킷 송수신 시간을 체크하기 위한 변수(최대 3초간 요청이 없는 경우 Thread 종료) |
|
| 42 |
+ private boolean IS_ERROR = false; |
|
| 41 | 43 |
|
| 42 | 44 |
/* 클라이언트 요청 데이터 수신 */ |
| 43 |
- private ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH); |
|
| 45 |
+ private final ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH); |
|
| 44 | 46 |
/* 세션이 만료되었는지 체크 */ |
| 45 | 47 |
private boolean isExpiredYn; |
| 46 | 48 |
|
... | ... | @@ -53,6 +55,11 @@ |
| 53 | 55 |
this.serviceName = serviceName; |
| 54 | 56 |
this.serviceType = serviceType; |
| 55 | 57 |
this.logger = logger; |
| 58 |
+ if (connectUserDto.isLogin()) {
|
|
| 59 |
+ saveSystemLog("[COLLECT SERVER READ] [ID : " + connectUserDto.getUserId() + "]");
|
|
| 60 |
+ } else {
|
|
| 61 |
+ saveSystemLog("[COLLECT SERVER READ] [FIRST CONNECTION ... ... ... ... ... ... ...]");
|
|
| 62 |
+ } |
|
| 56 | 63 |
} |
| 57 | 64 |
|
| 58 | 65 |
protected String getProp(String name) {
|
... | ... | @@ -121,6 +128,13 @@ |
| 121 | 128 |
break; |
| 122 | 129 |
} |
| 123 | 130 |
try {
|
| 131 |
+ /* 2. Packet Timeout Check */ |
|
| 132 |
+ if (checkTimeOut()) {
|
|
| 133 |
+ saveSystemLog(printTaskLog() + "[checkTimeOut : Expired ... ... ... ... ... ... ...]"); |
|
| 134 |
+ saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]"); |
|
| 135 |
+ expireConnectUser(); |
|
| 136 |
+ break; |
|
| 137 |
+ } |
|
| 124 | 138 |
/* 3. HeadBuffer 읽기 */ |
| 125 | 139 |
int size = readHeader(); |
| 126 | 140 |
/* 4. Body 읽기 */ |
... | ... | @@ -133,7 +147,7 @@ |
| 133 | 147 |
default: expireConnectUser(); break; |
| 134 | 148 |
} |
| 135 | 149 |
} else if (size == 0) {
|
| 136 |
- if (System.currentTimeMillis() - connectUserDto.getLastTrafficTime() > ServerConfig.DELIVER_EXEC_CYCLE_TIME) {
|
|
| 150 |
+ if (System.currentTimeMillis() - LAST_PACKET_SEND_TIME > ServerConfig.DELIVER_EXEC_CYCLE_TIME) {
|
|
| 137 | 151 |
this.isExpiredYn = true; |
| 138 | 152 |
} |
| 139 | 153 |
Thread.sleep(1); |
... | ... | @@ -143,14 +157,27 @@ |
| 143 | 157 |
} catch (Exception e) {
|
| 144 | 158 |
/* 세션 만료 여부 */ |
| 145 | 159 |
this.isExpiredYn = true; |
| 146 |
- e.printStackTrace(); |
|
| 160 |
+ this.IS_ERROR = true; |
|
| 161 |
+ saveSystemLog(e); |
|
| 147 | 162 |
} |
| 148 | 163 |
/* RUN Flag 체크 */ |
| 149 | 164 |
reloadRunFlag(); |
| 150 | 165 |
} |
| 151 | 166 |
/* 중요 : 사용자 Thread 실행모드 Off */ |
| 152 | 167 |
connectUserDto.setRunningMode(false); |
| 168 |
+ /* 에러가 발생한 경우 세션을 종료힌다. */ |
|
| 169 |
+ if (IS_ERROR) {
|
|
| 170 |
+ expireConnectUser(); |
|
| 171 |
+ } |
|
| 153 | 172 |
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]"); |
| 173 |
+ } |
|
| 174 |
+ |
|
| 175 |
+ private boolean checkTimeOut() {
|
|
| 176 |
+ if (System.currentTimeMillis() - this.connectUserDto.getLastTrafficTime() >= Packet.LIMIT_PACKET_TIMEOUT) {
|
|
| 177 |
+ return true; |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ return false; |
|
| 154 | 181 |
} |
| 155 | 182 |
|
| 156 | 183 |
private void recvDeliver(SocketChannel channel, ByteBuffer headBuffer) throws IOException {
|
... | ... | @@ -168,6 +195,8 @@ |
| 168 | 195 |
case "KFT": recvKftDeliver(channel, headBuffer); break; |
| 169 | 196 |
default:break; |
| 170 | 197 |
} |
| 198 |
+ /* 마지막 패킷 수신시간 체크 */ |
|
| 199 |
+ LAST_PACKET_SEND_TIME = System.currentTimeMillis(); |
|
| 171 | 200 |
} |
| 172 | 201 |
|
| 173 | 202 |
private boolean isExpireService() {
|
... | ... | @@ -468,16 +497,17 @@ |
| 468 | 497 |
} |
| 469 | 498 |
|
| 470 | 499 |
private void recvLinkCheck(SocketChannel channel) throws IOException {
|
| 471 |
- ByteBuffer bodyBuffer = ByteBuffer.allocate(LinkCheck.LINK_CHECK_ACK_BODY_LENGTH); |
|
| 472 |
- channel.read(bodyBuffer); |
|
| 473 |
-// SocketChannel channel = (SocketChannel) key.channel(); |
|
| 474 |
- channel.write(LinkCheck.makeLinkCheckAckBuffer()); |
|
| 475 |
- connectUserDto.updateLastTrafficTime(); |
|
| 476 | 500 |
/* 서비스 중지여부 체크 */ |
| 477 | 501 |
if (isExpireService()) {
|
| 478 | 502 |
expireConnectUser(); |
| 479 | 503 |
return; |
| 480 | 504 |
} |
| 505 |
+ ByteBuffer bodyBuffer = ByteBuffer.allocate(LinkCheck.LINK_CHECK_ACK_BODY_LENGTH); |
|
| 506 |
+ channel.read(bodyBuffer); |
|
| 507 |
+ saveSystemLog(printTaskLog() + "[COLLECTOR LINK CHECK RECEIVE ... ... ... ... ... ... ...]"); |
|
| 508 |
+ channel.write(LinkCheck.makeLinkCheckAckBuffer()); |
|
| 509 |
+ saveSystemLog(printTaskLog() + "[COLLECTOR LINK CHECK ACK SEND ... ... ... ... ... ... ...]"); |
|
| 510 |
+ connectUserDto.updateLastTrafficTime(); |
|
| 481 | 511 |
} |
| 482 | 512 |
|
| 483 | 513 |
private void recvBind(SocketChannel channel, ByteBuffer headBuffer) {
|
... | ... | @@ -490,13 +520,14 @@ |
| 490 | 520 |
|
| 491 | 521 |
String id = Bind.getBindId(bindBuffer); |
| 492 | 522 |
String pwd = Bind.getBindPwd(bindBuffer); |
| 523 |
+ saveSystemLog(printTaskLog() + "[BIND REQUEST] [ID : " + id + ", PWD : " + pwd + "]"); |
|
| 493 | 524 |
|
| 494 | 525 |
MemberService svc = (MemberService) CacheService.LOGIN_SERVICE.getService(); |
| 495 | 526 |
MemberDto memberDto = null; |
| 496 | 527 |
if (svc != null) {
|
| 497 | 528 |
memberDto = svc.get(id); |
| 498 | 529 |
} |
| 499 |
- saveSystemLog(printTaskLog() + "[BIND REQUEST] [ID : " + id + ", PWD : " + pwd + "]"); |
|
| 530 |
+ |
|
| 500 | 531 |
/* Bind Check */ |
| 501 | 532 |
resultCode = checkBind(memberDto, this.serviceType, id, pwd); |
| 502 | 533 |
|
--- src/main/java/com/munjaon/server/server/task/ReportQueueTask.java
+++ src/main/java/com/munjaon/server/server/task/ReportQueueTask.java
... | ... | @@ -18,7 +18,7 @@ |
| 18 | 18 |
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
| 19 | 19 |
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]"; |
| 20 | 20 |
|
| 21 |
- private ReportUserDto reportUserDto; |
|
| 21 |
+ private final ReportUserDto reportUserDto; |
|
| 22 | 22 |
private final LogUtil logger; |
| 23 | 23 |
|
| 24 | 24 |
public ReportQueueTask(ReportUserDto reportUserDto, LogUtil logger) {
|
... | ... | @@ -37,15 +37,15 @@ |
| 37 | 37 |
|
| 38 | 38 |
ReportQueue reportQueue = reportUserDto.getReportQueue(); |
| 39 | 39 |
/* 리포트큐에 최대 크기까지 쓰고 모두 리포트는 전송했는지 체크 : 테스트후 적용 */ |
| 40 |
-// if (reportQueue.isWriteLimit(reportUserDto.getMaxWriteCount())) {
|
|
| 41 |
-// if (reportQueue.isTruncateQueue(reportUserDto.getMaxWriteCount())) {
|
|
| 42 |
-// try {
|
|
| 43 |
-// reportQueue.truncateQueue(); |
|
| 44 |
-// } catch (Exception e) {}
|
|
| 45 |
-// } else {
|
|
| 46 |
-// return; |
|
| 47 |
-// } |
|
| 48 |
-// } |
|
| 40 |
+ if (reportQueue.isWriteLimit(reportUserDto.getMaxQueueCount())) {
|
|
| 41 |
+ if (reportQueue.isTruncateQueue(reportUserDto.getMaxQueueCount())) {
|
|
| 42 |
+ try {
|
|
| 43 |
+ reportQueue.truncateQueue(); |
|
| 44 |
+ } catch (Exception ignored) {}
|
|
| 45 |
+ } else {
|
|
| 46 |
+ return; |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 49 | 49 |
ReportService reportService = (ReportService) CacheService.REPORT_SERVICE.getService(); |
| 50 | 50 |
List<ReportDto> list = reportService.getReportListForUser(reportUserDto.getUserId()); |
| 51 | 51 |
if (list == null || list.isEmpty()) {
|
--- src/main/java/com/munjaon/server/server/task/ReportReadTask.java
+++ src/main/java/com/munjaon/server/server/task/ReportReadTask.java
... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 |
import com.munjaon.server.cache.service.MemberService; |
| 6 | 6 |
import com.munjaon.server.queue.pool.ReportQueue; |
| 7 | 7 |
import com.munjaon.server.server.dto.ReportUserDto; |
| 8 |
-import com.munjaon.server.server.packet.*; |
|
| 8 |
+import com.munjaon.server.server.packet.common.*; |
|
| 9 | 9 |
import com.munjaon.server.server.queue.ReportUserQueue; |
| 10 | 10 |
import com.munjaon.server.util.LogUtil; |
| 11 | 11 |
|
--- src/main/java/com/munjaon/server/server/task/ReportServerTask.java
+++ src/main/java/com/munjaon/server/server/task/ReportServerTask.java
... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 |
import com.munjaon.server.server.config.ServerConfig; |
| 8 | 8 |
import com.munjaon.server.server.dto.ReportDto; |
| 9 | 9 |
import com.munjaon.server.server.dto.ReportUserDto; |
| 10 |
-import com.munjaon.server.server.packet.*; |
|
| 10 |
+import com.munjaon.server.server.packet.common.*; |
|
| 11 | 11 |
import com.munjaon.server.server.queue.ReportUserQueue; |
| 12 | 12 |
import com.munjaon.server.server.service.PropertyLoader; |
| 13 | 13 |
import com.munjaon.server.util.LogUtil; |
... | ... | @@ -21,28 +21,29 @@ |
| 21 | 21 |
import java.time.LocalDateTime; |
| 22 | 22 |
import java.time.format.DateTimeFormatter; |
| 23 | 23 |
|
| 24 |
-public class ReportServerTask implements Runnable {
|
|
| 24 |
+public class ReportServerTask extends Thread {
|
|
| 25 | 25 |
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
| 26 | 26 |
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]"; |
| 27 | 27 |
|
| 28 | 28 |
private Selector selector; |
| 29 |
- private SelectionKey key; |
|
| 30 |
- private SocketChannel channel; |
|
| 29 |
+ private final SelectionKey key; |
|
| 30 |
+ private final SocketChannel channel; |
|
| 31 | 31 |
private final ReportUserQueue reportUserQueue = ReportUserQueue.getInstance(); |
| 32 |
- private ReportUserDto reportUserDto; |
|
| 33 |
- private ReportQueue reportQueue; |
|
| 34 |
- private String serviceName; |
|
| 32 |
+ private final ReportUserDto reportUserDto; |
|
| 33 |
+ private final ReportQueue reportQueue; |
|
| 34 |
+ private final String serviceName; |
|
| 35 | 35 |
private final LogUtil logger; |
| 36 | 36 |
|
| 37 | 37 |
private boolean IS_SERVER_RUN; // 서버가 구동중인지 여부 |
| 38 | 38 |
private boolean IS_RUN_YN; |
| 39 | 39 |
private long RUN_FLAG_CHECK_TIME; |
| 40 | 40 |
private long SEND_CYCLE_CHECK_TIME; |
| 41 |
+ private boolean IS_ERROR = false; |
|
| 41 | 42 |
|
| 42 | 43 |
/* 세션이 만료되었는지 체크 */ |
| 43 | 44 |
private boolean isExpiredYn; |
| 44 | 45 |
/* 클라이언트 요청 데이터 수신 */ |
| 45 |
- private ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH); |
|
| 46 |
+ private final ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH); |
|
| 46 | 47 |
private ReportDto reportDto; // 전송 리포트 |
| 47 | 48 |
/* Packet을 전송했는지 여부 */ |
| 48 | 49 |
private boolean isPacketSendYn; |
... | ... | @@ -56,6 +57,11 @@ |
| 56 | 57 |
this.serviceName = serviceName; |
| 57 | 58 |
this.reportQueue = reportUserDto.getReportQueue(); |
| 58 | 59 |
this.logger = logger; |
| 60 |
+ if (reportUserDto.isLogin()) {
|
|
| 61 |
+ saveSystemLog("[REPORT SERVER READ] [ID : " + reportUserDto.getUserId() + "]");
|
|
| 62 |
+ } else {
|
|
| 63 |
+ saveSystemLog("[REPORT SERVER READ] [FIRST CONNECTION ... ... ... ... ... ... ...]");
|
|
| 64 |
+ } |
|
| 59 | 65 |
} |
| 60 | 66 |
|
| 61 | 67 |
protected String getProp(String name) {
|
... | ... | @@ -105,25 +111,40 @@ |
| 105 | 111 |
if (isExpiredYn) {
|
| 106 | 112 |
break; |
| 107 | 113 |
} |
| 108 |
-// saveSystemLog("ReportServerTask is Running");
|
|
| 109 |
- try {
|
|
| 110 |
- sendInterest(); |
|
| 111 |
- recvInterest(); |
|
| 112 |
- /* RUN Flag 체크 */ |
|
| 113 |
- reloadRunFlag(); |
|
| 114 |
- } catch (Exception e) {
|
|
| 115 |
- this.isExpiredYn = true; |
|
| 116 |
- e.printStackTrace(); |
|
| 114 |
+ /* 2. Packet Timeout Check */ |
|
| 115 |
+ if (checkTimeOut()) {
|
|
| 116 |
+ saveSystemLog(printTaskLog() + "[checkTimeOut : Expired ... ... ... ... ... ... ...]"); |
|
| 117 |
+ saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]"); |
|
| 118 |
+ expireConnectUser(); |
|
| 119 |
+ break; |
|
| 117 | 120 |
} |
| 121 |
+ |
|
| 122 |
+ sendInterest(); |
|
| 123 |
+ recvInterest(); |
|
| 124 |
+ /* RUN Flag 체크 */ |
|
| 125 |
+ reloadRunFlag(); |
|
| 118 | 126 |
} |
| 119 | 127 |
} catch (Exception e) {
|
| 120 | 128 |
/* 세션 만료 여부 */ |
| 121 | 129 |
this.isExpiredYn = true; |
| 122 |
- e.printStackTrace(); |
|
| 130 |
+ this.IS_ERROR = true; |
|
| 131 |
+ saveSystemLog(e); |
|
| 123 | 132 |
} |
| 124 | 133 |
/* 중요 : 사용자 Thread 실행모드 Off */ |
| 125 | 134 |
reportUserDto.setRunningMode(false); |
| 135 |
+ /* 에러가 발생한 경우 세션을 종료힌다. */ |
|
| 136 |
+ if (IS_ERROR) {
|
|
| 137 |
+ expireConnectUser(); |
|
| 138 |
+ } |
|
| 126 | 139 |
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]"); |
| 140 |
+ } |
|
| 141 |
+ |
|
| 142 |
+ private boolean checkTimeOut() {
|
|
| 143 |
+ if (System.currentTimeMillis() - this.reportUserDto.getLastTrafficTime() >= Packet.LIMIT_PACKET_TIMEOUT) {
|
|
| 144 |
+ return true; |
|
| 145 |
+ } |
|
| 146 |
+ |
|
| 147 |
+ return false; |
|
| 127 | 148 |
} |
| 128 | 149 |
|
| 129 | 150 |
private void initHeaderBuffer() {
|
... | ... | @@ -146,8 +167,7 @@ |
| 146 | 167 |
return size; |
| 147 | 168 |
} |
| 148 | 169 |
|
| 149 |
- private void bindInterest() throws IOException {
|
|
| 150 |
-// if (reportUserDto.isLogin() && !isRun()) {
|
|
| 170 |
+ private void bindInterest() {
|
|
| 151 | 171 |
if (reportUserDto.isLogin()) {
|
| 152 | 172 |
return; |
| 153 | 173 |
} |
... | ... | @@ -158,9 +178,10 @@ |
| 158 | 178 |
/* 2. Body 읽기 */ |
| 159 | 179 |
if (size > 0) {
|
| 160 | 180 |
String command = Header.getCommand(this.headBuffer); |
| 161 |
- switch (Integer.parseInt(command)) {
|
|
| 162 |
- case 1 : recvBind(channel, headBuffer); break; |
|
| 163 |
- default: expireConnectUser(); break; |
|
| 181 |
+ if (Integer.parseInt(command) == 1) {
|
|
| 182 |
+ recvBind(channel, headBuffer); |
|
| 183 |
+ } else {
|
|
| 184 |
+ expireConnectUser(); |
|
| 164 | 185 |
} |
| 165 | 186 |
/* 패킷 수신한 경우 무조건 루프를 빠져나간다 */ |
| 166 | 187 |
break; |
... | ... | @@ -230,17 +251,17 @@ |
| 230 | 251 |
} |
| 231 | 252 |
} catch (Exception e) {
|
| 232 | 253 |
resultCode = "10"; |
| 233 |
- e.printStackTrace(); |
|
| 254 |
+ saveSystemLog(e); |
|
| 234 | 255 |
} |
| 235 | 256 |
|
| 236 | 257 |
try {
|
| 237 | 258 |
saveSystemLog(printTaskLog() + "[BIND RESULT : " + resultCode + "]"); |
| 238 | 259 |
channel.write(Bind.makeBindAckBuffer(resultCode)); |
| 239 |
- if ("00".equals(resultCode) == false) {
|
|
| 260 |
+ if (!"00".equals(resultCode)) {
|
|
| 240 | 261 |
expireConnectUser(); |
| 241 | 262 |
} |
| 242 | 263 |
} catch (IOException e) {
|
| 243 |
- e.printStackTrace(); |
|
| 264 |
+ saveSystemLog(e); |
|
| 244 | 265 |
} |
| 245 | 266 |
} |
| 246 | 267 |
|
... | ... | @@ -262,7 +283,7 @@ |
| 262 | 283 |
return "00"; |
| 263 | 284 |
} |
| 264 | 285 |
|
| 265 |
- private void recvInterest() throws IOException, InterruptedException, Exception {
|
|
| 286 |
+ private void recvInterest() throws IOException, Exception {
|
|
| 266 | 287 |
while (isPacketSendYn) {
|
| 267 | 288 |
/* 1. Head 읽기 */ |
| 268 | 289 |
ByteBuffer headBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH); |
... | ... | @@ -270,8 +291,8 @@ |
| 270 | 291 |
if (size > 0) {
|
| 271 | 292 |
String command = Header.getCommand(headBuffer); |
| 272 | 293 |
switch (Integer.parseInt(command)) {
|
| 273 |
- case 6 : recvReport(channel, headBuffer); break; |
|
| 274 |
- case 8 : recvLinkCheck(channel, headBuffer); break; |
|
| 294 |
+ case 6 : recvReport(channel); break; |
|
| 295 |
+ case 8 : recvLinkCheck(channel); break; |
|
| 275 | 296 |
default: saveSystemLog(printTaskLog() + "[INVALID REQUEST][command : " + command + ";"); |
| 276 | 297 |
expireConnectUser(); break; |
| 277 | 298 |
} |
... | ... | @@ -289,7 +310,7 @@ |
| 289 | 310 |
} |
| 290 | 311 |
} |
| 291 | 312 |
|
| 292 |
- private void recvLinkCheck(SocketChannel channel, ByteBuffer headBuffer) throws IOException {
|
|
| 313 |
+ private void recvLinkCheck(SocketChannel channel) throws IOException {
|
|
| 293 | 314 |
ByteBuffer bodyBuffer = ByteBuffer.allocate(LinkCheck.LINK_CHECK_ACK_BODY_LENGTH); |
| 294 | 315 |
int size = channel.read(bodyBuffer); |
| 295 | 316 |
if (size > 0) {
|
... | ... | @@ -299,7 +320,7 @@ |
| 299 | 320 |
} |
| 300 | 321 |
} |
| 301 | 322 |
|
| 302 |
- private void recvReport(SocketChannel channel, ByteBuffer headBuffer) throws Exception {
|
|
| 323 |
+ private void recvReport(SocketChannel channel) throws Exception {
|
|
| 303 | 324 |
ByteBuffer bodyBuffer = ByteBuffer.allocate(Report.REPORT_ACK_BODY_LENGTH); |
| 304 | 325 |
int size = channel.read(bodyBuffer); |
| 305 | 326 |
if (size != Report.REPORT_ACK_BODY_LENGTH) {
|
... | ... | @@ -316,34 +337,30 @@ |
| 316 | 337 |
} |
| 317 | 338 |
} |
| 318 | 339 |
|
| 319 |
- private void sendInterest() throws IOException {
|
|
| 320 |
- if (reportUserDto.isLogin() == false) {
|
|
| 340 |
+ private void sendInterest() throws Exception {
|
|
| 341 |
+ if (!reportUserDto.isLogin()) {
|
|
| 321 | 342 |
return; |
| 322 | 343 |
} |
| 323 | 344 |
if (reportUserDto.isAlive() == 2) {
|
| 324 | 345 |
channel.write(LinkCheck.makeLinkCheckBuffer()); |
| 325 | 346 |
SEND_CYCLE_CHECK_TIME = System.currentTimeMillis(); |
| 326 |
- /* Packet을 전송했는지 여부 */ |
|
| 347 |
+ /* Packet 전송했는지 여부 */ |
|
| 327 | 348 |
isPacketSendYn = true; |
| 328 | 349 |
} else {
|
| 329 | 350 |
if (this.reportQueue != null && this.reportQueue.isRemainReport()) {
|
| 330 |
- try {
|
|
| 331 |
- this.reportDto = this.reportQueue.popReportFromQueue(); |
|
| 332 |
- if (reportDto == null) {
|
|
| 333 |
- return; |
|
| 334 |
- } |
|
| 335 |
- saveSystemLog(printTaskLog() + "[REPORT SEND : " + reportDto.toString() + "]"); |
|
| 336 |
- ByteBuffer reportBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Report.REPORT_BODY_LENGTH); |
|
| 337 |
- Packet.setDefaultByte(reportBuffer); |
|
| 338 |
- Header.putHeader(reportBuffer, Header.COMMAND_REPORT, Report.REPORT_BODY_LENGTH); |
|
| 339 |
- Report.putReport(reportBuffer, reportDto); |
|
| 340 |
- channel.write(reportBuffer); |
|
| 341 |
- /* Packet을 전송했는지 여부 */ |
|
| 342 |
- SEND_CYCLE_CHECK_TIME = System.currentTimeMillis(); |
|
| 343 |
- isPacketSendYn = true; |
|
| 344 |
- } catch (Exception e) {
|
|
| 345 |
- e.printStackTrace(); |
|
| 351 |
+ this.reportDto = this.reportQueue.popReportFromQueue(); |
|
| 352 |
+ if (reportDto == null) {
|
|
| 353 |
+ return; |
|
| 346 | 354 |
} |
| 355 |
+ saveSystemLog(printTaskLog() + "[REPORT SEND : " + reportDto.toString() + "]"); |
|
| 356 |
+ ByteBuffer reportBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Report.REPORT_BODY_LENGTH); |
|
| 357 |
+ Packet.setDefaultByte(reportBuffer); |
|
| 358 |
+ Header.putHeader(reportBuffer, Header.COMMAND_REPORT, Report.REPORT_BODY_LENGTH); |
|
| 359 |
+ Report.putReport(reportBuffer, reportDto); |
|
| 360 |
+ channel.write(reportBuffer); |
|
| 361 |
+ /* Packet 전송했는지 여부 */ |
|
| 362 |
+ SEND_CYCLE_CHECK_TIME = System.currentTimeMillis(); |
|
| 363 |
+ isPacketSendYn = true; |
|
| 347 | 364 |
} |
| 348 | 365 |
} |
| 349 | 366 |
/* 쓰레드 완료 시점 체크 */ |
... | ... | @@ -372,7 +389,7 @@ |
| 372 | 389 |
// 키 닫기 |
| 373 | 390 |
key.cancel(); |
| 374 | 391 |
} catch (IOException e) {
|
| 375 |
- e.printStackTrace(); |
|
| 392 |
+ saveSystemLog(e); |
|
| 376 | 393 |
} |
| 377 | 394 |
} |
| 378 | 395 |
|
--- src/main/java/com/munjaon/server/server/task/SendReadTask.java
+++ src/main/java/com/munjaon/server/server/task/SendReadTask.java
... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 7 | 7 |
import com.munjaon.server.queue.enums.QueueTypeWorker; |
| 8 | 8 |
import com.munjaon.server.server.dto.ConnectUserDto; |
| 9 |
-import com.munjaon.server.server.packet.*; |
|
| 9 |
+import com.munjaon.server.server.packet.common.*; |
|
| 10 | 10 |
import com.munjaon.server.server.queue.CollectUserQueue; |
| 11 | 11 |
import com.munjaon.server.util.*; |
| 12 | 12 |
|
--- src/main/java/com/munjaon/server/server/task/StatusCheckTask.java
+++ src/main/java/com/munjaon/server/server/task/StatusCheckTask.java
... | ... | @@ -16,8 +16,8 @@ |
| 16 | 16 |
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
| 17 | 17 |
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]"; |
| 18 | 18 |
|
| 19 |
- private CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 20 |
- private String serviceType; |
|
| 19 |
+ private final CollectUserQueue collectUserQueue = CollectUserQueue.getInstance(); |
|
| 20 |
+ private final String serviceType; |
|
| 21 | 21 |
private final LogUtil logger; |
| 22 | 22 |
|
| 23 | 23 |
public StatusCheckTask(String serviceType, LogUtil logger) {
|
... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 |
public void run() {
|
| 30 | 30 |
saveSystemLog("[" + this.serviceType + "][USER STATUS CHECK is starting ... ...]");
|
| 31 | 31 |
List<ConnectUserDto> userList = collectUserQueue.getUsers(this.serviceType); |
| 32 |
- if (userList == null && userList.isEmpty()) {
|
|
| 32 |
+ if (userList == null || userList.isEmpty()) {
|
|
| 33 | 33 |
saveSystemLog("[" + this.serviceType + "][USER STATUS CHECK is empty ... ...]");
|
| 34 | 34 |
saveSystemLog("[" + this.serviceType + "][USER STATUS CHECK is ended ... ...]");
|
| 35 | 35 |
return; |
... | ... | @@ -39,9 +39,6 @@ |
| 39 | 39 |
for (ConnectUserDto user : userList) {
|
| 40 | 40 |
MemberDto savedMemberDto = user.getMemberDto(); |
| 41 | 41 |
saveSystemLog("[" + this.serviceType + "][USER PREVIOUS STATUS : " + savedMemberDto.toString() + "]");
|
| 42 |
- if (savedMemberDto == null) {
|
|
| 43 |
- continue; |
|
| 44 |
- } |
|
| 45 | 42 |
MemberDto newMemberDto = svc.get(savedMemberDto.getMberId()); |
| 46 | 43 |
saveSystemLog("[" + this.serviceType + "][USER NEW STATUS : " + newMemberDto.toString() + "]");
|
| 47 | 44 |
if (newMemberDto == null) {
|
--- src/main/java/com/munjaon/server/util/MessageUtil.java
+++ src/main/java/com/munjaon/server/util/MessageUtil.java
... | ... | @@ -477,27 +477,27 @@ |
| 477 | 477 |
buffer.position(ReportConfig.MSG_ID_POSITION); |
| 478 | 478 |
destArray = new byte[ReportConfig.MSG_ID_LENGTH]; |
| 479 | 479 |
buffer.get(destArray); |
| 480 |
- reportDto.setMsgId(new String(destArray).trim()); |
|
| 480 |
+ reportDto.setMsgId(QueueConstants.getString(destArray)); |
|
| 481 | 481 |
/* AGENT_CODE (Length : 2 / Position : 20) */ |
| 482 | 482 |
buffer.position(ReportConfig.AGENT_CODE_POSITION); |
| 483 | 483 |
destArray = new byte[ReportConfig.AGENT_CODE_LENGTH]; |
| 484 | 484 |
buffer.get(destArray); |
| 485 |
- reportDto.setAgentCode(new String(destArray).trim()); |
|
| 485 |
+ reportDto.setAgentCode(QueueConstants.getString(destArray)); |
|
| 486 | 486 |
/* SEND_TIME (Length : 14 / Position : 22) */ |
| 487 | 487 |
buffer.position(ReportConfig.SEND_TIME_POSITION); |
| 488 | 488 |
destArray = new byte[ReportConfig.SEND_TIME_LENGTH]; |
| 489 | 489 |
buffer.get(destArray); |
| 490 |
- reportDto.setRsltDate(new String(destArray).trim()); |
|
| 490 |
+ reportDto.setRsltDate(QueueConstants.getString(destArray)); |
|
| 491 | 491 |
/* TELECOM (Length : 3 / Position : 36) */ |
| 492 | 492 |
buffer.position(ReportConfig.TELECOM_POSITION); |
| 493 | 493 |
destArray = new byte[ReportConfig.TELECOM_LENGTH]; |
| 494 | 494 |
buffer.get(destArray); |
| 495 |
- reportDto.setRsltNet(new String(destArray).trim()); |
|
| 495 |
+ reportDto.setRsltNet(QueueConstants.getString(destArray)); |
|
| 496 | 496 |
/* RESULT (Length : 5 / Position : 39) */ |
| 497 | 497 |
buffer.position(ReportConfig.RESULT_POSITION); |
| 498 | 498 |
destArray = new byte[ReportConfig.RESULT_LENGTH]; |
| 499 | 499 |
buffer.get(destArray); |
| 500 |
- reportDto.setRsltCode(new String(destArray).trim()); |
|
| 500 |
+ reportDto.setRsltCode(QueueConstants.getString(destArray)); |
|
| 501 | 501 |
|
| 502 | 502 |
return reportDto; |
| 503 | 503 |
} |
--- src/main/java/com/munjaon/server/util/StringUtil.java
+++ src/main/java/com/munjaon/server/util/StringUtil.java
... | ... | @@ -5,9 +5,6 @@ |
| 5 | 5 |
|
| 6 | 6 |
package com.munjaon.server.util; |
| 7 | 7 |
|
| 8 |
-import java.text.DecimalFormat; |
|
| 9 |
-import java.util.ArrayList; |
|
| 10 |
- |
|
| 11 | 8 |
/** |
| 12 | 9 |
* 문자열 관련 유틸리티 클래스 |
| 13 | 10 |
* @author JDS |
... | ... | @@ -38,130 +35,5 @@ |
| 38 | 35 |
} |
| 39 | 36 |
|
| 40 | 37 |
return ((String)obj).trim(); |
| 41 |
- } |
|
| 42 |
- |
|
| 43 |
- public static String ltrim(byte[] obj) {
|
|
| 44 |
- return ltrim(new String(obj)); |
|
| 45 |
- } |
|
| 46 |
- |
|
| 47 |
- public static String ltrim(String obj) {
|
|
| 48 |
- return ltrim(obj.toCharArray()); |
|
| 49 |
- } |
|
| 50 |
- |
|
| 51 |
- public static String ltrim(char[] obj) {
|
|
| 52 |
- int len = obj.length; |
|
| 53 |
- int idx = 0; |
|
| 54 |
- |
|
| 55 |
- while( idx < len && obj[idx] <= ' ' ) {
|
|
| 56 |
- idx++; |
|
| 57 |
- } |
|
| 58 |
- |
|
| 59 |
- return new String(obj, idx, len-idx); |
|
| 60 |
- } |
|
| 61 |
- |
|
| 62 |
- public static String rtrim(byte[] obj) {
|
|
| 63 |
- return rtrim(new String(obj)); |
|
| 64 |
- } |
|
| 65 |
- |
|
| 66 |
- public static String rtrim(String obj) {
|
|
| 67 |
- return rtrim(obj.toCharArray()); |
|
| 68 |
- } |
|
| 69 |
- |
|
| 70 |
- public static String rtrim(char[] obj) {
|
|
| 71 |
- int len = obj.length; |
|
| 72 |
- int idx = len-1; |
|
| 73 |
- |
|
| 74 |
- while( idx >= 0 && obj[idx] <= ' ' ) {
|
|
| 75 |
- idx--; |
|
| 76 |
- } |
|
| 77 |
- |
|
| 78 |
- return new String(obj, 0, idx+1); |
|
| 79 |
- } |
|
| 80 |
- |
|
| 81 |
- public static String replaceAll(String src, String from, String to) {
|
|
| 82 |
- StringBuilder sbuf = new StringBuilder(); |
|
| 83 |
- |
|
| 84 |
- int len = from.length(); |
|
| 85 |
- int idx = 0; |
|
| 86 |
- int stx = 0; |
|
| 87 |
- |
|
| 88 |
- while( (idx=src.indexOf(from, stx)) > -1 ) {
|
|
| 89 |
- sbuf.append(src.substring(stx, idx)); |
|
| 90 |
- sbuf.append(to); |
|
| 91 |
- stx=idx+len; |
|
| 92 |
- } |
|
| 93 |
- |
|
| 94 |
- sbuf.append(src.substring(stx)); |
|
| 95 |
- |
|
| 96 |
- return sbuf.toString(); |
|
| 97 |
- } |
|
| 98 |
- |
|
| 99 |
- public static String[] split(String sSrc, String sDelim) {
|
|
| 100 |
- ArrayList aList = new ArrayList(); |
|
| 101 |
- |
|
| 102 |
- String sTmp; |
|
| 103 |
- int len = sDelim.length(); |
|
| 104 |
- int idx = 0; |
|
| 105 |
- int stx = 0; |
|
| 106 |
- |
|
| 107 |
- while( (idx=sSrc.indexOf(sDelim, stx)) > -1 ) {
|
|
| 108 |
- sTmp = sSrc.substring(stx, idx); |
|
| 109 |
- aList.add(sTmp); |
|
| 110 |
- stx=idx+len; |
|
| 111 |
- } |
|
| 112 |
- |
|
| 113 |
- if( stx <= sSrc.length() ) {
|
|
| 114 |
- aList.add(sSrc.substring(stx)); |
|
| 115 |
- } |
|
| 116 |
- |
|
| 117 |
- String[] sRet = new String[aList.size()]; |
|
| 118 |
- |
|
| 119 |
- for( int i=0; i<aList.size(); i++ ) {
|
|
| 120 |
- sRet[i] = (String) aList.get(i); |
|
| 121 |
- } |
|
| 122 |
- |
|
| 123 |
- return sRet; |
|
| 124 |
- } |
|
| 125 |
- |
|
| 126 |
- public static String substring(String obj, int idx, int length) {
|
|
| 127 |
- if( obj.getBytes().length <= idx ) {
|
|
| 128 |
- return ""; |
|
| 129 |
- } |
|
| 130 |
- |
|
| 131 |
- if( obj.getBytes().length <= length ) {
|
|
| 132 |
- return obj; |
|
| 133 |
- } |
|
| 134 |
- |
|
| 135 |
- int totallen=0; |
|
| 136 |
- int i=idx; |
|
| 137 |
- for( i=idx; i<obj.length(); i++ ) {
|
|
| 138 |
- totallen += obj.substring(i, i+1).getBytes().length; |
|
| 139 |
- |
|
| 140 |
- if( length < totallen ) {
|
|
| 141 |
- break; |
|
| 142 |
- } |
|
| 143 |
- } |
|
| 144 |
- |
|
| 145 |
- return obj.substring(idx, i); |
|
| 146 |
- } |
|
| 147 |
- |
|
| 148 |
- public static String substring(String obj, int length) {
|
|
| 149 |
- return substring(obj, 0, length); |
|
| 150 |
- } |
|
| 151 |
- |
|
| 152 |
- public static String numFilter(String src) {
|
|
| 153 |
- return src.replaceAll("[^0-9]", "");
|
|
| 154 |
- } |
|
| 155 |
- |
|
| 156 |
- public static String toNumberFormat(Object obj, String fmt) {
|
|
| 157 |
- DecimalFormat df = new DecimalFormat(fmt); |
|
| 158 |
- return df.format(obj); |
|
| 159 |
- } |
|
| 160 |
- |
|
| 161 |
- public static String pad0(String str, int size) {
|
|
| 162 |
- char[] zeros = new char[size - str.length()]; |
|
| 163 |
- for (int i = 0; i < zeros.length; i++) |
|
| 164 |
- zeros[i] = '0'; |
|
| 165 |
- return new String(zeros) + str; |
|
| 166 | 38 |
} |
| 167 | 39 |
} |
--- src/main/resources/dev/application-dev.yml
+++ src/main/resources/dev/application-dev.yml
... | ... | @@ -7,6 +7,11 @@ |
| 7 | 7 |
# jdbc-url: jdbc:mariadb://119.193.215.98:3306/mjon_agent_back |
| 8 | 8 |
username: mjonUr_agent |
| 9 | 9 |
password: mjagent123$ |
| 10 |
+ connectionTimeout: 30000 |
|
| 11 |
+ maximumPoolSize: 15 |
|
| 12 |
+ maxLifetime: 1800000 |
|
| 13 |
+ poolName: HikariCP |
|
| 14 |
+ connectionTestQuery: SELECT 1 |
|
| 10 | 15 |
|
| 11 | 16 |
server: |
| 12 | 17 |
port: 8090 |
--- src/main/resources/local/application-local.yml
+++ src/main/resources/local/application-local.yml
... | ... | @@ -2,10 +2,15 @@ |
| 2 | 2 |
datasource: |
| 3 | 3 |
server: |
| 4 | 4 |
driver-class-name: org.mariadb.jdbc.Driver |
| 5 |
- url: jdbc:mariadb://119.193.215.98:3306/mjon_agent_back |
|
| 6 |
- jdbc-url: jdbc:mariadb://119.193.215.98:3306/mjon_agent_back |
|
| 7 |
- username: mjonUr_agent |
|
| 8 |
- password: mjagent123$ |
|
| 5 |
+ url: jdbc:mariadb://localhost:3306/mjon |
|
| 6 |
+ jdbc-url: jdbc:mariadb://localhost:3306/mjon |
|
| 7 |
+ username: root |
|
| 8 |
+ password: 1234 |
|
| 9 |
+ connectionTimeout: 30000 |
|
| 10 |
+ maximumPoolSize: 15 |
|
| 11 |
+ maxLifetime: 1800000 |
|
| 12 |
+ poolName: HikariCP |
|
| 13 |
+ connectionTestQuery: SELECT 1 |
|
| 9 | 14 |
|
| 10 | 15 |
server: |
| 11 | 16 |
port: 8090 |
--- src/main/resources/prod/application-prod.yml
+++ src/main/resources/prod/application-prod.yml
... | ... | @@ -6,6 +6,11 @@ |
| 6 | 6 |
jdbc-url: jdbc:mariadb://119.193.215.98:3306/mjon_agent |
| 7 | 7 |
username: mjonUr_agent |
| 8 | 8 |
password: mjagent123$ |
| 9 |
+ connectionTimeout: 30000 |
|
| 10 |
+ maximumPoolSize: 20 |
|
| 11 |
+ maxLifetime: 1800000 |
|
| 12 |
+ poolName: HikariCP |
|
| 13 |
+ connectionTestQuery: SELECT 1 |
|
| 9 | 14 |
|
| 10 | 15 |
server: |
| 11 | 16 |
port: 8090 |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?