write 큐 기능 개선, 통신 프로세스 변경, Read 큐 프로세스 개선, 서버, 클라이언트 통신 오류 수정중
@3950fba677ef66fc7be4f5f22bfe61d3bcd637a5
+++ src/main/java/com/munjaon/server/api/controller/MessageController.java
... | ... | @@ -0,0 +1,34 @@ |
| 1 | +package com.munjaon.server.api.controller; | |
| 2 | + | |
| 3 | +import com.munjaon.server.api.dto.base.ApiResponse; | |
| 4 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 5 | +import com.munjaon.server.queue.enums.QueueTypeWorker; | |
| 6 | +import lombok.RequiredArgsConstructor; | |
| 7 | +import lombok.extern.slf4j.Slf4j; | |
| 8 | +import org.apache.commons.configuration2.ex.ConfigurationException; | |
| 9 | +import org.springframework.http.HttpStatus; | |
| 10 | +import org.springframework.http.ResponseEntity; | |
| 11 | +import org.springframework.web.bind.annotation.PostMapping; | |
| 12 | +import org.springframework.web.bind.annotation.RequestBody; | |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | +import org.springframework.web.bind.annotation.RestController; | |
| 15 | + | |
| 16 | +@Slf4j | |
| 17 | +@RequestMapping("/api/message") | |
| 18 | +@RestController | |
| 19 | +@RequiredArgsConstructor | |
| 20 | +public class MessageController { | |
| 21 | + @PostMapping("/save") | |
| 22 | + public ResponseEntity postSample(@RequestBody BasicMessageDto reqDto) throws ConfigurationException { | |
| 23 | + log.debug("BasicMessageDto : {}", reqDto); | |
| 24 | + if (reqDto.getServiceType() != null && reqDto.getServiceType().equals("4")) { | |
| 25 | + QueueTypeWorker worker = QueueTypeWorker.find("SMS"); | |
| 26 | + if (worker != null) { | |
| 27 | + log.debug("queue size : {}", worker.isExistQueue("SMS01")); | |
| 28 | + worker.pushQueue(reqDto); | |
| 29 | + } | |
| 30 | + } | |
| 31 | + | |
| 32 | + return new ResponseEntity(ApiResponse.toResponse(200, "OK", reqDto), HttpStatus.OK); | |
| 33 | + } | |
| 34 | +} |
--- src/main/java/com/munjaon/server/config/RunnerConfiguration.java
+++ src/main/java/com/munjaon/server/config/RunnerConfiguration.java
... | ... | @@ -1,13 +1,20 @@ |
| 1 | 1 |
package com.munjaon.server.config; |
| 2 | 2 |
|
| 3 |
+import com.munjaon.server.queue.dto.QueueInfo; |
|
| 4 |
+import com.munjaon.server.queue.pool.SmsReadQueue; |
|
| 5 |
+import com.munjaon.server.queue.pool.SmsWriteQueue; |
|
| 3 | 6 |
import com.munjaon.server.server.service.PropertyLoader; |
| 7 |
+import com.munjaon.server.server.service.QueueServerService; |
|
| 8 |
+import com.munjaon.server.util.ServiceUtil; |
|
| 4 | 9 |
import lombok.RequiredArgsConstructor; |
| 10 |
+import lombok.extern.slf4j.Slf4j; |
|
| 5 | 11 |
import org.apache.commons.configuration2.ex.ConfigurationException; |
| 6 | 12 |
import org.springframework.boot.CommandLineRunner; |
| 7 | 13 |
import org.springframework.context.annotation.Bean; |
| 8 | 14 |
import org.springframework.context.annotation.Configuration; |
| 9 | 15 |
import org.springframework.core.annotation.Order; |
| 10 | 16 |
|
| 17 |
+@Slf4j |
|
| 11 | 18 |
@Configuration |
| 12 | 19 |
@RequiredArgsConstructor |
| 13 | 20 |
public class RunnerConfiguration {
|
... | ... | @@ -34,7 +41,28 @@ |
| 34 | 41 |
|
| 35 | 42 |
@Bean |
| 36 | 43 |
@Order(2) |
| 37 |
- public CommandLineRunner getRunnerBeanForService() {
|
|
| 44 |
+ public CommandLineRunner getRunnerBeanForSmsQueue() {
|
|
| 45 |
+ try {
|
|
| 46 |
+ String[] svcArray = ServiceUtil.getServiceNames(serverConfig.getStringArray("SMS.SERVICE_LIST"));
|
|
| 47 |
+ if (svcArray == null || svcArray.length == 0) {
|
|
| 48 |
+ log.info("SMS service list is empty");
|
|
| 49 |
+ } else {
|
|
| 50 |
+ if (ServiceUtil.isDuplicate(svcArray)) {
|
|
| 51 |
+ log.info("SMS service list is duplicated");
|
|
| 52 |
+ } else {
|
|
| 53 |
+ for (String svc : svcArray) {
|
|
| 54 |
+ log.info("SERVICE CREATE : {}", svc);
|
|
| 55 |
+ QueueInfo queueInfo = QueueInfo.builder().queueName(svc).serviceType("SMS").queuePath(serverConfig.getString("SMS.QUEUE_PATH")).build();
|
|
| 56 |
+ SmsWriteQueue smsWriteQueue = new SmsWriteQueue(queueInfo); |
|
| 57 |
+ SmsReadQueue smsReadQueue = new SmsReadQueue(queueInfo); |
|
| 58 |
+ QueueServerService queueServerService = new QueueServerService(svc, smsWriteQueue, smsReadQueue); |
|
| 59 |
+ queueServerService.start(); |
|
| 60 |
+ } |
|
| 61 |
+ } |
|
| 62 |
+ } |
|
| 63 |
+ } catch (Exception e) {
|
|
| 64 |
+ throw new RuntimeException(e); |
|
| 65 |
+ } |
|
| 38 | 66 |
return args -> System.out.println("Runner Bean #2");
|
| 39 | 67 |
} |
| 40 | 68 |
} |
--- src/main/java/com/munjaon/server/queue/dto/QueueInfo.java
+++ src/main/java/com/munjaon/server/queue/dto/QueueInfo.java
... | ... | @@ -10,10 +10,10 @@ |
| 10 | 10 |
@Builder |
| 11 | 11 |
@ToString |
| 12 | 12 |
public class QueueInfo {
|
| 13 |
- private String queueName = ""; |
|
| 14 |
- private String queueFileName = ""; |
|
| 13 |
+ private String queuePath; |
|
| 14 |
+ private String queueName; |
|
| 15 |
+ private String queueFileName; |
|
| 15 | 16 |
// private int queueDataLength = 0; |
| 16 |
- private String serviceType = ""; |
|
| 17 |
- private String readXMLFileName = ""; |
|
| 18 |
- private boolean isRun; |
|
| 17 |
+ private String serviceType; |
|
| 18 |
+ private String readXMLFileName; |
|
| 19 | 19 |
} |
--- src/main/java/com/munjaon/server/queue/enums/QueueTypeWorker.java
+++ src/main/java/com/munjaon/server/queue/enums/QueueTypeWorker.java
... | ... | @@ -39,6 +39,30 @@ |
| 39 | 39 |
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService(); |
| 40 | 40 |
return smsQueueService.saveMessageToTable(data); |
| 41 | 41 |
} |
| 42 |
+ |
|
| 43 |
+ @Override |
|
| 44 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 45 |
+ SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService(); |
|
| 46 |
+ smsQueueService.memoryEnQueue(data); |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ @Override |
|
| 50 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 51 |
+ SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService(); |
|
| 52 |
+ return smsQueueService.memoryDeQueue(); |
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ @Override |
|
| 56 |
+ public int getMemorySize() {
|
|
| 57 |
+ SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService(); |
|
| 58 |
+ return smsQueueService.getMemorySize(); |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ @Override |
|
| 62 |
+ public boolean isMemoryEmpty() {
|
|
| 63 |
+ SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService(); |
|
| 64 |
+ return smsQueueService.isMemoryEmpty(); |
|
| 65 |
+ } |
|
| 42 | 66 |
}, |
| 43 | 67 |
MSG_TYPE_LMS("LMS") {
|
| 44 | 68 |
@Override |
... | ... | @@ -69,6 +93,30 @@ |
| 69 | 93 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 70 | 94 |
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService(); |
| 71 | 95 |
return lmsQueueService.saveMessageToTable(data); |
| 96 |
+ } |
|
| 97 |
+ |
|
| 98 |
+ @Override |
|
| 99 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 100 |
+ LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService(); |
|
| 101 |
+ lmsQueueService.memoryEnQueue(data); |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ @Override |
|
| 105 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 106 |
+ LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService(); |
|
| 107 |
+ return lmsQueueService.memoryDeQueue(); |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ @Override |
|
| 111 |
+ public int getMemorySize() {
|
|
| 112 |
+ LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService(); |
|
| 113 |
+ return lmsQueueService.getMemorySize(); |
|
| 114 |
+ } |
|
| 115 |
+ |
|
| 116 |
+ @Override |
|
| 117 |
+ public boolean isMemoryEmpty() {
|
|
| 118 |
+ LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService(); |
|
| 119 |
+ return lmsQueueService.isMemoryEmpty(); |
|
| 72 | 120 |
} |
| 73 | 121 |
}, |
| 74 | 122 |
MSG_TYPE_MMS("MMS") {
|
... | ... | @@ -101,6 +149,30 @@ |
| 101 | 149 |
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService(); |
| 102 | 150 |
return mmsQueueService.saveMessageToTable(data); |
| 103 | 151 |
} |
| 152 |
+ |
|
| 153 |
+ @Override |
|
| 154 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 155 |
+ MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService(); |
|
| 156 |
+ mmsQueueService.memoryEnQueue(data); |
|
| 157 |
+ } |
|
| 158 |
+ |
|
| 159 |
+ @Override |
|
| 160 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 161 |
+ MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService(); |
|
| 162 |
+ return mmsQueueService.memoryDeQueue(); |
|
| 163 |
+ } |
|
| 164 |
+ |
|
| 165 |
+ @Override |
|
| 166 |
+ public int getMemorySize() {
|
|
| 167 |
+ MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService(); |
|
| 168 |
+ return mmsQueueService.getMemorySize(); |
|
| 169 |
+ } |
|
| 170 |
+ |
|
| 171 |
+ @Override |
|
| 172 |
+ public boolean isMemoryEmpty() {
|
|
| 173 |
+ MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService(); |
|
| 174 |
+ return mmsQueueService.isMemoryEmpty(); |
|
| 175 |
+ } |
|
| 104 | 176 |
}, |
| 105 | 177 |
MSG_TYPE_KAT("KAT") {
|
| 106 | 178 |
@Override |
... | ... | @@ -131,6 +203,30 @@ |
| 131 | 203 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 132 | 204 |
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService(); |
| 133 | 205 |
return kakaoAlarmQueueService.saveMessageToTable(data); |
| 206 |
+ } |
|
| 207 |
+ |
|
| 208 |
+ @Override |
|
| 209 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 210 |
+ KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService(); |
|
| 211 |
+ kakaoAlarmQueueService.memoryEnQueue(data); |
|
| 212 |
+ } |
|
| 213 |
+ |
|
| 214 |
+ @Override |
|
| 215 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 216 |
+ KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService(); |
|
| 217 |
+ return kakaoAlarmQueueService.memoryDeQueue(); |
|
| 218 |
+ } |
|
| 219 |
+ |
|
| 220 |
+ @Override |
|
| 221 |
+ public int getMemorySize() {
|
|
| 222 |
+ KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService(); |
|
| 223 |
+ return kakaoAlarmQueueService.getMemorySize(); |
|
| 224 |
+ } |
|
| 225 |
+ |
|
| 226 |
+ @Override |
|
| 227 |
+ public boolean isMemoryEmpty() {
|
|
| 228 |
+ KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService(); |
|
| 229 |
+ return kakaoAlarmQueueService.isMemoryEmpty(); |
|
| 134 | 230 |
} |
| 135 | 231 |
}, |
| 136 | 232 |
MSG_TYPE_KFT("KFT") {
|
... | ... | @@ -163,6 +259,30 @@ |
| 163 | 259 |
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService(); |
| 164 | 260 |
return kakaoFriendQueueService.saveMessageToTable(data); |
| 165 | 261 |
} |
| 262 |
+ |
|
| 263 |
+ @Override |
|
| 264 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 265 |
+ KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService(); |
|
| 266 |
+ kakaoFriendQueueService.memoryEnQueue(data); |
|
| 267 |
+ } |
|
| 268 |
+ |
|
| 269 |
+ @Override |
|
| 270 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 271 |
+ KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService(); |
|
| 272 |
+ return kakaoFriendQueueService.memoryDeQueue(); |
|
| 273 |
+ } |
|
| 274 |
+ |
|
| 275 |
+ @Override |
|
| 276 |
+ public int getMemorySize() {
|
|
| 277 |
+ KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService(); |
|
| 278 |
+ return kakaoFriendQueueService.getMemorySize(); |
|
| 279 |
+ } |
|
| 280 |
+ |
|
| 281 |
+ @Override |
|
| 282 |
+ public boolean isMemoryEmpty() {
|
|
| 283 |
+ KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService(); |
|
| 284 |
+ return kakaoFriendQueueService.isMemoryEmpty(); |
|
| 285 |
+ } |
|
| 166 | 286 |
}; |
| 167 | 287 |
|
| 168 | 288 |
QueueTypeWorker(final String name) {
|
... | ... | @@ -186,4 +306,9 @@ |
| 186 | 306 |
public abstract void addQueue(WriteQueue queue); |
| 187 | 307 |
public abstract void pushQueue(BasicMessageDto data); |
| 188 | 308 |
public abstract int saveMessageToTable(BasicMessageDto data); |
| 309 |
+ |
|
| 310 |
+ public abstract void memoryEnQueue(BasicMessageDto data); |
|
| 311 |
+ public abstract BasicMessageDto memoryDeQueue(); |
|
| 312 |
+ public abstract int getMemorySize(); |
|
| 313 |
+ public abstract boolean isMemoryEmpty(); |
|
| 189 | 314 |
} |
+++ src/main/java/com/munjaon/server/queue/pool/KakaoAlarmMemoryQueue.java
... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +public class KakaoAlarmMemoryQueue { | |
| 8 | + /** Lock Object */ | |
| 9 | + private final Object msgMonitor = new Object(); | |
| 10 | + /** Message Queue */ | |
| 11 | + private final LinkedList<BasicMessageDto> msgQueue = new LinkedList<>(); | |
| 12 | + /** Singleton Instance */ | |
| 13 | + private static KakaoAlarmMemoryQueue memoryQueue; | |
| 14 | + | |
| 15 | + public synchronized static KakaoAlarmMemoryQueue getInstance() { | |
| 16 | + if(memoryQueue == null){ | |
| 17 | + memoryQueue = new KakaoAlarmMemoryQueue(); | |
| 18 | + } | |
| 19 | + return memoryQueue; | |
| 20 | + } | |
| 21 | + /** MESSAGE QUEUE ************************************************************************ */ | |
| 22 | + /** MESSAGE enQueue */ | |
| 23 | + public void memoryEnQueue(BasicMessageDto data){ | |
| 24 | + synchronized(msgMonitor){ | |
| 25 | + msgQueue.addLast(data); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + /** SMS deQueue */ | |
| 29 | + public BasicMessageDto memoryDeQueue() { | |
| 30 | + synchronized(msgMonitor){ | |
| 31 | + if (msgQueue.isEmpty()) return null; | |
| 32 | + else return msgQueue.removeFirst(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + /** SMS size */ | |
| 36 | + public int getMemorySize() { | |
| 37 | + synchronized(msgMonitor) { | |
| 38 | + return msgQueue.size(); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** SMS isEmpty */ | |
| 42 | + public boolean isMemoryEmpty() { | |
| 43 | + synchronized(msgMonitor) { | |
| 44 | + return msgQueue.isEmpty(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} |
--- src/main/java/com/munjaon/server/queue/pool/KakaoAlarmWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/pool/KakaoAlarmWriteQueue.java
... | ... | @@ -5,17 +5,17 @@ |
| 5 | 5 |
public class KakaoAlarmWriteQueue extends WriteQueue {
|
| 6 | 6 |
|
| 7 | 7 |
@Override |
| 8 |
- int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 8 |
+ public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 9 | 9 |
return 0; |
| 10 | 10 |
} |
| 11 | 11 |
|
| 12 | 12 |
@Override |
| 13 |
- void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 13 |
+ public void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 14 | 14 |
|
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 | 17 |
@Override |
| 18 |
- void initDataBuffer() {
|
|
| 18 |
+ public void initDataBuffer() {
|
|
| 19 | 19 |
|
| 20 | 20 |
} |
| 21 | 21 |
} |
+++ src/main/java/com/munjaon/server/queue/pool/KakaoFriendMemoryQueue.java
... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +public class KakaoFriendMemoryQueue { | |
| 8 | + /** SMS Lock Object */ | |
| 9 | + private final Object msgMonitor = new Object(); | |
| 10 | + /** SMS Message Queue */ | |
| 11 | + private final LinkedList<BasicMessageDto> msgQueue = new LinkedList<>(); | |
| 12 | + /** Singleton Instance */ | |
| 13 | + private static KakaoFriendMemoryQueue memoryQueue; | |
| 14 | + | |
| 15 | + public synchronized static KakaoFriendMemoryQueue getInstance() { | |
| 16 | + if(memoryQueue == null){ | |
| 17 | + memoryQueue = new KakaoFriendMemoryQueue(); | |
| 18 | + } | |
| 19 | + return memoryQueue; | |
| 20 | + } | |
| 21 | + /** MESSAGE QUEUE ************************************************************************ */ | |
| 22 | + /** MESSAGE enQueue */ | |
| 23 | + public void memoryEnQueue(BasicMessageDto data){ | |
| 24 | + synchronized(msgMonitor){ | |
| 25 | + msgQueue.addLast(data); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + /** SMS deQueue */ | |
| 29 | + public BasicMessageDto memoryDeQueue() { | |
| 30 | + synchronized(msgMonitor){ | |
| 31 | + if (msgQueue.isEmpty()) return null; | |
| 32 | + else return msgQueue.removeFirst(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + /** SMS size */ | |
| 36 | + public int getMemorySize() { | |
| 37 | + synchronized(msgMonitor) { | |
| 38 | + return msgQueue.size(); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** SMS isEmpty */ | |
| 42 | + public boolean isMemoryEmpty() { | |
| 43 | + synchronized(msgMonitor) { | |
| 44 | + return msgQueue.isEmpty(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} |
--- src/main/java/com/munjaon/server/queue/pool/KakaoFriendWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/pool/KakaoFriendWriteQueue.java
... | ... | @@ -4,17 +4,17 @@ |
| 4 | 4 |
|
| 5 | 5 |
public class KakaoFriendWriteQueue extends WriteQueue {
|
| 6 | 6 |
@Override |
| 7 |
- int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 7 |
+ public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 8 | 8 |
return 0; |
| 9 | 9 |
} |
| 10 | 10 |
|
| 11 | 11 |
@Override |
| 12 |
- void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 12 |
+ public void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 13 | 13 |
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 | 16 |
@Override |
| 17 |
- void initDataBuffer() {
|
|
| 17 |
+ public void initDataBuffer() {
|
|
| 18 | 18 |
|
| 19 | 19 |
} |
| 20 | 20 |
} |
+++ src/main/java/com/munjaon/server/queue/pool/LmsMemoryQueue.java
... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +public class LmsMemoryQueue { | |
| 8 | + /** Lock Object */ | |
| 9 | + private final Object msgMonitor = new Object(); | |
| 10 | + /** Message Queue */ | |
| 11 | + private final LinkedList<BasicMessageDto> msgQueue = new LinkedList<>(); | |
| 12 | + /** Singleton Instance */ | |
| 13 | + private static LmsMemoryQueue memoryQueue; | |
| 14 | + | |
| 15 | + public synchronized static LmsMemoryQueue getInstance() { | |
| 16 | + if(memoryQueue == null){ | |
| 17 | + memoryQueue = new LmsMemoryQueue(); | |
| 18 | + } | |
| 19 | + return memoryQueue; | |
| 20 | + } | |
| 21 | + /** MESSAGE QUEUE ************************************************************************ */ | |
| 22 | + /** MESSAGE enQueue */ | |
| 23 | + public void memoryEnQueue(BasicMessageDto data){ | |
| 24 | + synchronized(msgMonitor){ | |
| 25 | + msgQueue.addLast(data); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + /** SMS deQueue */ | |
| 29 | + public BasicMessageDto memoryDeQueue() { | |
| 30 | + synchronized(msgMonitor){ | |
| 31 | + if (msgQueue.isEmpty()) return null; | |
| 32 | + else return msgQueue.removeFirst(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + /** SMS size */ | |
| 36 | + public int getMemorySize() { | |
| 37 | + synchronized(msgMonitor) { | |
| 38 | + return msgQueue.size(); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** SMS isEmpty */ | |
| 42 | + public boolean isMemoryEmpty() { | |
| 43 | + synchronized(msgMonitor) { | |
| 44 | + return msgQueue.isEmpty(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} |
+++ src/main/java/com/munjaon/server/queue/pool/MmsMemoryQueue.java
... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +public class MmsMemoryQueue { | |
| 8 | + /** Lock Object */ | |
| 9 | + private final Object msgMonitor = new Object(); | |
| 10 | + /** Message Queue */ | |
| 11 | + private final LinkedList<BasicMessageDto> msgQueue = new LinkedList<>(); | |
| 12 | + /** Singleton Instance */ | |
| 13 | + private static MmsMemoryQueue memoryQueue; | |
| 14 | + | |
| 15 | + public synchronized static MmsMemoryQueue getInstance() { | |
| 16 | + if(memoryQueue == null){ | |
| 17 | + memoryQueue = new MmsMemoryQueue(); | |
| 18 | + } | |
| 19 | + return memoryQueue; | |
| 20 | + } | |
| 21 | + /** MESSAGE QUEUE ************************************************************************ */ | |
| 22 | + /** MESSAGE enQueue */ | |
| 23 | + public void memoryEnQueue(BasicMessageDto data){ | |
| 24 | + synchronized(msgMonitor){ | |
| 25 | + msgQueue.addLast(data); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + /** SMS deQueue */ | |
| 29 | + public BasicMessageDto memoryDeQueue() { | |
| 30 | + synchronized(msgMonitor){ | |
| 31 | + if (msgQueue.isEmpty()) return null; | |
| 32 | + else return msgQueue.removeFirst(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + /** SMS size */ | |
| 36 | + public int getMemorySize() { | |
| 37 | + synchronized(msgMonitor) { | |
| 38 | + return msgQueue.size(); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** SMS isEmpty */ | |
| 42 | + public boolean isMemoryEmpty() { | |
| 43 | + synchronized(msgMonitor) { | |
| 44 | + return msgQueue.isEmpty(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} |
--- src/main/java/com/munjaon/server/queue/pool/QueuePool.java
+++ src/main/java/com/munjaon/server/queue/pool/QueuePool.java
... | ... | @@ -1,9 +1,11 @@ |
| 1 | 1 |
package com.munjaon.server.queue.pool; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import lombok.extern.slf4j.Slf4j; |
|
| 4 | 5 |
|
| 5 | 6 |
import java.util.LinkedList; |
| 6 | 7 |
|
| 8 |
+@Slf4j |
|
| 7 | 9 |
public abstract class QueuePool {
|
| 8 | 10 |
/** Lock Object */ |
| 9 | 11 |
protected final Object lockMonitor = new Object(); |
... | ... | @@ -69,6 +71,7 @@ |
| 69 | 71 |
} |
| 70 | 72 |
// 파일큐에 Push 한다. |
| 71 | 73 |
queue = queuePool.get(queueIndex); |
| 74 |
+ log.info("Adding queue : {}, Data : {}", queue.getQueueName(), data);
|
|
| 72 | 75 |
queue.pushMessageToBuffer(data); |
| 73 | 76 |
// 큐인덱서를 증가시킨다. |
| 74 | 77 |
queueIndex++; |
+++ src/main/java/com/munjaon/server/queue/pool/ReadQueue.java
... | ... | @@ -0,0 +1,211 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.config.QueueConstants; | |
| 4 | +import com.munjaon.server.queue.config.QueueHeaderConfig; | |
| 5 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 6 | +import com.munjaon.server.queue.dto.QueueInfo; | |
| 7 | +import com.munjaon.server.util.FileUtil; | |
| 8 | +import com.munjaon.server.util.MessageUtil; | |
| 9 | +import lombok.Getter; | |
| 10 | +import org.jdom2.Document; | |
| 11 | +import org.jdom2.Element; | |
| 12 | +import org.jdom2.JDOMException; | |
| 13 | +import org.jdom2.input.SAXBuilder; | |
| 14 | +import org.jdom2.output.Format; | |
| 15 | +import org.jdom2.output.XMLOutputter; | |
| 16 | + | |
| 17 | +import java.io.File; | |
| 18 | +import java.io.FileOutputStream; | |
| 19 | +import java.io.IOException; | |
| 20 | +import java.io.RandomAccessFile; | |
| 21 | +import java.nio.ByteBuffer; | |
| 22 | +import java.nio.channels.FileChannel; | |
| 23 | +import java.time.LocalDateTime; | |
| 24 | +import java.time.format.DateTimeFormatter; | |
| 25 | +import java.util.List; | |
| 26 | + | |
| 27 | +public abstract class ReadQueue { | |
| 28 | + /** Queue Header Buffer */ | |
| 29 | + protected ByteBuffer headerBuffer = null; | |
| 30 | + /** Header 에서 사용하는 변수 */ | |
| 31 | + protected byte[] headerArray = null; | |
| 32 | + /** Queue Create Date - [Format:YYYYMMDD] */ | |
| 33 | + @Getter | |
| 34 | + protected String createDate; | |
| 35 | + /** XML 읽은 날짜 */ | |
| 36 | + @Getter | |
| 37 | + protected String readXMLDate; | |
| 38 | + /** Queue Pop Counter */ | |
| 39 | + @Getter | |
| 40 | + protected int popCounter = -1; | |
| 41 | + /** Queue Push Counter */ | |
| 42 | + @Getter | |
| 43 | + protected int pushCounter = 0; | |
| 44 | + /* 큐경로 */ | |
| 45 | + @Getter | |
| 46 | + protected String queuePath; | |
| 47 | + | |
| 48 | + /** Queue File Channel */ | |
| 49 | + protected FileChannel channel = null; | |
| 50 | + protected FileOutputStream fileOutputStream = null; | |
| 51 | + /** Queue Information */ | |
| 52 | + @Getter | |
| 53 | + protected QueueInfo queueInfo = null; | |
| 54 | + /** pushBuffer() 함수에서 사용하는 변수 */ | |
| 55 | + protected ByteBuffer dataBuffer = null; | |
| 56 | + | |
| 57 | + protected void initQueuePath() { | |
| 58 | + /* 1. 큐경로 */ | |
| 59 | + this.queuePath = System.getProperty("ROOTPATH") + File.separator + queueInfo.getQueuePath(); | |
| 60 | + /* 2. 경로 체크 및 생성 */ | |
| 61 | + FileUtil.mkdirs(this.queuePath); | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void initReadQueue() throws IOException, JDOMException { | |
| 65 | + this.queueInfo.setReadXMLFileName(this.queuePath + File.separator + this.queueInfo.getQueueName() + "_Read.xml"); | |
| 66 | + File file = new File(this.queueInfo.getReadXMLFileName()); | |
| 67 | + if (file.exists()) { | |
| 68 | + readPopCounter(file); | |
| 69 | + } else { | |
| 70 | + this.readXMLDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | |
| 71 | + this.popCounter = 0; | |
| 72 | + writePopCounter(); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void initPopCounter() throws IOException { | |
| 77 | + initHeaderBuffer(); | |
| 78 | + // 데이터 초기화 | |
| 79 | + this.readXMLDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | |
| 80 | + this.popCounter = 0; | |
| 81 | + | |
| 82 | + writePopCounter(); | |
| 83 | + } | |
| 84 | + protected void readPopCounter(File file) throws IOException, JDOMException { | |
| 85 | + SAXBuilder sax = new SAXBuilder(); | |
| 86 | + // String that contains XML | |
| 87 | + Document doc = (Document) sax.build(file); | |
| 88 | + Element rootNode = doc.getRootElement(); | |
| 89 | + List<Element> childElements = rootNode.getChildren(); | |
| 90 | + for (Element child : childElements) { | |
| 91 | + if ("createDate".equals(child.getName())) { | |
| 92 | + this.readXMLDate = child.getValue(); | |
| 93 | + } | |
| 94 | + if ("popCounter".equals(child.getName())) { | |
| 95 | + this.popCounter = Integer.parseInt(child.getValue()); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + } | |
| 99 | + protected void readPopCounter() throws IOException, JDOMException { | |
| 100 | + // String that contains XML | |
| 101 | + File file = new File(this.queueInfo.getReadXMLFileName()); | |
| 102 | + readPopCounter(file); | |
| 103 | + } | |
| 104 | + | |
| 105 | + public void writePopCounter() throws IOException { | |
| 106 | + SAXBuilder sb = new SAXBuilder(); | |
| 107 | + Document docFile = new Document(); | |
| 108 | + | |
| 109 | + Element rootElement = new Element("ReadQueue"); | |
| 110 | + rootElement.addContent(new Element("createDate").setText(this.readXMLDate)); | |
| 111 | + rootElement.addContent(new Element("popCounter").setText(Integer.toString(this.popCounter))); | |
| 112 | + docFile.setRootElement(rootElement); | |
| 113 | + // pretty print format | |
| 114 | + XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); | |
| 115 | + | |
| 116 | + // output to console | |
| 117 | + this.fileOutputStream = new FileOutputStream(this.queueInfo.getReadXMLFileName()); | |
| 118 | + xmlOutputter.output(docFile, fileOutputStream); | |
| 119 | + } | |
| 120 | + | |
| 121 | + public void initQueue() throws Exception { | |
| 122 | + this.headerBuffer = ByteBuffer.allocateDirect(QueueHeaderConfig.QUEUE_HEADER_LENGTH); | |
| 123 | + try { | |
| 124 | + /* 1. 큐경로 초기화 */ | |
| 125 | + initQueuePath(); | |
| 126 | + this.queueInfo.setQueueFileName(this.queuePath + File.separator + this.queueInfo.getQueueName() + ".queue"); | |
| 127 | + File file = new File(this.queueInfo.getQueueFileName()); | |
| 128 | + if (file.exists()) { | |
| 129 | + this.channel = new RandomAccessFile(file, "r").getChannel(); | |
| 130 | + // 파일큐의 헤더 정보를 읽어온다. | |
| 131 | + readHeader(); | |
| 132 | + /* 읽기 큐 XML Load Or Create */ | |
| 133 | + initReadQueue(); | |
| 134 | + } else { | |
| 135 | + throw new Exception(this.queueInfo.getQueueName() + "'s Queue is Not Exists!!"); | |
| 136 | + } | |
| 137 | + } catch(Exception e) { | |
| 138 | + throw e; | |
| 139 | + } finally { | |
| 140 | + //lock.release(); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + protected void readHeader() throws Exception { | |
| 145 | + try { | |
| 146 | + initHeaderBuffer(); | |
| 147 | + this.channel.position(0); | |
| 148 | + this.channel.read(this.headerBuffer); | |
| 149 | + this.headerArray = new byte[QueueHeaderConfig.CREATE_DATE_LENGTH]; | |
| 150 | + // 생성날짜 가져오기 - 생성날짜(10) / 읽은카운트(10) / 쓴카운트(10) | |
| 151 | + this.headerBuffer.position(QueueHeaderConfig.CREATE_DATE_POSITION); | |
| 152 | + this.headerBuffer.get(this.headerArray); | |
| 153 | + this.createDate = (new String(this.headerArray)).trim(); | |
| 154 | + // 쓴 카운트 가져오기 | |
| 155 | + this.headerArray = new byte[QueueHeaderConfig.PUSH_COUNT_LENGTH]; | |
| 156 | + this.headerBuffer.position(QueueHeaderConfig.PUSH_COUNT_POSITION); | |
| 157 | + this.headerBuffer.get(this.headerArray); | |
| 158 | + this.pushCounter = Integer.parseInt((new String(this.headerArray)).trim()); | |
| 159 | + } catch(Exception e) { | |
| 160 | + throw e; | |
| 161 | + } | |
| 162 | + } | |
| 163 | + | |
| 164 | + protected void initHeaderBuffer(){ | |
| 165 | + this.headerBuffer.clear(); | |
| 166 | + for(int loopCnt = 0; loopCnt < QueueHeaderConfig.QUEUE_HEADER_LENGTH; loopCnt++){ | |
| 167 | + this.headerBuffer.put(QueueConstants.SET_DEFAULT_BYTE); | |
| 168 | + } | |
| 169 | + this.headerBuffer.position(0); | |
| 170 | + } | |
| 171 | + | |
| 172 | + public void close() throws IOException { | |
| 173 | + try { | |
| 174 | + if (this.channel != null && this.channel.isOpen()) { | |
| 175 | + channel.close(); | |
| 176 | + } | |
| 177 | + if (this.fileOutputStream != null) { | |
| 178 | + this.fileOutputStream.close(); | |
| 179 | + } | |
| 180 | + } catch(IOException e) { | |
| 181 | + throw e; | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + public BasicMessageDto popMessageFromBuffer() throws IOException, JDOMException, Exception { | |
| 186 | + readHeader(); | |
| 187 | + readPopCounter(); | |
| 188 | + BasicMessageDto messageDto = null; | |
| 189 | + if (this.popCounter < this.pushCounter) { | |
| 190 | + /* Read buffer 초기화 */ | |
| 191 | + initDataBuffer(); | |
| 192 | + /* Read Queue 읽기 */ | |
| 193 | + popBuffer(); | |
| 194 | + /* 메시지 추출 */ | |
| 195 | + messageDto = new BasicMessageDto(); | |
| 196 | + MessageUtil.getBytesForCommonMessage(this.dataBuffer, messageDto); | |
| 197 | + getBytesForExtendMessage(messageDto); | |
| 198 | + /* Pop Counter 증가 및 저장 */ | |
| 199 | + this.popCounter = this.popCounter + 1; | |
| 200 | + writePopCounter(); | |
| 201 | + | |
| 202 | + | |
| 203 | + } | |
| 204 | + | |
| 205 | + return messageDto; | |
| 206 | + } | |
| 207 | + | |
| 208 | + abstract void popBuffer() throws Exception; | |
| 209 | + abstract void getBytesForExtendMessage(BasicMessageDto messageDto); | |
| 210 | + abstract void initDataBuffer(); | |
| 211 | +} |
+++ src/main/java/com/munjaon/server/queue/pool/SmsMemoryQueue.java
... | ... | @@ -0,0 +1,47 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | + | |
| 5 | +import java.util.LinkedList; | |
| 6 | + | |
| 7 | +public class SmsMemoryQueue { | |
| 8 | + /** Lock Object */ | |
| 9 | + private final Object msgMonitor = new Object(); | |
| 10 | + /** Message Queue */ | |
| 11 | + private final LinkedList<BasicMessageDto> msgQueue = new LinkedList<>(); | |
| 12 | + /** Singleton Instance */ | |
| 13 | + private static SmsMemoryQueue memoryQueue; | |
| 14 | + | |
| 15 | + public synchronized static SmsMemoryQueue getInstance() { | |
| 16 | + if(memoryQueue == null){ | |
| 17 | + memoryQueue = new SmsMemoryQueue(); | |
| 18 | + } | |
| 19 | + return memoryQueue; | |
| 20 | + } | |
| 21 | + /** MESSAGE QUEUE ************************************************************************ */ | |
| 22 | + /** MESSAGE enQueue */ | |
| 23 | + public void memoryEnQueue(BasicMessageDto data) { | |
| 24 | + synchronized(msgMonitor) { | |
| 25 | + msgQueue.addLast(data); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + /** SMS deQueue */ | |
| 29 | + public BasicMessageDto memoryDeQueue() { | |
| 30 | + synchronized(msgMonitor) { | |
| 31 | + if(msgQueue.isEmpty()) return null; | |
| 32 | + else return msgQueue.removeFirst(); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + /** SMS size */ | |
| 36 | + public int getMemorySize(){ | |
| 37 | + synchronized(msgMonitor) { | |
| 38 | + return msgQueue.size(); | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** SMS isEmpty */ | |
| 42 | + public boolean isMemoryEmpty() { | |
| 43 | + synchronized(msgMonitor) { | |
| 44 | + return msgQueue.isEmpty(); | |
| 45 | + } | |
| 46 | + } | |
| 47 | +} |
+++ src/main/java/com/munjaon/server/queue/pool/SmsReadQueue.java
... | ... | @@ -0,0 +1,39 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.config.QueueConstants; | |
| 4 | +import com.munjaon.server.queue.config.SmsBodyConfig; | |
| 5 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 6 | +import com.munjaon.server.queue.dto.QueueInfo; | |
| 7 | +import com.munjaon.server.util.MessageUtil; | |
| 8 | + | |
| 9 | +import java.nio.ByteBuffer; | |
| 10 | + | |
| 11 | +public class SmsReadQueue extends ReadQueue { | |
| 12 | + public SmsReadQueue(QueueInfo queueInfo) throws Exception { | |
| 13 | + this.queueInfo = queueInfo; | |
| 14 | +// initQueue(); | |
| 15 | + } | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + void popBuffer() throws Exception { | |
| 19 | + this.channel.position(MessageUtil.calcReadPosition(this.popCounter, SmsBodyConfig.SMS_SUM_BYTE_LENGTH)); | |
| 20 | + this.channel.read(this.dataBuffer); | |
| 21 | + } | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + void getBytesForExtendMessage(BasicMessageDto messageDto) { | |
| 25 | + MessageUtil.getBytesForSmsMessage(this.dataBuffer, messageDto); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + void initDataBuffer() { | |
| 30 | + if (this.dataBuffer == null) { | |
| 31 | + this.dataBuffer = ByteBuffer.allocateDirect(SmsBodyConfig.SMS_SUM_BYTE_LENGTH); | |
| 32 | + } | |
| 33 | + this.dataBuffer.clear(); | |
| 34 | + for(int loopCnt = 0; loopCnt < SmsBodyConfig.SMS_SUM_BYTE_LENGTH; loopCnt++){ | |
| 35 | + this.dataBuffer.put(QueueConstants.SET_DEFAULT_BYTE); | |
| 36 | + } | |
| 37 | + this.dataBuffer.position(0); | |
| 38 | + } | |
| 39 | +} |
--- src/main/java/com/munjaon/server/queue/pool/SmsWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/pool/SmsWriteQueue.java
... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 |
public SmsWriteQueue(QueueInfo queueInfo) throws Exception {
|
| 14 | 14 |
this.queueInfo = queueInfo; |
| 15 | 15 |
/* 큐초기화 */ |
| 16 |
- initQueue(); |
|
| 16 |
+// initQueue(); |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
@Override |
--- src/main/java/com/munjaon/server/queue/pool/WriteQueue.java
+++ src/main/java/com/munjaon/server/queue/pool/WriteQueue.java
... | ... | @@ -6,6 +6,8 @@ |
| 6 | 6 |
import com.munjaon.server.queue.config.QueueHeaderConfig; |
| 7 | 7 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 8 | 8 |
import com.munjaon.server.queue.dto.QueueInfo; |
| 9 |
+import com.munjaon.server.util.FileUtil; |
|
| 10 |
+import com.munjaon.server.util.JobFileFactory; |
|
| 9 | 11 |
import com.munjaon.server.util.MessageUtil; |
| 10 | 12 |
import lombok.Getter; |
| 11 | 13 |
|
... | ... | @@ -29,6 +31,10 @@ |
| 29 | 31 |
@Getter |
| 30 | 32 |
protected int pushCounter = 0; |
| 31 | 33 |
|
| 34 |
+ /* 큐경로 */ |
|
| 35 |
+ @Getter |
|
| 36 |
+ protected String queuePath; |
|
| 37 |
+ |
|
| 32 | 38 |
/** Queue File Channel */ |
| 33 | 39 |
protected FileChannel channel = null; |
| 34 | 40 |
/** Queue Information */ |
... | ... | @@ -37,12 +43,21 @@ |
| 37 | 43 |
/** pushBuffer() 함수에서 사용하는 변수 */ |
| 38 | 44 |
protected ByteBuffer dataBuffer = null; |
| 39 | 45 |
|
| 40 |
- protected void initQueue() throws Exception {
|
|
| 46 |
+ protected void initQueuePath() {
|
|
| 47 |
+ /* 1. 큐경로 */ |
|
| 48 |
+ this.queuePath = System.getProperty("ROOTPATH") + File.separator + queueInfo.getQueuePath();
|
|
| 49 |
+ /* 2. 경로 체크 및 생성 */ |
|
| 50 |
+ FileUtil.mkdirs(this.queuePath); |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ public void initQueue() throws Exception {
|
|
| 41 | 54 |
this.headerBuffer = ByteBuffer.allocateDirect(QueueHeaderConfig.QUEUE_HEADER_LENGTH); |
| 42 | 55 |
try{
|
| 56 |
+ /* 1. 큐경로 초기화 */ |
|
| 57 |
+ initQueuePath(); |
|
| 58 |
+ this.queueInfo.setQueueFileName(this.queuePath + File.separator + this.queueInfo.getQueueName() + ".queue"); |
|
| 43 | 59 |
File file = new File(this.queueInfo.getQueueFileName()); |
| 44 | 60 |
this.channel = new RandomAccessFile(file, "rw").getChannel(); |
| 45 |
- //this.lock = this.channel.lock(); |
|
| 46 | 61 |
|
| 47 | 62 |
if (file.length() == 0) {
|
| 48 | 63 |
// Push 및 Pop 카운트 초기화 |
... | ... | @@ -53,12 +68,21 @@ |
| 53 | 68 |
} else {
|
| 54 | 69 |
readHeader(); |
| 55 | 70 |
} |
| 56 |
- }catch(Exception e){
|
|
| 71 |
+// backupQueue(); |
|
| 72 |
+ } catch(Exception e) {
|
|
| 57 | 73 |
throw e; |
| 58 | 74 |
} finally {
|
| 59 | 75 |
//lock.release(); |
| 60 | 76 |
} |
| 61 | 77 |
} |
| 78 |
+ |
|
| 79 |
+ public void backupQueue() throws IOException {
|
|
| 80 |
+ /* 1. 백업경로 */ |
|
| 81 |
+ String backupDir = this.queuePath + File.separator + "backup" + File.separator + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
| 82 |
+ /* 2. 파일 백업 */ |
|
| 83 |
+ JobFileFactory.transferFile(this.queuePath, this.queueInfo.getQueueName() + ".queue", backupDir, this.queueInfo.getQueueName() + ".queue"); |
|
| 84 |
+ } |
|
| 85 |
+ |
|
| 62 | 86 |
|
| 63 | 87 |
protected void readHeader() throws Exception {
|
| 64 | 88 |
try {
|
... | ... | @@ -102,7 +126,7 @@ |
| 102 | 126 |
this.headerBuffer.position(0); |
| 103 | 127 |
} |
| 104 | 128 |
|
| 105 |
- protected void close() throws IOException {
|
|
| 129 |
+ public void close() throws IOException {
|
|
| 106 | 130 |
try {
|
| 107 | 131 |
if (isOpen()) {
|
| 108 | 132 |
channel.close(); |
... | ... | @@ -120,7 +144,7 @@ |
| 120 | 144 |
return this.channel.isOpen(); |
| 121 | 145 |
} |
| 122 | 146 |
|
| 123 |
- protected void truncateQueue() throws Exception{
|
|
| 147 |
+ public void truncateQueue() throws Exception{
|
|
| 124 | 148 |
try {
|
| 125 | 149 |
/* 1. 날짜가 지난경우와 더이상 읽을 데이터가 없을 경우 큐를 초기화 */ |
| 126 | 150 |
String thisDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
... | ... | @@ -213,7 +237,7 @@ |
| 213 | 237 |
return ServiceCode.OK.getCode(); |
| 214 | 238 |
} |
| 215 | 239 |
|
| 216 |
- abstract int isValidateMessageForExtend(BasicMessageDto messageDto); |
|
| 217 |
- abstract void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception; |
|
| 218 |
- abstract void initDataBuffer(); |
|
| 240 |
+ public abstract int isValidateMessageForExtend(BasicMessageDto messageDto); |
|
| 241 |
+ public abstract void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception; |
|
| 242 |
+ public abstract void initDataBuffer(); |
|
| 219 | 243 |
} |
--- src/main/java/com/munjaon/server/queue/service/KakaoAlarmQueueService.java
+++ src/main/java/com/munjaon/server/queue/service/KakaoAlarmQueueService.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import com.munjaon.server.queue.pool.KakaoAlarmMemoryQueue; |
|
| 4 | 5 |
import com.munjaon.server.queue.pool.WriteQueue; |
| 5 | 6 |
import lombok.RequiredArgsConstructor; |
| 6 | 7 |
import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -10,6 +11,7 @@ |
| 10 | 11 |
@Service |
| 11 | 12 |
@RequiredArgsConstructor |
| 12 | 13 |
public class KakaoAlarmQueueService implements QueueAction {
|
| 14 |
+ private final KakaoAlarmMemoryQueue memoryQueue = KakaoAlarmMemoryQueue.getInstance(); |
|
| 13 | 15 |
@Override |
| 14 | 16 |
public boolean isExistQueue(String name) {
|
| 15 | 17 |
return false; |
... | ... | @@ -34,4 +36,24 @@ |
| 34 | 36 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 35 | 37 |
return 0; |
| 36 | 38 |
} |
| 39 |
+ |
|
| 40 |
+ @Override |
|
| 41 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 42 |
+ memoryQueue.memoryEnQueue(data); |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ @Override |
|
| 46 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 47 |
+ return memoryQueue.memoryDeQueue(); |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ @Override |
|
| 51 |
+ public int getMemorySize() {
|
|
| 52 |
+ return memoryQueue.getMemorySize(); |
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ @Override |
|
| 56 |
+ public boolean isMemoryEmpty() {
|
|
| 57 |
+ return memoryQueue.isMemoryEmpty(); |
|
| 58 |
+ } |
|
| 37 | 59 |
} |
--- src/main/java/com/munjaon/server/queue/service/KakaoFriendQueueService.java
+++ src/main/java/com/munjaon/server/queue/service/KakaoFriendQueueService.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import com.munjaon.server.queue.pool.KakaoAlarmMemoryQueue; |
|
| 4 | 5 |
import com.munjaon.server.queue.pool.WriteQueue; |
| 5 | 6 |
import lombok.RequiredArgsConstructor; |
| 6 | 7 |
import lombok.extern.slf4j.Slf4j; |
... | ... | @@ -10,6 +11,7 @@ |
| 10 | 11 |
@Service |
| 11 | 12 |
@RequiredArgsConstructor |
| 12 | 13 |
public class KakaoFriendQueueService implements QueueAction {
|
| 14 |
+ private final KakaoAlarmMemoryQueue memoryQueue = KakaoAlarmMemoryQueue.getInstance(); |
|
| 13 | 15 |
@Override |
| 14 | 16 |
public boolean isExistQueue(String name) {
|
| 15 | 17 |
return false; |
... | ... | @@ -34,4 +36,24 @@ |
| 34 | 36 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 35 | 37 |
return 0; |
| 36 | 38 |
} |
| 39 |
+ |
|
| 40 |
+ @Override |
|
| 41 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 42 |
+ memoryQueue.memoryEnQueue(data); |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ @Override |
|
| 46 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 47 |
+ return memoryQueue.memoryDeQueue(); |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ @Override |
|
| 51 |
+ public int getMemorySize() {
|
|
| 52 |
+ return memoryQueue.getMemorySize(); |
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ @Override |
|
| 56 |
+ public boolean isMemoryEmpty() {
|
|
| 57 |
+ return memoryQueue.isMemoryEmpty(); |
|
| 58 |
+ } |
|
| 37 | 59 |
} |
--- src/main/java/com/munjaon/server/queue/service/LmsQueueService.java
+++ src/main/java/com/munjaon/server/queue/service/LmsQueueService.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import com.munjaon.server.queue.pool.LmsMemoryQueue; |
|
| 4 | 5 |
import com.munjaon.server.queue.pool.LmsQueuePool; |
| 5 | 6 |
import com.munjaon.server.queue.pool.WriteQueue; |
| 6 | 7 |
import lombok.RequiredArgsConstructor; |
... | ... | @@ -12,6 +13,7 @@ |
| 12 | 13 |
@RequiredArgsConstructor |
| 13 | 14 |
public class LmsQueueService implements QueueAction {
|
| 14 | 15 |
private final LmsQueuePool queueInstance = LmsQueuePool.getInstance(); |
| 16 |
+ private final LmsMemoryQueue memoryQueue = LmsMemoryQueue.getInstance(); |
|
| 15 | 17 |
|
| 16 | 18 |
@Override |
| 17 | 19 |
public boolean isExistQueue(String name) {
|
... | ... | @@ -46,4 +48,24 @@ |
| 46 | 48 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 47 | 49 |
return 0; |
| 48 | 50 |
} |
| 51 |
+ |
|
| 52 |
+ @Override |
|
| 53 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 54 |
+ memoryQueue.memoryEnQueue(data); |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ @Override |
|
| 58 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 59 |
+ return memoryQueue.memoryDeQueue(); |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ @Override |
|
| 63 |
+ public int getMemorySize() {
|
|
| 64 |
+ return memoryQueue.getMemorySize(); |
|
| 65 |
+ } |
|
| 66 |
+ |
|
| 67 |
+ @Override |
|
| 68 |
+ public boolean isMemoryEmpty() {
|
|
| 69 |
+ return memoryQueue.isMemoryEmpty(); |
|
| 70 |
+ } |
|
| 49 | 71 |
} |
--- src/main/java/com/munjaon/server/queue/service/MmsQueueService.java
+++ src/main/java/com/munjaon/server/queue/service/MmsQueueService.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import com.munjaon.server.queue.pool.MmsMemoryQueue; |
|
| 4 | 5 |
import com.munjaon.server.queue.pool.MmsQueuePool; |
| 5 | 6 |
import com.munjaon.server.queue.pool.WriteQueue; |
| 6 | 7 |
import lombok.RequiredArgsConstructor; |
... | ... | @@ -12,6 +13,7 @@ |
| 12 | 13 |
@RequiredArgsConstructor |
| 13 | 14 |
public class MmsQueueService implements QueueAction {
|
| 14 | 15 |
private final MmsQueuePool queueInstance = MmsQueuePool.getInstance(); |
| 16 |
+ private final MmsMemoryQueue memoryQueue = MmsMemoryQueue.getInstance(); |
|
| 15 | 17 |
@Override |
| 16 | 18 |
public boolean isExistQueue(String name) {
|
| 17 | 19 |
return queueInstance.isExistQueue(name); |
... | ... | @@ -45,4 +47,24 @@ |
| 45 | 47 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 46 | 48 |
return 0; |
| 47 | 49 |
} |
| 50 |
+ |
|
| 51 |
+ @Override |
|
| 52 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 53 |
+ memoryQueue.memoryEnQueue(data); |
|
| 54 |
+ } |
|
| 55 |
+ |
|
| 56 |
+ @Override |
|
| 57 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 58 |
+ return memoryQueue.memoryDeQueue(); |
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ @Override |
|
| 62 |
+ public int getMemorySize() {
|
|
| 63 |
+ return memoryQueue.getMemorySize(); |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 66 |
+ @Override |
|
| 67 |
+ public boolean isMemoryEmpty() {
|
|
| 68 |
+ return memoryQueue.isMemoryEmpty(); |
|
| 69 |
+ } |
|
| 48 | 70 |
} |
--- src/main/java/com/munjaon/server/queue/service/QueueAction.java
+++ src/main/java/com/munjaon/server/queue/service/QueueAction.java
... | ... | @@ -9,4 +9,9 @@ |
| 9 | 9 |
void addQueue(WriteQueue queue); |
| 10 | 10 |
void pushQueue(BasicMessageDto data); |
| 11 | 11 |
int saveMessageToTable(BasicMessageDto data); |
| 12 |
+ |
|
| 13 |
+ void memoryEnQueue(BasicMessageDto data); |
|
| 14 |
+ BasicMessageDto memoryDeQueue(); |
|
| 15 |
+ int getMemorySize(); |
|
| 16 |
+ boolean isMemoryEmpty(); |
|
| 12 | 17 |
} |
--- src/main/java/com/munjaon/server/queue/service/ReadQueue.java
... | ... | @@ -1,197 +0,0 @@ |
| 1 | -package com.munjaon.server.queue.service; | |
| 2 | - | |
| 3 | -import com.munjaon.server.queue.dto.QueueInfo; | |
| 4 | - | |
| 5 | -import java.nio.ByteBuffer; | |
| 6 | -import java.nio.channels.FileChannel; | |
| 7 | - | |
| 8 | -public class ReadQueue { | |
| 9 | - /** Queue Header Size - [Create Date:10 Byte, Push Count:10 Byte] */ | |
| 10 | - private static final int QUEUE_HEADER_LENGTH = 20; | |
| 11 | - /** Queue Create Date - [Format:YYYYMMDD] */ | |
| 12 | - private String createDate = ""; | |
| 13 | - /** Queue Pop Counter */ | |
| 14 | - private int popCounter = 0; | |
| 15 | - /** Queue Push Counter */ | |
| 16 | - private int pushCounter = 0; | |
| 17 | - /** XML 읽은 날짜 */ | |
| 18 | - private String readXMLDate = ""; | |
| 19 | - /** Queue Header Buffer */ | |
| 20 | - private ByteBuffer headerBuffer = null; | |
| 21 | - /** Queue Data Read Buffer */ | |
| 22 | - private ByteBuffer readBuffer = null; | |
| 23 | - /** Queue Information */ | |
| 24 | - private QueueInfo queueInfo = null; | |
| 25 | - /** Queue File Channel */ | |
| 26 | - private FileChannel channel = null; | |
| 27 | - /** Header 에서 사용하는 변수 */ | |
| 28 | - byte[] headerArray = null; | |
| 29 | - | |
| 30 | - /** XML Control */ | |
| 31 | -// private Document document = null; // XML Document | |
| 32 | -// private Element rootElement = null; | |
| 33 | -// private Element childElement = null; | |
| 34 | -// private final Format format = Format.getPrettyFormat(); | |
| 35 | -// private XMLOutputter outputter = null; | |
| 36 | -// private FileWriter fileWriter = null; | |
| 37 | -// | |
| 38 | -// public ReadQueue(QueueInfo info) throws Exception{ | |
| 39 | -// this.queueInfo = info; | |
| 40 | -// this.headerBuffer = ByteBuffer.allocateDirect(this.QUEUE_HEADER_LENGTH); | |
| 41 | -// this.readBuffer = ByteBuffer.allocateDirect(this.queueInfo.getQueueDataLength()); | |
| 42 | -// try{ | |
| 43 | -// File file = new File(this.queueInfo.getQueueFileName()); | |
| 44 | -// if(file.exists()){ | |
| 45 | -// this.channel = new RandomAccessFile(file, "r").getChannel(); | |
| 46 | -// // 파일큐의 헤더 정보를 읽어온다. | |
| 47 | -// readHeader(); | |
| 48 | -// // XML Write Formater | |
| 49 | -// this.format.setEncoding("EUC-KR"); | |
| 50 | -// this.format.setIndent("\t"); | |
| 51 | -// | |
| 52 | -// // 해당큐를 읽은 PopCounter 정보를 가져온다. | |
| 53 | -// file = new File(this.queueInfo.getReadXMLFileName()); | |
| 54 | -// if(file.exists()){ | |
| 55 | -// readPopCounter(); | |
| 56 | -// }else{ | |
| 57 | -// this.readXMLDate = MessageUtil.currentDay(); | |
| 58 | -// this.popCounter = 0; | |
| 59 | -// writePopCounter(); | |
| 60 | -// } | |
| 61 | -// }else{ | |
| 62 | -// throw new Exception(this.queueInfo.getQueueName() + "'s Queue is Not Exists!!"); | |
| 63 | -// } | |
| 64 | -// | |
| 65 | -// }catch(Exception e){ | |
| 66 | -// throw e; | |
| 67 | -// } | |
| 68 | -// } | |
| 69 | -// public ByteBuffer popBuffer() throws Exception{ | |
| 70 | -// try { | |
| 71 | -// readHeader(); | |
| 72 | -// readPopCounter(); | |
| 73 | -// | |
| 74 | -// if(this.popCounter == this.pushCounter){ | |
| 75 | -// // 더이상 읽을 데이터가 없는 경우 | |
| 76 | -// return null; | |
| 77 | -// }else{ | |
| 78 | -// initReadBuffer(); | |
| 79 | -// this.channel.position(QUEUE_HEADER_LENGTH + (this.queueInfo.getQueueDataLength() * this.popCounter)); | |
| 80 | -// this.channel.read(this.readBuffer); | |
| 81 | -// this.popCounter = this.popCounter + 1; | |
| 82 | -// // Header 정보 변경 | |
| 83 | -// writePopCounter(); | |
| 84 | -// | |
| 85 | -// return this.readBuffer; | |
| 86 | -// } | |
| 87 | -// } catch(Exception e) { | |
| 88 | -// throw e; | |
| 89 | -// } | |
| 90 | -// } | |
| 91 | -// public void readPopCounter() throws Exception{ | |
| 92 | -// try { | |
| 93 | -// this.document = new SAXBuilder().build(this.queueInfo.getReadXMLFileName()); | |
| 94 | -// this.rootElement = this.document.getRootElement(); | |
| 95 | -// this.readXMLDate = this.rootElement.getChild("createDate").getText().trim(); | |
| 96 | -// this.popCounter = Integer.parseInt(this.rootElement.getChild("PopCounter").getText().trim()); | |
| 97 | -// } catch(Exception e) { | |
| 98 | -// throw e; | |
| 99 | -// } | |
| 100 | -// } | |
| 101 | -// public void writePopCounter() throws Exception{ | |
| 102 | -// try { | |
| 103 | -// // Root Element | |
| 104 | -// this.rootElement = new Element("ReadQueue"); | |
| 105 | -// // 생성날짜 | |
| 106 | -// this.childElement = new Element("createDate"); | |
| 107 | -// this.childElement.setText(this.readXMLDate); | |
| 108 | -// this.rootElement.addContent(this.childElement); | |
| 109 | -// // 읽은 카운트 | |
| 110 | -// this.childElement = new Element("PopCounter"); | |
| 111 | -// this.childElement.setText(Integer.toString(this.popCounter)); | |
| 112 | -// this.rootElement.addContent(this.childElement); | |
| 113 | -// | |
| 114 | -// this.document = new Document(this.rootElement); | |
| 115 | -// this.outputter = new XMLOutputter(); | |
| 116 | -// this.outputter.setFormat(this.format); | |
| 117 | -// this.fileWriter = new FileWriter(this.queueInfo.getReadXMLFileName()); | |
| 118 | -// this.outputter.output(this.document, this.fileWriter); | |
| 119 | -// } catch(Exception e) { | |
| 120 | -// throw e; | |
| 121 | -// }finally{ | |
| 122 | -// if(this.fileWriter != null){this.fileWriter.close(); this.fileWriter = null; } | |
| 123 | -// } | |
| 124 | -// } | |
| 125 | -// public void initPopCounter() throws Exception{ | |
| 126 | -// try { | |
| 127 | -// initHeaderBuffer(); | |
| 128 | -// // 데이터 초기화 | |
| 129 | -// this.readXMLDate = MessageUtil.currentDay(); | |
| 130 | -// this.popCounter = 0; | |
| 131 | -// | |
| 132 | -// writePopCounter(); | |
| 133 | -// } catch(Exception e) { | |
| 134 | -// throw e; | |
| 135 | -// } | |
| 136 | -// } | |
| 137 | -// public void readHeader() throws Exception { | |
| 138 | -// try { | |
| 139 | -// initHeaderBuffer(); | |
| 140 | -// this.channel.position(0); | |
| 141 | -// this.channel.read(this.headerBuffer); | |
| 142 | -// this.headerArray = new byte[10]; | |
| 143 | -// // 생성날짜 가져오기 - 생성날짜(10) / 쓴카운트(10) | |
| 144 | -// this.headerBuffer.position(0); | |
| 145 | -// this.headerBuffer.get(this.headerArray); | |
| 146 | -// this.createDate = (new String(this.headerArray)).trim(); | |
| 147 | -// // 쓴 카운트 가져오기 | |
| 148 | -// this.headerArray = new byte[10]; | |
| 149 | -// this.headerBuffer.position(10); | |
| 150 | -// this.headerBuffer.get(this.headerArray); | |
| 151 | -// this.pushCounter = Integer.parseInt((new String(this.headerArray)).trim()); | |
| 152 | -// } catch(Exception e) { | |
| 153 | -// throw e; | |
| 154 | -// } | |
| 155 | -// } | |
| 156 | -// public void close() throws IOException { | |
| 157 | -// try { | |
| 158 | -// if(channel != null && channel.isOpen()) { | |
| 159 | -// channel.close(); | |
| 160 | -// } | |
| 161 | -// } catch(IOException e) { | |
| 162 | -// throw e; | |
| 163 | -// } | |
| 164 | -// } | |
| 165 | -// public void initHeaderBuffer(){ | |
| 166 | -// this.headerBuffer.clear(); | |
| 167 | -// for(int loopCnt=0;loopCnt<this.QUEUE_HEADER_LENGTH;loopCnt++){ | |
| 168 | -// this.headerBuffer.put(QueueVariable.SET_DEFAULT_BYTE); | |
| 169 | -// } | |
| 170 | -// this.headerBuffer.position(0); | |
| 171 | -// } | |
| 172 | -// public void initReadBuffer(){ | |
| 173 | -// this.readBuffer.clear(); | |
| 174 | -// for(int loopCnt=0;loopCnt<this.queueInfo.getQueueDataLength();loopCnt++){ | |
| 175 | -// this.readBuffer.put(QueueVariable.SET_DEFAULT_BYTE); | |
| 176 | -// } | |
| 177 | -// this.readBuffer.position(0); | |
| 178 | -// } | |
| 179 | -// public String getQueueName(){ | |
| 180 | -// if(this.queueInfo == null) | |
| 181 | -// return null; | |
| 182 | -// else | |
| 183 | -// return this.queueInfo.getQueueName(); | |
| 184 | -// } | |
| 185 | -// public String getCreateDate() { | |
| 186 | -// return createDate; | |
| 187 | -// } | |
| 188 | -// public String getReadXMLDate() { | |
| 189 | -// return readXMLDate; | |
| 190 | -// } | |
| 191 | -// public int getPushCounter() { | |
| 192 | -// return pushCounter; | |
| 193 | -// } | |
| 194 | -// public int getPopCounter() { | |
| 195 | -// return popCounter; | |
| 196 | -// } | |
| 197 | -} |
--- src/main/java/com/munjaon/server/queue/service/SmsQueueService.java
+++ src/main/java/com/munjaon/server/queue/service/SmsQueueService.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 | 3 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 4 |
+import com.munjaon.server.queue.pool.SmsMemoryQueue; |
|
| 4 | 5 |
import com.munjaon.server.queue.pool.SmsQueuePool; |
| 5 | 6 |
import com.munjaon.server.queue.pool.WriteQueue; |
| 6 | 7 |
import lombok.RequiredArgsConstructor; |
... | ... | @@ -12,6 +13,7 @@ |
| 12 | 13 |
@RequiredArgsConstructor |
| 13 | 14 |
public class SmsQueueService implements QueueAction {
|
| 14 | 15 |
private final SmsQueuePool queueInstance = SmsQueuePool.getInstance(); |
| 16 |
+ private final SmsMemoryQueue memoryQueue = SmsMemoryQueue.getInstance(); |
|
| 15 | 17 |
|
| 16 | 18 |
@Override |
| 17 | 19 |
public boolean isExistQueue(String name) {
|
... | ... | @@ -44,6 +46,27 @@ |
| 44 | 46 |
|
| 45 | 47 |
@Override |
| 46 | 48 |
public int saveMessageToTable(BasicMessageDto data) {
|
| 49 |
+ log.debug("Save message to table : {}", data);
|
|
| 47 | 50 |
return 0; |
| 48 | 51 |
} |
| 52 |
+ |
|
| 53 |
+ @Override |
|
| 54 |
+ public void memoryEnQueue(BasicMessageDto data) {
|
|
| 55 |
+ memoryQueue.memoryEnQueue(data); |
|
| 56 |
+ } |
|
| 57 |
+ |
|
| 58 |
+ @Override |
|
| 59 |
+ public BasicMessageDto memoryDeQueue() {
|
|
| 60 |
+ return memoryQueue.memoryDeQueue(); |
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ @Override |
|
| 64 |
+ public int getMemorySize() {
|
|
| 65 |
+ return memoryQueue.getMemorySize(); |
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ @Override |
|
| 69 |
+ public boolean isMemoryEmpty() {
|
|
| 70 |
+ return memoryQueue.isMemoryEmpty(); |
|
| 71 |
+ } |
|
| 49 | 72 |
} |
--- src/main/java/com/munjaon/server/server/service/QueueServerService.java
+++ src/main/java/com/munjaon/server/server/service/QueueServerService.java
... | ... | @@ -1,19 +1,51 @@ |
| 1 | 1 |
package com.munjaon.server.server.service; |
| 2 | 2 |
|
| 3 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 4 |
+import com.munjaon.server.queue.enums.QueueTypeWorker; |
|
| 5 |
+import com.munjaon.server.queue.pool.ReadQueue; |
|
| 6 |
+import com.munjaon.server.queue.pool.WriteQueue; |
|
| 7 |
+import com.munjaon.server.util.CommonUtil; |
|
| 8 |
+import com.munjaon.server.util.ServiceUtil; |
|
| 3 | 9 |
import org.json.simple.JSONObject; |
| 4 | 10 |
|
| 5 |
-import java.util.HashMap; |
|
| 6 |
-import java.util.Map; |
|
| 11 |
+import java.io.IOException; |
|
| 12 |
+import java.time.LocalDateTime; |
|
| 13 |
+import java.time.format.DateTimeFormatter; |
|
| 7 | 14 |
|
| 8 | 15 |
public class QueueServerService extends Service {
|
| 9 |
- private int SMS_QUEUE_SIZE = 0; |
|
| 10 |
- private int LMS_QUEUE_SIZE = 0; |
|
| 11 |
- private int MMS_QUEUE_SIZE = 0; |
|
| 12 |
- private int KAT_QUEUE_SIZE = 0; |
|
| 13 |
- private int KFT_QUEUE_SIZE = 0; |
|
| 16 |
+ /** 큐모드 설정(WAIT : 파일에 쓰기모드만 / DB : DB에 적재) */ |
|
| 17 |
+ private String QUEUE_MODE = null; |
|
| 18 |
+ /** 큐모드 설정 모니터링(10초단위로 체크한다.) */ |
|
| 19 |
+ private long QUEUE_MODE_CHECK_TIME = 0; |
|
| 20 |
+ /** 큐 초기화 모니터링(1분단위로 체크한다.) 및 초기화 여부 */ |
|
| 21 |
+ private long QUEUE_INIT_CHECK_TIME = 0; |
|
| 22 |
+ /** Commit 누적 카운트 */ |
|
| 23 |
+ private long SUM_COMMIT_COUNT = 0; |
|
| 24 |
+ /* 쓰기큐 */ |
|
| 25 |
+ private WriteQueue writeQueue; |
|
| 26 |
+ private ReadQueue readQueue; |
|
| 27 |
+ private QueueTypeWorker worker; |
|
| 28 |
+ public QueueServerService(String serviceName, WriteQueue writeQueue, ReadQueue readQueue) {
|
|
| 29 |
+ super(serviceName); |
|
| 30 |
+ this.writeQueue = writeQueue; |
|
| 31 |
+ this.readQueue = readQueue; |
|
| 32 |
+ this.worker = QueueTypeWorker.find(writeQueue.getQueueInfo().getServiceType()); |
|
| 33 |
+ if (this.worker == null) {
|
|
| 34 |
+ throw new RuntimeException("No worker found for " + writeQueue.getQueueInfo().getServiceType());
|
|
| 35 |
+ } |
|
| 36 |
+ } |
|
| 14 | 37 |
|
| 15 |
- private Map<String, String> queueConfigMap = new HashMap<String, String>(); |
|
| 16 |
- |
|
| 38 |
+ /** 큐모드 설정(WAIT : 파일에 쓰기모드만 / DB : DB에 적재) */ |
|
| 39 |
+ public void checkMode(){
|
|
| 40 |
+ if((System.currentTimeMillis() - QUEUE_MODE_CHECK_TIME) > 10000){
|
|
| 41 |
+ QUEUE_MODE = PropertyLoader.get("COMMON.QUEUE_MODE");
|
|
| 42 |
+ // 예외체크 |
|
| 43 |
+ if(QUEUE_MODE == null) QUEUE_MODE = "DB"; |
|
| 44 |
+ QUEUE_MODE = QUEUE_MODE.toUpperCase(); |
|
| 45 |
+ // 읽은 시간 업데이트 |
|
| 46 |
+ QUEUE_MODE_CHECK_TIME = System.currentTimeMillis(); |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 17 | 49 |
|
| 18 | 50 |
@Override |
| 19 | 51 |
public void checkReady() {
|
... | ... | @@ -22,17 +54,172 @@ |
| 22 | 54 |
|
| 23 | 55 |
@Override |
| 24 | 56 |
public void initResources() {
|
| 25 |
- SMS_QUEUE_SIZE = |
|
| 57 |
+ // 큐모드 정보를 읽어온다. |
|
| 58 |
+ QUEUE_MODE = getProp("COMMON", "QUEUE_MODE");
|
|
| 59 |
+ if (QUEUE_MODE == null) {
|
|
| 60 |
+ QUEUE_MODE = "DB"; // 예외체크 |
|
| 61 |
+ } |
|
| 62 |
+ |
|
| 63 |
+ try {
|
|
| 64 |
+ if (isRun()) {
|
|
| 65 |
+ /* 쓰기 큐 */ |
|
| 66 |
+ writeQueue.initQueue(); |
|
| 67 |
+ /* 읽기 큐 */ |
|
| 68 |
+ readQueue.initQueue(); |
|
| 69 |
+ /* 큐 초기화 */ |
|
| 70 |
+ initQueue(); |
|
| 71 |
+ /* 큐 pool에 등록 */ |
|
| 72 |
+ worker.addQueue(writeQueue); |
|
| 73 |
+ /* 메모리큐에서 다시 적재하기 */ |
|
| 74 |
+ loadMemoryQueue(); |
|
| 75 |
+ } |
|
| 76 |
+ } catch (Exception e) {
|
|
| 77 |
+ throw new RuntimeException(e); |
|
| 78 |
+ } |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ private void initQueue() throws Exception {
|
|
| 82 |
+ boolean isQueueInit = false; // 큐 초기화 여부 |
|
| 83 |
+ String writeQueueCreateDate = writeQueue.getCreateDate(); |
|
| 84 |
+ String readQueueCreateDate = readQueue.getReadXMLDate(); |
|
| 85 |
+ String thisDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
| 86 |
+ |
|
| 87 |
+ if (readQueueCreateDate.equals(readQueueCreateDate)) {
|
|
| 88 |
+ if (thisDate.equals(writeQueueCreateDate)) {
|
|
| 89 |
+ isQueueInit = false; |
|
| 90 |
+ } else {
|
|
| 91 |
+ String preDate = CommonUtil.getTargetDay(-24); |
|
| 92 |
+ // 하루전이면 남은 큐데이터를 DB 처리한다. |
|
| 93 |
+ if (writeQueueCreateDate.equals(preDate)) {
|
|
| 94 |
+ while (true) {
|
|
| 95 |
+ BasicMessageDto messageDto = readQueue.popMessageFromBuffer(); |
|
| 96 |
+ if (messageDto == null) {
|
|
| 97 |
+ break; |
|
| 98 |
+ } else {
|
|
| 99 |
+ worker.memoryEnQueue(messageDto); |
|
| 100 |
+ } |
|
| 101 |
+ } |
|
| 102 |
+ isQueueInit = true; |
|
| 103 |
+ } else {
|
|
| 104 |
+ isQueueInit = true; |
|
| 105 |
+ } |
|
| 106 |
+ } |
|
| 107 |
+ } else {
|
|
| 108 |
+ isQueueInit = true; |
|
| 109 |
+ } |
|
| 110 |
+ // 큐초기화 대상이면 |
|
| 111 |
+ if (isQueueInit) {
|
|
| 112 |
+ /* 커밋 카운트 초기화 */ |
|
| 113 |
+ SUM_COMMIT_COUNT = 0; |
|
| 114 |
+ writeQueue.truncateQueue(); |
|
| 115 |
+ readQueue.initPopCounter(); |
|
| 116 |
+ } |
|
| 117 |
+ } |
|
| 118 |
+ |
|
| 119 |
+ private void loadMemoryQueue() throws Exception {
|
|
| 120 |
+ if (worker.getMemorySize() > 0) {
|
|
| 121 |
+ while (true) {
|
|
| 122 |
+ BasicMessageDto messageDto = worker.memoryDeQueue(); |
|
| 123 |
+ if (messageDto == null) {
|
|
| 124 |
+ break; |
|
| 125 |
+ } else {
|
|
| 126 |
+ writeQueue.pushMessageToBuffer(messageDto); |
|
| 127 |
+ } |
|
| 128 |
+ } |
|
| 129 |
+ } |
|
| 130 |
+ } |
|
| 131 |
+ |
|
| 132 |
+ private void checkQueue() throws Exception {
|
|
| 133 |
+ if((System.currentTimeMillis() - QUEUE_INIT_CHECK_TIME) < 60000){
|
|
| 134 |
+ return; |
|
| 135 |
+ } |
|
| 136 |
+ // 큐 초기화 체크시간 업데이트 |
|
| 137 |
+ QUEUE_INIT_CHECK_TIME = System.currentTimeMillis(); |
|
| 138 |
+ // 큐 초기화 여부 |
|
| 139 |
+ boolean isQueueInit = false; |
|
| 140 |
+ // 오늘 날짜 체크 및 큐 생성날짜 저장 |
|
| 141 |
+ String thisDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
| 142 |
+ String writeQueueCreateDate = writeQueue.getCreateDate(); |
|
| 143 |
+ if (writeQueueCreateDate.equals(thisDate)) {
|
|
| 144 |
+ // 아무 처리도 하지 않는다. |
|
| 145 |
+ } else {
|
|
| 146 |
+ /* 큐 pool에서 제거 */ |
|
| 147 |
+ if (worker != null) {
|
|
| 148 |
+ worker.removeQueue(writeQueue.getQueueInfo().getQueueName()); |
|
| 149 |
+ } |
|
| 150 |
+ while(true){
|
|
| 151 |
+ BasicMessageDto messageDto = readQueue.popMessageFromBuffer(); |
|
| 152 |
+ if (messageDto == null) {
|
|
| 153 |
+ break; |
|
| 154 |
+ } else {
|
|
| 155 |
+ worker.memoryEnQueue(messageDto); |
|
| 156 |
+ } |
|
| 157 |
+ } |
|
| 158 |
+ isQueueInit = true; |
|
| 159 |
+ } |
|
| 160 |
+ if (isQueueInit) {
|
|
| 161 |
+ /* 커밋 카운트 초기화 */ |
|
| 162 |
+ SUM_COMMIT_COUNT = 0; |
|
| 163 |
+ // 큐를 초기화한다. |
|
| 164 |
+ writeQueue.truncateQueue(); |
|
| 165 |
+ readQueue.initPopCounter(); |
|
| 166 |
+ /* 큐에 등록 */ |
|
| 167 |
+ worker.addQueue(writeQueue); |
|
| 168 |
+ /* 메모리큐에서 다시 적재하기 */ |
|
| 169 |
+ loadMemoryQueue(); |
|
| 170 |
+ } |
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ private void messageService() throws Exception {
|
|
| 174 |
+ int DB_PROC_COUNT = 0; |
|
| 175 |
+ for (int loopCnt = 0; loopCnt < ServiceUtil.COMMIT_COUNT; loopCnt++) {
|
|
| 176 |
+ BasicMessageDto messageDto = readQueue.popMessageFromBuffer(); |
|
| 177 |
+ if (messageDto == null) {
|
|
| 178 |
+ break; |
|
| 179 |
+ } |
|
| 180 |
+ worker.saveMessageToTable(messageDto); |
|
| 181 |
+ DB_PROC_COUNT++; |
|
| 182 |
+ SUM_COMMIT_COUNT++; |
|
| 183 |
+ } |
|
| 184 |
+ |
|
| 185 |
+ // DB 처리한 카운트에 대한 처리 |
|
| 186 |
+ if (DB_PROC_COUNT > 0) {
|
|
| 187 |
+ Thread.sleep(10); |
|
| 188 |
+ } else {
|
|
| 189 |
+ Thread.sleep(1000); |
|
| 190 |
+ } |
|
| 26 | 191 |
} |
| 27 | 192 |
|
| 28 | 193 |
@Override |
| 29 | 194 |
public void releaseResources() {
|
| 195 |
+ try {
|
|
| 196 |
+ if (writeQueue != null) {
|
|
| 197 |
+ /* 쓰기 Pool에서 제거 */ |
|
| 198 |
+ worker.removeQueue(writeQueue.getQueueInfo().getQueueName()); |
|
| 199 |
+ /* 자원 해제 */ |
|
| 200 |
+ writeQueue.close(); |
|
| 201 |
+ } |
|
| 30 | 202 |
|
| 203 |
+ if (readQueue != null) {
|
|
| 204 |
+ readQueue.close(); |
|
| 205 |
+ } |
|
| 206 |
+ } catch (IOException e) {
|
|
| 207 |
+ throw new RuntimeException(e); |
|
| 208 |
+ } |
|
| 31 | 209 |
} |
| 32 | 210 |
|
| 33 | 211 |
@Override |
| 34 | 212 |
public void doService() {
|
| 35 | 213 |
|
| 214 |
+ while (isRun()) {
|
|
| 215 |
+ try {
|
|
| 216 |
+ checkMode(); |
|
| 217 |
+ checkQueue(); |
|
| 218 |
+ messageService(); |
|
| 219 |
+ } catch (Exception e) {
|
|
| 220 |
+ throw new RuntimeException(e); |
|
| 221 |
+ } |
|
| 222 |
+ } |
|
| 36 | 223 |
} |
| 37 | 224 |
|
| 38 | 225 |
@Override |
--- src/main/java/com/munjaon/server/server/service/Service.java
+++ src/main/java/com/munjaon/server/server/service/Service.java
... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 |
public Service() {}
|
| 25 | 25 |
public Service(String serviceName) {
|
| 26 | 26 |
super(serviceName); |
| 27 |
- LOG_FILE = getProp("LOG_FILE");
|
|
| 27 |
+ LOG_FILE = System.getProperty("ROOTPATH") + getProp("LOG_FILE");
|
|
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 | 30 |
protected String getProp(String name) {
|
... | ... | @@ -92,7 +92,8 @@ |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
protected void initLogFile() {
|
| 95 |
- LOG_FILE = getProp("LOG_FILE");
|
|
| 95 |
+ LOG_FILE = System.getProperty("ROOTPATH") + getProp("LOG_FILE");
|
|
| 96 |
+ System.out.println("LOG_FILE: " + LOG_FILE);
|
|
| 96 | 97 |
setLogFile( LOG_FILE ); |
| 97 | 98 |
saveSystemLog("Service Log Initializing ... ...");
|
| 98 | 99 |
} |
... | ... | @@ -103,9 +104,12 @@ |
| 103 | 104 |
try {
|
| 104 | 105 |
/* 1. 서비스간의 dependency에 따른 체크 */ |
| 105 | 106 |
checkReady(); |
| 107 |
+ /* 2. 로그 초기화 */ |
|
| 108 |
+ initLogFile(); |
|
| 109 |
+ /* 3. Runflag reload */ |
|
| 110 |
+ reloadCheckRun(); |
|
| 111 |
+ |
|
| 106 | 112 |
if (isRun() && isReady()) {
|
| 107 |
- /* 2. 로그 초기화 */ |
|
| 108 |
- initLogFile(); |
|
| 109 | 113 |
/* 3. 서비스 초기화 */ |
| 110 | 114 |
initResources(); |
| 111 | 115 |
/* 4. 서비스 시작 */ |
+++ src/main/java/com/munjaon/server/util/CommonUtil.java
... | ... | @@ -0,0 +1,359 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +import java.text.SimpleDateFormat; | |
| 4 | +import java.text.ParseException; | |
| 5 | +import java.util.Calendar; | |
| 6 | +import java.util.Date; | |
| 7 | + | |
| 8 | +public final class CommonUtil { | |
| 9 | + public static final String DATE_FORMAT_14 = "yyyyMMddHHmmss"; | |
| 10 | + public static final int TIMEOUT_DIVIDE = 1000 * 60; | |
| 11 | + | |
| 12 | + // NewLine 공백처리하기 | |
| 13 | + public static String cutNewLine(String msg){ | |
| 14 | + String encString = ""; | |
| 15 | + if(msg != null){ | |
| 16 | + encString = msg.replaceAll("\r", ""); | |
| 17 | + encString = encString.replaceAll("\n", ""); | |
| 18 | + } | |
| 19 | + return encString; | |
| 20 | + } | |
| 21 | + // NewLine 인코딩 돌리기 | |
| 22 | + public static String encodeNewLine(String msg){ | |
| 23 | + String encString = ""; | |
| 24 | + if(msg != null){ | |
| 25 | + /*encString = msg.replaceAll("\r", "\n"); | |
| 26 | + encString = encString.replaceAll("\n\n", "\n"); | |
| 27 | + encString = encString.replaceAll("\n", "ⓝⓛ");*/ | |
| 28 | + encString = msg.replaceAll("\r", ""); | |
| 29 | + encString = encString.replaceAll("\n", "ⓝⓛ"); | |
| 30 | + } | |
| 31 | + return encString; | |
| 32 | + } | |
| 33 | + // NewLine 디코딩 돌리기 | |
| 34 | + public static String decodeNewLine(String msg){ | |
| 35 | + String encString = ""; | |
| 36 | + if(msg != null){ | |
| 37 | + encString = msg.replaceAll("ⓝⓛ", "\n"); | |
| 38 | + } | |
| 39 | + return encString; | |
| 40 | + } | |
| 41 | + // Comma 인코딩 돌리기 | |
| 42 | + public static String encodeComma(String msg){ | |
| 43 | + String encString = ""; | |
| 44 | + if(msg != null){ | |
| 45 | + encString = msg.replaceAll("\"", "ⓒⓞⓜⓜⓐ"); | |
| 46 | + } | |
| 47 | + return encString; | |
| 48 | + } | |
| 49 | + // Comma 디코딩 돌리기 | |
| 50 | + public static String decodeComma(String msg){ | |
| 51 | + String decString = ""; | |
| 52 | + if(msg != null){ | |
| 53 | + decString = msg.replaceAll("ⓒⓞⓜⓜⓐ", "\""); | |
| 54 | + } | |
| 55 | + return decString; | |
| 56 | + } | |
| 57 | + // 문자열이 널인지 체크하는 함수 | |
| 58 | + public static boolean checkMsgNull(String msgStr){ | |
| 59 | + boolean isValid = false; | |
| 60 | + String[] msgArray = msgStr.split("ⓜⓢ"); | |
| 61 | + int msgArrayLen = msgArray.length; | |
| 62 | + for(int i=0;i<msgArrayLen;i++){ | |
| 63 | + msgArray[i] = msgArray[i].trim(); | |
| 64 | + if(msgArray[i].length() < 1){ | |
| 65 | + isValid = true; | |
| 66 | + break; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + return isValid; | |
| 70 | + } | |
| 71 | + // 해당 길이만큼 문자열을 자르는 함수 | |
| 72 | + public static String CutString(String str,int limit) | |
| 73 | + { | |
| 74 | + int len = str.length(); | |
| 75 | + int sumLength=0; | |
| 76 | + String cutString = null; | |
| 77 | + byte[] toByte = str.getBytes(); | |
| 78 | + | |
| 79 | + if(limit < 2) | |
| 80 | + return ""; | |
| 81 | + if(toByte.length > limit){ | |
| 82 | + for(int cnt = 0 ; cnt < len ;cnt++){ | |
| 83 | + if ((str.charAt(cnt) & 0xFF00) == 0) // 1 Byte 문자이면 | |
| 84 | + sumLength++; | |
| 85 | + else // 2바이트 문자라면... | |
| 86 | + sumLength = sumLength + 2; | |
| 87 | + if(sumLength > limit){ | |
| 88 | + cutString = str.substring(0, cnt); | |
| 89 | + break; | |
| 90 | + } | |
| 91 | + } | |
| 92 | + }else{ | |
| 93 | + cutString = str; | |
| 94 | + } | |
| 95 | + | |
| 96 | + return cutString; | |
| 97 | + } | |
| 98 | + // 날짜를 구간별로 자르는 함수 | |
| 99 | + // (inDate:날짜 >> (입력형식:2012년 12월 20일일 경우 : 20121220)) | |
| 100 | + public static int substringDate(String inDate, int beginIndex, int lastIndex){ | |
| 101 | + int subDate = -1; | |
| 102 | + inDate = doNumber(inDate); | |
| 103 | + if(inDate.length() == 8){ | |
| 104 | + if((beginIndex < lastIndex) && (lastIndex <= 8)) | |
| 105 | + subDate = Integer.parseInt(inDate.substring(beginIndex, lastIndex)); | |
| 106 | + } | |
| 107 | + return subDate; | |
| 108 | + } | |
| 109 | + // 시간을 구간별로 자르는 함수 | |
| 110 | + public static int substringTime(String inTime, int beginIndex, int lastIndex){ | |
| 111 | + int subDate = -1; | |
| 112 | + inTime = doNumber(inTime); | |
| 113 | + if(inTime.length() == 6){ | |
| 114 | + if((beginIndex < lastIndex) && (lastIndex <= 6)) | |
| 115 | + subDate = Integer.parseInt(inTime.substring(beginIndex, lastIndex)); | |
| 116 | + } | |
| 117 | + return subDate; | |
| 118 | + } | |
| 119 | + public static boolean validDate(String fullDate){ | |
| 120 | + boolean validFlag = true; | |
| 121 | + fullDate = doNumber(fullDate); | |
| 122 | + | |
| 123 | + if(fullDate.length() != 14){ | |
| 124 | + validFlag = false; | |
| 125 | + }else{ | |
| 126 | + if(!(isValidDay(fullDate.substring(0, 8)) && isValidTime(fullDate.substring(8, 14)))) | |
| 127 | + validFlag = false; | |
| 128 | + } | |
| 129 | + return validFlag; | |
| 130 | + } | |
| 131 | + // 유효한 날짜 형식인지 체크하는 함수 | |
| 132 | + public static boolean isValidDay(String inDate){ | |
| 133 | + boolean validFlag = true; | |
| 134 | + int year = substringDate(inDate, 0, 4); | |
| 135 | + // 년도에서 앞에 두자리 체크 | |
| 136 | + if(year < 2013){ | |
| 137 | + validFlag = false; | |
| 138 | + } | |
| 139 | + int month = substringDate(inDate, 4, 6); | |
| 140 | + int day = substringDate(inDate, 6, 8); | |
| 141 | + if (month < 1 || month > 12) { // check month range | |
| 142 | + validFlag = false; | |
| 143 | + } | |
| 144 | + if (day < 1 || day > 31) { | |
| 145 | + validFlag = false; | |
| 146 | + } | |
| 147 | + if ((month==4 || month==6 || month==9 || month==11) && day==31) { | |
| 148 | + validFlag = false; | |
| 149 | + } | |
| 150 | + if (month == 2) { // check for february 29th | |
| 151 | + boolean isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); | |
| 152 | + if (day>29 || (day==29 && !isleap)) { | |
| 153 | + validFlag = false; | |
| 154 | + } | |
| 155 | + } | |
| 156 | + return validFlag; | |
| 157 | + } | |
| 158 | + // 유효한 날짜 형식인지 체크하는 함수 | |
| 159 | + public static boolean isValidTime(String inTime){ | |
| 160 | + boolean validFlag = true; | |
| 161 | + int hour = substringTime(inTime, 0, 2); | |
| 162 | + int minute = substringTime(inTime, 2, 4); | |
| 163 | + int second = substringTime(inTime, 4, 6); | |
| 164 | + if(hour < 0 || hour > 23) | |
| 165 | + validFlag = false; | |
| 166 | + if(minute < 0 || minute > 59) | |
| 167 | + validFlag = false; | |
| 168 | + if(second < 0 || second > 59) | |
| 169 | + validFlag = false; | |
| 170 | + return validFlag; | |
| 171 | + } | |
| 172 | + // 예약일이 하루전인지 체크하는 함수 | |
| 173 | + // 앞의 날짜가 뒤의 날짜보다 이전이면: true / 그렇지않으면 false) | |
| 174 | + public static boolean isBeforeDate(String srcDate, String destDate){ | |
| 175 | + boolean validFlag = false; | |
| 176 | + Calendar srcCal = getCalendar(srcDate); | |
| 177 | + Calendar destCal = getCalendar(destDate); | |
| 178 | + if(srcCal == null || destCal == null){ | |
| 179 | + validFlag = true; | |
| 180 | + }else{ | |
| 181 | + if(srcCal.before(destCal)) | |
| 182 | + validFlag = true; | |
| 183 | + } | |
| 184 | + | |
| 185 | + return validFlag; | |
| 186 | + } | |
| 187 | + | |
| 188 | + public static Calendar getCalendar(int hour){ | |
| 189 | + Calendar thisCal = null; | |
| 190 | + thisCal.add(Calendar.HOUR, hour); | |
| 191 | + return thisCal; | |
| 192 | + } | |
| 193 | + public static Calendar getCalendar(String inDate){ | |
| 194 | + Calendar thisCal = null; | |
| 195 | + inDate = doNumber(inDate); | |
| 196 | + if(inDate.length() == 14 && validDate(inDate)){ | |
| 197 | + String date = inDate.substring(0, 8); | |
| 198 | + String time = inDate.substring(8, 14); | |
| 199 | + int year = substringDate(date, 0, 4); | |
| 200 | + int month = substringDate(date, 4, 6); | |
| 201 | + int day = substringDate(date, 6, 8); | |
| 202 | + int hour = substringTime(time, 0, 2); | |
| 203 | + int minute = substringTime(time, 2, 4); | |
| 204 | + int second = substringTime(time, 4, 6); | |
| 205 | + thisCal = Calendar.getInstance(); | |
| 206 | + thisCal.set(year, (month-1), day, hour, minute, second); | |
| 207 | + } | |
| 208 | + return thisCal; | |
| 209 | + } | |
| 210 | + public static String currentTime(){ | |
| 211 | + Calendar currDate = Calendar.getInstance(); | |
| 212 | + SimpleDateFormat dateForm = new SimpleDateFormat("HHmmss"); | |
| 213 | + return dateForm.format(currDate.getTime()); | |
| 214 | + } | |
| 215 | + public static String getLastDate(String year, String month, String day){ | |
| 216 | + String dateStr = null; | |
| 217 | + String lastDay = null; | |
| 218 | + Calendar currDate = Calendar.getInstance(); | |
| 219 | + currDate.set(Integer.parseInt(year),Integer.parseInt(month)-1,Integer.parseInt(day)); | |
| 220 | + lastDay = Integer.toString(currDate.getActualMaximum(Calendar.DAY_OF_MONTH)); | |
| 221 | + dateStr = year+month+lastDay; | |
| 222 | + return dateStr; | |
| 223 | + } | |
| 224 | + public static String currentDay(){ | |
| 225 | + Calendar currDate = Calendar.getInstance(); | |
| 226 | + SimpleDateFormat dateForm = new SimpleDateFormat("yyyyMMdd"); | |
| 227 | + return dateForm.format(currDate.getTime()); | |
| 228 | + } | |
| 229 | + public static String currentDate(){ | |
| 230 | + Calendar currDate = Calendar.getInstance(); | |
| 231 | + SimpleDateFormat dateForm = new SimpleDateFormat("yyyyMMddHHmmss"); | |
| 232 | + return dateForm.format(currDate.getTime()); | |
| 233 | + } | |
| 234 | + public static String currentLogDate(){ | |
| 235 | + Calendar currDate = Calendar.getInstance(); | |
| 236 | + SimpleDateFormat dateForm = new SimpleDateFormat("[yyyy-MM-dd][HH:mm:ss]"); | |
| 237 | + return dateForm.format(currDate.getTime()); | |
| 238 | + } | |
| 239 | + // "yyyyMMddHHmmss" 의 조합 | |
| 240 | + public static String formatDate(String format){ | |
| 241 | + Calendar currDate = Calendar.getInstance(); | |
| 242 | + SimpleDateFormat dateForm = new SimpleDateFormat(format); | |
| 243 | + return dateForm.format(currDate.getTime()); | |
| 244 | + } | |
| 245 | + public static String getTargetDate(int term){ | |
| 246 | + Calendar currDate = Calendar.getInstance(); | |
| 247 | + currDate.add(Calendar.HOUR, term); | |
| 248 | + SimpleDateFormat dateForm = new SimpleDateFormat("yyyyMMddHHmmss"); | |
| 249 | + return dateForm.format(currDate.getTime()); | |
| 250 | + } | |
| 251 | + public static String getTargetDay(int term){ | |
| 252 | + Calendar currDate = Calendar.getInstance(); | |
| 253 | + currDate.add(Calendar.HOUR, term); | |
| 254 | + SimpleDateFormat dateForm = new SimpleDateFormat("yyyyMMdd"); | |
| 255 | + return dateForm.format(currDate.getTime()); | |
| 256 | + } | |
| 257 | + public static Date parseDate14(String sDay){ | |
| 258 | + Date date = null; | |
| 259 | + if(sDay != null || sDay.length() == 14){ | |
| 260 | + SimpleDateFormat dateForm = new SimpleDateFormat(DATE_FORMAT_14); | |
| 261 | + try { | |
| 262 | + date = dateForm.parse(sDay); | |
| 263 | + } catch (ParseException e) { | |
| 264 | + | |
| 265 | + } | |
| 266 | + } | |
| 267 | + | |
| 268 | + return date; | |
| 269 | + } | |
| 270 | + public static int validTimeOut(String sDay){ | |
| 271 | + int interval = 100000; | |
| 272 | + Date fromDate = parseDate14(sDay); | |
| 273 | + Date toDate = parseDate14(currentDate()); | |
| 274 | + if(fromDate != null && toDate != null){ | |
| 275 | + long duration = toDate.getTime() - fromDate.getTime(); | |
| 276 | + interval = (int)(duration / TIMEOUT_DIVIDE); | |
| 277 | + } | |
| 278 | + | |
| 279 | + return interval; | |
| 280 | + } | |
| 281 | + // 숫자만 반환하는 함수 | |
| 282 | + public static String doNumber(String spell){ | |
| 283 | + String phoneNumber = ""; | |
| 284 | + if(spell == null){ | |
| 285 | + return phoneNumber; | |
| 286 | + } | |
| 287 | + spell = spell.trim(); | |
| 288 | + int spell_Length = spell.length(); | |
| 289 | + if(spell_Length < 1){ | |
| 290 | + return phoneNumber; | |
| 291 | + } | |
| 292 | + for(int i=0;i<spell_Length;i++){ | |
| 293 | + char eachChar = spell.charAt(i); | |
| 294 | + if( 0x30 <= eachChar && eachChar <= 0x39 ){ | |
| 295 | + phoneNumber += eachChar; | |
| 296 | + } | |
| 297 | + } | |
| 298 | + return phoneNumber; | |
| 299 | + } | |
| 300 | + // 소수점 뒤에 해당하는 자리만큼 자르기 | |
| 301 | + public static String cutFloatNumber(String srcNum, int digit){ | |
| 302 | + String headNum = ""; | |
| 303 | + String tailNum = ""; | |
| 304 | + String retNum = ""; | |
| 305 | + | |
| 306 | + if(!(srcNum == null || srcNum.trim().equals(""))){ | |
| 307 | + srcNum = srcNum.trim(); | |
| 308 | + int index = srcNum.indexOf("."); | |
| 309 | + // 소수점 위치가 0보다 큰경우만 처리 | |
| 310 | + if(index > 0){ | |
| 311 | + headNum = srcNum.substring(0, index); | |
| 312 | + tailNum = srcNum.substring((index + 1), srcNum.length()); | |
| 313 | + | |
| 314 | + if(tailNum.length() == 0){ | |
| 315 | + tailNum = "0"; | |
| 316 | + } | |
| 317 | + if(tailNum.length() > digit){ | |
| 318 | + tailNum = tailNum.substring(0, digit); | |
| 319 | + } | |
| 320 | + retNum = headNum + "." + tailNum; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + | |
| 324 | + return retNum; | |
| 325 | + } | |
| 326 | + // 수신번호 체크하기 | |
| 327 | + public static boolean CheckPhone(String src) { | |
| 328 | + if(src == null || src.trim().length() < 10) { | |
| 329 | + return false; | |
| 330 | + } | |
| 331 | + | |
| 332 | + if(!src.startsWith("0")) { | |
| 333 | + return false; | |
| 334 | + } | |
| 335 | + | |
| 336 | + return true; | |
| 337 | + } | |
| 338 | + // 문자열 공백 제거 | |
| 339 | + public static String trim(String obj) { | |
| 340 | + return StringUtil.trim(obj); | |
| 341 | + } | |
| 342 | + /** | |
| 343 | + * @param args | |
| 344 | + */ | |
| 345 | + public static void main(String[] args) { | |
| 346 | + // TODO Auto-generated method stub | |
| 347 | + //System.out.println(QueueUtil.cutFloatNumber("10.2", 2)); | |
| 348 | + //System.out.println(QueueUtil.isValidTime("20131207173555")); | |
| 349 | + | |
| 350 | + /*Calendar currDate = Calendar.getInstance(); | |
| 351 | + currDate.add(Calendar.HOUR, 0); // 1년후의 시간 | |
| 352 | + System.out.println("하루전 시간 : " + currDate.getTime());*/ | |
| 353 | + System.out.println(CommonUtil.isBeforeDate("20131206121212", "20131207121212")); | |
| 354 | + System.out.println("하루전 : " + CommonUtil.getTargetDay(-24)); | |
| 355 | + System.out.println(CommonUtil.currentLogDate()); | |
| 356 | + //Date date = MessageUtil.parseDate14("20141208125958"); | |
| 357 | + System.out.println("validTimeOut() : " + CommonUtil.validTimeOut("20141209154558")); | |
| 358 | + } | |
| 359 | +} |
--- src/main/java/com/munjaon/server/util/MessageUtil.java
+++ src/main/java/com/munjaon/server/util/MessageUtil.java
... | ... | @@ -117,6 +117,10 @@ |
| 117 | 117 |
return pushCounter < 0 ? QueueHeaderConfig.QUEUE_HEADER_LENGTH : (QueueHeaderConfig.QUEUE_HEADER_LENGTH + pushCounter + dataByteLength); |
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 |
+ public static int calcReadPosition(int popCounter, int dataByteLength) {
|
|
| 121 |
+ return popCounter < 0 ? QueueHeaderConfig.QUEUE_HEADER_LENGTH : (QueueHeaderConfig.QUEUE_HEADER_LENGTH + popCounter + dataByteLength); |
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 120 | 124 |
public static void setBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
| 121 | 125 |
/* 1. 사용자 아이디 */ |
| 122 | 126 |
buffer.position(BodyCommonConfig.USERID_BYTE_POSITION); |
... | ... | @@ -159,12 +163,92 @@ |
| 159 | 163 |
buffer.put(messageDto.getRouterSeq().getBytes()); |
| 160 | 164 |
} |
| 161 | 165 |
|
| 166 |
+ public static void getBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 167 |
+ byte[] destArray = null; |
|
| 168 |
+ if (buffer == null || messageDto == null) {
|
|
| 169 |
+ return; |
|
| 170 |
+ } |
|
| 171 |
+ /* 1. 사용자 아이디 */ |
|
| 172 |
+ buffer.position(BodyCommonConfig.USERID_BYTE_POSITION); |
|
| 173 |
+ destArray = new byte[BodyCommonConfig.USERID_BYTE_LENGTH]; |
|
| 174 |
+ buffer.get(destArray); |
|
| 175 |
+ messageDto.setUserId(new String(destArray)); |
|
| 176 |
+ /* 2. 요금제(선불 : P / 후불 : A) : final : 아무작업도 하지 않음 */ |
|
| 177 |
+ /* 3. 단가 */ |
|
| 178 |
+ buffer.position(BodyCommonConfig.UNITCOST_BYTE_POSITION); |
|
| 179 |
+ destArray = new byte[BodyCommonConfig.UNITCOST_BYTE_LENGTH]; |
|
| 180 |
+ buffer.get(destArray); |
|
| 181 |
+ messageDto.setUnitCost(new String(destArray)); |
|
| 182 |
+ /* 4. MSG Group ID */ |
|
| 183 |
+ buffer.position(BodyCommonConfig.MSGGROUPID_BYTE_POSITION); |
|
| 184 |
+ destArray = new byte[BodyCommonConfig.MSGGROUPID_BYTE_LENGTH]; |
|
| 185 |
+ buffer.get(destArray); |
|
| 186 |
+ messageDto.setMsgGroupID(new String(destArray)); |
|
| 187 |
+ /* 5. MSG ID */ |
|
| 188 |
+ buffer.position(BodyCommonConfig.MSGID_BYTE_POSITION); |
|
| 189 |
+ destArray = new byte[BodyCommonConfig.MSGID_BYTE_LENGTH]; |
|
| 190 |
+ buffer.get(destArray); |
|
| 191 |
+ messageDto.setUserMsgID(new String(destArray)); |
|
| 192 |
+ /* 6. Service Type */ |
|
| 193 |
+ buffer.position(BodyCommonConfig.SERVICETYPE_BYTE_POSITION); |
|
| 194 |
+ destArray = new byte[BodyCommonConfig.SERVICETYPE_BYTE_LENGTH]; |
|
| 195 |
+ buffer.get(destArray); |
|
| 196 |
+ messageDto.setServiceType(new String(destArray)); |
|
| 197 |
+ /* 7. 메시지 전송 결과 >> 성공 : 0 / 필터링 : 기타값 */ |
|
| 198 |
+ buffer.position(BodyCommonConfig.SENDSTATUS_BYTE_POSITION); |
|
| 199 |
+ destArray = new byte[BodyCommonConfig.SENDSTATUS_BYTE_LENGTH]; |
|
| 200 |
+ buffer.get(destArray); |
|
| 201 |
+ messageDto.setSendStatus(new String(destArray)); |
|
| 202 |
+ /* 8. 회신번호 */ |
|
| 203 |
+ buffer.position(BodyCommonConfig.SENDER_BYTE_POSITION); |
|
| 204 |
+ destArray = new byte[BodyCommonConfig.SENDER_BYTE_LENGTH]; |
|
| 205 |
+ buffer.get(destArray); |
|
| 206 |
+ messageDto.setUserSender(new String(destArray)); |
|
| 207 |
+ /* 9. 수신번호 */ |
|
| 208 |
+ buffer.position(BodyCommonConfig.RECEIVER_BYTE_POSITION); |
|
| 209 |
+ destArray = new byte[BodyCommonConfig.RECEIVER_BYTE_LENGTH]; |
|
| 210 |
+ buffer.get(destArray); |
|
| 211 |
+ messageDto.setUserReceiver(new String(destArray)); |
|
| 212 |
+ /* 10. 예약시간 */ |
|
| 213 |
+ buffer.position(BodyCommonConfig.RESERVEDT_BYTE_POSITION); |
|
| 214 |
+ destArray = new byte[BodyCommonConfig.RESERVEDT_BYTE_LENGTH]; |
|
| 215 |
+ buffer.get(destArray); |
|
| 216 |
+ messageDto.setReserveDt(new String(destArray)); |
|
| 217 |
+ /* 11. 요청시간 */ |
|
| 218 |
+ buffer.position(BodyCommonConfig.REQUESTDT_BYTE_POSITION); |
|
| 219 |
+ destArray = new byte[BodyCommonConfig.REQUESTDT_BYTE_LENGTH]; |
|
| 220 |
+ buffer.get(destArray); |
|
| 221 |
+ messageDto.setRequestDt(new String(destArray)); |
|
| 222 |
+ /* 12. 원격 주소 */ |
|
| 223 |
+ buffer.position(BodyCommonConfig.REMOTEIP_BYTE_POSITION); |
|
| 224 |
+ destArray = new byte[BodyCommonConfig.REMOTEIP_BYTE_LENGTH]; |
|
| 225 |
+ buffer.get(destArray); |
|
| 226 |
+ messageDto.setRemoteIP(new String(destArray)); |
|
| 227 |
+ /* 13. 발송망 */ |
|
| 228 |
+ buffer.position(BodyCommonConfig.AGENT_CODE_BYTE_POSITION); |
|
| 229 |
+ destArray = new byte[BodyCommonConfig.AGENT_CODE_BYTE_LENGTH]; |
|
| 230 |
+ buffer.get(destArray); |
|
| 231 |
+ messageDto.setRouterSeq(new String(destArray)); |
|
| 232 |
+ } |
|
| 233 |
+ |
|
| 162 | 234 |
public static void setBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
| 163 | 235 |
/* 14. 메시지 */ |
| 164 | 236 |
buffer.position(SmsBodyConfig.SMS_MSG_BYTE_POSITION); |
| 165 | 237 |
buffer.put(messageDto.getUserMessage().getBytes()); |
| 166 | 238 |
} |
| 167 | 239 |
|
| 240 |
+ public static void getBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 241 |
+ byte[] destArray = null; |
|
| 242 |
+ if (buffer == null || messageDto == null) {
|
|
| 243 |
+ return; |
|
| 244 |
+ } |
|
| 245 |
+ /* 14. 메시지 */ |
|
| 246 |
+ buffer.position(SmsBodyConfig.SMS_MSG_BYTE_POSITION); |
|
| 247 |
+ destArray = new byte[SmsBodyConfig.SMS_MSG_BYTE_LENGTH]; |
|
| 248 |
+ buffer.get(destArray); |
|
| 249 |
+ messageDto.setUserMessage(new String(destArray)); |
|
| 250 |
+ } |
|
| 251 |
+ |
|
| 168 | 252 |
public static void setBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
| 169 | 253 |
/* 14. 제목 */ |
| 170 | 254 |
buffer.position(MediaBodyConfig.SUBJECT_BYTE_POSITION); |
+++ src/main/java/com/munjaon/server/util/ServiceUtil.java
... | ... | @@ -0,0 +1,32 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +public final class ServiceUtil { | |
| 4 | + /** DB Commit Check Counter */ | |
| 5 | + public static final int COMMIT_COUNT = 30; | |
| 6 | + | |
| 7 | + public static String[] getServiceNames(String[] serviceNames) { | |
| 8 | + if (serviceNames == null) return null; | |
| 9 | + for (int i = 0; i < serviceNames.length; i++) { | |
| 10 | + serviceNames[i] = serviceNames[i].trim(); | |
| 11 | + } | |
| 12 | + | |
| 13 | + return serviceNames; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public static boolean isDuplicate(String[] serviceNames) { | |
| 17 | + if (serviceNames == null) return false; | |
| 18 | + | |
| 19 | + boolean duplicate = false; | |
| 20 | + for (int i = 0; i < serviceNames.length; i++) { | |
| 21 | + for (int j = (i + 1); j < serviceNames.length; j++) { | |
| 22 | + if (serviceNames[i].equals(serviceNames[j])) { | |
| 23 | + duplicate = true; | |
| 24 | + break; | |
| 25 | + } | |
| 26 | + } | |
| 27 | + if (duplicate) break; | |
| 28 | + } | |
| 29 | + | |
| 30 | + return duplicate; | |
| 31 | + } | |
| 32 | +} |
--- src/main/java/com/munjaon/server/util/XmlUtil.java
+++ src/main/java/com/munjaon/server/util/XmlUtil.java
... | ... | @@ -84,6 +84,7 @@ |
| 84 | 84 |
String value = bookElement.getValue(); |
| 85 | 85 |
System.out.println(name + " : " + value); |
| 86 | 86 |
} |
| 87 |
+ |
|
| 87 | 88 |
} catch (IOException | JDOMException e) {
|
| 88 | 89 |
e.printStackTrace(); |
| 89 | 90 |
} |
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?