쓰레드 기능 개선, 서비스타입별(SMS, LMS, MMS) 쓰기큐 교체, 서비스 구동 설정 추가, 큐풀 개선등
@47f9eab3d32f9c1735f20499c575bdeffb03d841
--- build.gradle
+++ build.gradle
... | ... | @@ -47,6 +47,8 @@ |
| 47 | 47 |
implementation 'commons-beanutils:commons-beanutils:1.9.4' |
| 48 | 48 |
// https://mvnrepository.com/artifact/io.netty/netty-all |
| 49 | 49 |
implementation 'io.netty:netty-all:4.1.42.Final' |
| 50 |
+ // https://mvnrepository.com/artifact/org.jdom/jdom2 |
|
| 51 |
+ implementation 'org.jdom:jdom2:2.0.6.1' |
|
| 50 | 52 |
|
| 51 | 53 |
testCompileOnly 'org.projectlombok:lombok' |
| 52 | 54 |
testAnnotationProcessor 'org.projectlombok:lombok' |
+++ src/main/java/com/munjaon/server/config/RunnerConfiguration.java
... | ... | @@ -0,0 +1,39 @@ |
| 1 | +package com.munjaon.server.config; | |
| 2 | + | |
| 3 | +import com.munjaon.server.server.service.PropertyLoader; | |
| 4 | +import lombok.RequiredArgsConstructor; | |
| 5 | +import org.apache.commons.configuration2.ex.ConfigurationException; | |
| 6 | +import org.springframework.boot.CommandLineRunner; | |
| 7 | +import org.springframework.context.annotation.Bean; | |
| 8 | +import org.springframework.context.annotation.Configuration; | |
| 9 | +import org.springframework.core.annotation.Order; | |
| 10 | + | |
| 11 | +@Configuration | |
| 12 | +@RequiredArgsConstructor | |
| 13 | +public class RunnerConfiguration { | |
| 14 | + private final ServerConfig serverConfig; | |
| 15 | + | |
| 16 | + @Bean | |
| 17 | + @Order(1) | |
| 18 | + public CommandLineRunner getRunnerBeanForProperty() { | |
| 19 | + System.setProperty("PROPS", serverConfig.getServerProperyFile()); | |
| 20 | + PropertyLoader.load(); | |
| 21 | + try { | |
| 22 | + String[] array = serverConfig.getStringArray("test.list"); | |
| 23 | + if (array != null && array.length > 0) { | |
| 24 | + for (String s : array) { | |
| 25 | + System.out.println("List : " + s); | |
| 26 | + } | |
| 27 | + } | |
| 28 | + } catch (ConfigurationException e) { | |
| 29 | + throw new RuntimeException(e); | |
| 30 | + } | |
| 31 | + return args -> System.out.println("Runner Bean #1 : " + serverConfig.getServerProperyFile()); | |
| 32 | + } | |
| 33 | + | |
| 34 | + @Bean | |
| 35 | + @Order(2) | |
| 36 | + public CommandLineRunner getRunnerBeanForService() { | |
| 37 | + return args -> System.out.println("Runner Bean #2"); | |
| 38 | + } | |
| 39 | +} |
--- src/main/java/com/munjaon/server/config/ServerConfig.java
+++ src/main/java/com/munjaon/server/config/ServerConfig.java
... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 |
package com.munjaon.server.config; |
| 2 | 2 |
|
| 3 | 3 |
import jakarta.annotation.PostConstruct; |
| 4 |
+import lombok.Getter; |
|
| 4 | 5 |
import lombok.extern.slf4j.Slf4j; |
| 5 | 6 |
import org.apache.commons.configuration2.PropertiesConfiguration; |
| 6 | 7 |
import org.apache.commons.configuration2.builder.ConfigurationBuilderEvent; |
... | ... | @@ -19,6 +20,7 @@ |
| 19 | 20 |
@Slf4j |
| 20 | 21 |
@Component |
| 21 | 22 |
public class ServerConfig {
|
| 23 |
+ @Getter |
|
| 22 | 24 |
@Value("${agent.server-property-file}")
|
| 23 | 25 |
private String serverProperyFile; |
| 24 | 26 |
|
... | ... | @@ -47,4 +49,13 @@ |
| 47 | 49 |
public int getInt(String key) throws ConfigurationException {
|
| 48 | 50 |
return builder.getConfiguration().getInt(key, 3); |
| 49 | 51 |
} |
| 52 |
+ |
|
| 53 |
+ public String[] getStringArray(String key) throws ConfigurationException {
|
|
| 54 |
+ return getStringArray(key, ","); |
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+ public String[] getStringArray(String key, String regExp) throws ConfigurationException {
|
|
| 58 |
+ String value = getString(key); |
|
| 59 |
+ return value == null ? null : value.split(regExp); |
|
| 60 |
+ } |
|
| 50 | 61 |
} |
+++ src/main/java/com/munjaon/server/config/ServiceCode.java
... | ... | @@ -0,0 +1,52 @@ |
| 1 | +package com.munjaon.server.config; | |
| 2 | + | |
| 3 | +import lombok.Getter; | |
| 4 | + | |
| 5 | +@Getter | |
| 6 | +public enum ServiceCode { | |
| 7 | + OK(200, "Success"), | |
| 8 | + MSG_ERROR_USERID(300, "userId is Null OR is Over Limit Byte"), | |
| 9 | + MSG_ERROR_FEETYPE(301, "feeType is Null OR is Over Limit Byte"), | |
| 10 | + MSG_ERROR_UNITCOST(302, "unitCost is Null OR is Over Limit Byte"), | |
| 11 | + MSG_ERROR_MSGGROUPID(303, "msgGroupID is Null OR is Over Limit Byte"), | |
| 12 | + MSG_ERROR_USERMSGID(304, "userMsgID is Null OR is Over Limit Byte"), | |
| 13 | + MSG_ERROR_SERVICETYPE(305, "serviceType is Null OR is Over Limit Byte"), | |
| 14 | + MSG_ERROR_SENDSTATUS(306, "sendStatus is Null OR is Over Limit Byte"), | |
| 15 | + MSG_ERROR_USERSENDER(307, "userSender is Null OR is Over Limit Byte"), | |
| 16 | + MSG_ERROR_USERRECEIVER(308, "userReceiver is Null OR is Over Limit Byte"), | |
| 17 | + MSG_ERROR_REQUESTDT(309, "requestDt is Null OR is Over Limit Byte"), | |
| 18 | + MSG_ERROR_REMOTEIP(310, "remoteIP is Null OR is Over Limit Byte"), | |
| 19 | + MSG_ERROR_ROUTERSEQ(311, "routerSeq is Null OR is Over Limit Byte"), | |
| 20 | + | |
| 21 | + /* SMS 메시지 */ | |
| 22 | + MSG_ERROR_SMS_MESSAGE(400, "SMS Message is Null OR is Over Limit Byte"), | |
| 23 | + | |
| 24 | + /* LMS, MMS 제목, 메시지 */ | |
| 25 | + MSG_ERROR_MEDIA_SUBJECT(500, "LMS, MMS Subject is Null OR is Over Limit Byte"), | |
| 26 | + MSG_ERROR_MEDIA_MESSAGE(501, "LMS, MMS Message is Null OR is Over Limit Byte"), | |
| 27 | + | |
| 28 | + | |
| 29 | + ETC_ERROR(999, "ETC ERROR"); | |
| 30 | + | |
| 31 | + private Integer code; | |
| 32 | + private String message; | |
| 33 | + | |
| 34 | + ServiceCode(Integer code, String msg) { | |
| 35 | + this.code = code; | |
| 36 | + this.message = msg; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public static String getMessage(Integer code) { | |
| 40 | + if (code == null) { | |
| 41 | + return "etc"; | |
| 42 | + } | |
| 43 | + | |
| 44 | + for (ServiceCode resCode : values()) { | |
| 45 | + if (resCode.getCode().equals(code)) { | |
| 46 | + return resCode.getMessage(); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + | |
| 50 | + return "etc"; | |
| 51 | + } | |
| 52 | +} |
--- src/main/java/com/munjaon/server/queue/config/MediaBodyConfig.java
+++ src/main/java/com/munjaon/server/queue/config/MediaBodyConfig.java
... | ... | @@ -20,6 +20,8 @@ |
| 20 | 20 |
public static final int FILENAME_THREE_BYTE_LENGTH = 128; |
| 21 | 21 |
public static final int FILENAME_THREE_BYTE_POSITION = FILENAME_TWO_BYTE_POSITION + FILENAME_TWO_BYTE_LENGTH; |
| 22 | 22 |
|
| 23 |
- /* Media Body 길이 */ |
|
| 24 |
- public static final int MEDIA_SUM_BYTE_LENGTH = BodyCommonConfig.COMMON_SUM_BYTE_LENGTH + SUBJECT_BYTE_LENGTH + MEDIA_MSG_BYTE_LENGTH + FILECNT_BYTE_LENGTH + FILENAME_ONE_BYTE_LENGTH + FILENAME_TWO_BYTE_LENGTH + FILENAME_THREE_BYTE_LENGTH; |
|
| 23 |
+ /* LMS Body 길이 */ |
|
| 24 |
+ public static final int LMS_SUM_BYTE_LENGTH = BodyCommonConfig.COMMON_SUM_BYTE_LENGTH + SUBJECT_BYTE_LENGTH + MEDIA_MSG_BYTE_LENGTH; |
|
| 25 |
+ /* MMS Body 길이 */ |
|
| 26 |
+ public static final int MMS_SUM_BYTE_LENGTH = BodyCommonConfig.COMMON_SUM_BYTE_LENGTH + SUBJECT_BYTE_LENGTH + MEDIA_MSG_BYTE_LENGTH + FILECNT_BYTE_LENGTH + FILENAME_ONE_BYTE_LENGTH + FILENAME_TWO_BYTE_LENGTH + FILENAME_THREE_BYTE_LENGTH; |
|
| 25 | 27 |
} |
--- src/main/java/com/munjaon/server/queue/dto/BasicMessageDto.java
+++ src/main/java/com/munjaon/server/queue/dto/BasicMessageDto.java
... | ... | @@ -8,9 +8,9 @@ |
| 8 | 8 |
@Setter |
| 9 | 9 |
@ToString |
| 10 | 10 |
public class BasicMessageDto {
|
| 11 |
- protected String userId = ""; |
|
| 12 |
- protected String feeType = ""; |
|
| 13 |
- protected String unitCost = ""; |
|
| 11 |
+ protected String userId = ""; // 사용자 아이디 |
|
| 12 |
+ protected final String feeType = "A"; // 요금제(선불 : P / 후불 : A) |
|
| 13 |
+ protected String unitCost = ""; // 단가 |
|
| 14 | 14 |
protected String msgGroupID = "0"; |
| 15 | 15 |
protected String userMsgID = ""; |
| 16 | 16 |
protected String serviceType = ""; |
... | ... | @@ -23,5 +23,13 @@ |
| 23 | 23 |
protected String routerSeq = "0"; |
| 24 | 24 |
|
| 25 | 25 |
protected String userMessage = ""; |
| 26 |
- protected String userMsgType = ""; |
|
| 26 |
+ |
|
| 27 |
+ protected String userSubject = ""; |
|
| 28 |
+ protected int userFileCnt = 0; |
|
| 29 |
+ protected String userFileName01; |
|
| 30 |
+ protected String userFileName02; |
|
| 31 |
+ protected String userFileName03; |
|
| 32 |
+ protected int userFileSize01 = 0; |
|
| 33 |
+ protected int userFileSize02 = 0; |
|
| 34 |
+ protected int userFileSize03 = 0; |
|
| 27 | 35 |
} |
--- src/main/java/com/munjaon/server/queue/dto/QueueInfo.java
+++ src/main/java/com/munjaon/server/queue/dto/QueueInfo.java
... | ... | @@ -1,11 +1,13 @@ |
| 1 | 1 |
package com.munjaon.server.queue.dto; |
| 2 | 2 |
|
| 3 |
+import lombok.Builder; |
|
| 3 | 4 |
import lombok.Getter; |
| 4 | 5 |
import lombok.Setter; |
| 5 | 6 |
import lombok.ToString; |
| 6 | 7 |
|
| 7 | 8 |
@Getter |
| 8 | 9 |
@Setter |
| 10 |
+@Builder |
|
| 9 | 11 |
@ToString |
| 10 | 12 |
public class QueueInfo {
|
| 11 | 13 |
private String queueName = ""; |
+++ src/main/java/com/munjaon/server/queue/pool/LmsQueuePool.java
... | ... | @@ -0,0 +1,84 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | +import com.munjaon.server.queue.service.LmsWriteQueue; | |
| 5 | + | |
| 6 | +import java.util.LinkedList; | |
| 7 | + | |
| 8 | +public class LmsQueuePool { | |
| 9 | + /** Lock Object */ | |
| 10 | + private final Object lockMonitor = new Object(); | |
| 11 | + /** File Queue Pool */ | |
| 12 | + private final LinkedList<LmsWriteQueue> queuePool = new LinkedList<>(); | |
| 13 | + /** File Queue */ | |
| 14 | + private LmsWriteQueue queue = null; | |
| 15 | + /** File Queue 분배를 위한 인덱서 */ | |
| 16 | + private int queueIndex = 0; | |
| 17 | + | |
| 18 | + /** Singleton Instance */ | |
| 19 | + private static SmsQueuePool fileQueue; | |
| 20 | + | |
| 21 | + public synchronized static SmsQueuePool getInstance(){ | |
| 22 | + if(fileQueue == null){ | |
| 23 | + fileQueue = new SmsQueuePool(); | |
| 24 | + } | |
| 25 | + return fileQueue; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** Queue 존재하는지 조회 */ | |
| 29 | + public boolean isExistQueue(String name){ | |
| 30 | + synchronized(lockMonitor){ | |
| 31 | + boolean isExist = false; | |
| 32 | + for (LmsWriteQueue writeQueue : queuePool) { | |
| 33 | + if (name.equals(writeQueue.getQueueName())) { | |
| 34 | + isExist = true; | |
| 35 | + break; | |
| 36 | + } | |
| 37 | + } | |
| 38 | + return isExist; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** Queue 제거 */ | |
| 42 | + public void removeQueue(String name){ | |
| 43 | + synchronized(lockMonitor) { | |
| 44 | + for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) { | |
| 45 | + queue = queuePool.get(loopCnt); | |
| 46 | + if(name.equals(queue.getQueueName())){ | |
| 47 | + queuePool.remove(loopCnt); | |
| 48 | + System.out.println("[LMS Queue] [" + queue.getQueueName() + " is Removed]"); | |
| 49 | + break; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + /** Queue 등록 */ | |
| 55 | + public void addShortQueue(LmsWriteQueue queue){ | |
| 56 | + synchronized(lockMonitor){ | |
| 57 | + if (queue != null){ | |
| 58 | + queuePool.addLast(queue); | |
| 59 | + lockMonitor.notifyAll(); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + /** Queue 데이터 저장 */ | |
| 64 | + public void pushQueue(BasicMessageDto data) throws Exception{ | |
| 65 | + synchronized(lockMonitor) { | |
| 66 | + if (queuePool.isEmpty()) { | |
| 67 | + try{ | |
| 68 | + lockMonitor.wait(); | |
| 69 | + }catch(InterruptedException e){ | |
| 70 | + // 아무 처리도 하지 않는다. | |
| 71 | + } | |
| 72 | + } | |
| 73 | + //큐리스트의 끝까지 이동한 경우 처음으로 되돌린다. | |
| 74 | + if (queueIndex >= queuePool.size()) { | |
| 75 | + queueIndex = 0; | |
| 76 | + } | |
| 77 | + // 파일큐에 Push 한다. | |
| 78 | + queue = queuePool.get(queueIndex); | |
| 79 | + queue.pushMessageToBuffer(data); | |
| 80 | + // 큐인덱서를 증가시킨다. | |
| 81 | + queueIndex++; | |
| 82 | + } | |
| 83 | + } | |
| 84 | +} |
+++ src/main/java/com/munjaon/server/queue/pool/MmsQueuePool.java
... | ... | @@ -0,0 +1,84 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | +import com.munjaon.server.queue.service.MmsWriteQueue; | |
| 5 | + | |
| 6 | +import java.util.LinkedList; | |
| 7 | + | |
| 8 | +public class MmsQueuePool { | |
| 9 | + /** Lock Object */ | |
| 10 | + private final Object lockMonitor = new Object(); | |
| 11 | + /** File Queue Pool */ | |
| 12 | + private final LinkedList<MmsWriteQueue> queuePool = new LinkedList<>(); | |
| 13 | + /** File Queue */ | |
| 14 | + private MmsWriteQueue queue = null; | |
| 15 | + /** File Queue 분배를 위한 인덱서 */ | |
| 16 | + private int queueIndex = 0; | |
| 17 | + | |
| 18 | + /** Singleton Instance */ | |
| 19 | + private static SmsQueuePool fileQueue; | |
| 20 | + | |
| 21 | + public synchronized static SmsQueuePool getInstance(){ | |
| 22 | + if(fileQueue == null){ | |
| 23 | + fileQueue = new SmsQueuePool(); | |
| 24 | + } | |
| 25 | + return fileQueue; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** Queue 존재하는지 조회 */ | |
| 29 | + public boolean isExistQueue(String name){ | |
| 30 | + synchronized(lockMonitor){ | |
| 31 | + boolean isExist = false; | |
| 32 | + for (MmsWriteQueue writeQueue : queuePool) { | |
| 33 | + if (name.equals(writeQueue.getQueueName())) { | |
| 34 | + isExist = true; | |
| 35 | + break; | |
| 36 | + } | |
| 37 | + } | |
| 38 | + return isExist; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** Queue 제거 */ | |
| 42 | + public void removeQueue(String name){ | |
| 43 | + synchronized(lockMonitor) { | |
| 44 | + for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) { | |
| 45 | + queue = queuePool.get(loopCnt); | |
| 46 | + if(name.equals(queue.getQueueName())){ | |
| 47 | + queuePool.remove(loopCnt); | |
| 48 | + System.out.println("[MMS Queue] [" + queue.getQueueName() + " is Removed]"); | |
| 49 | + break; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + /** Queue 등록 */ | |
| 55 | + public void addShortQueue(MmsWriteQueue queue){ | |
| 56 | + synchronized(lockMonitor){ | |
| 57 | + if (queue != null){ | |
| 58 | + queuePool.addLast(queue); | |
| 59 | + lockMonitor.notifyAll(); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + /** Queue 데이터 저장 */ | |
| 64 | + public void pushQueue(BasicMessageDto data) throws Exception{ | |
| 65 | + synchronized(lockMonitor) { | |
| 66 | + if (queuePool.isEmpty()) { | |
| 67 | + try{ | |
| 68 | + lockMonitor.wait(); | |
| 69 | + } catch (InterruptedException e) { | |
| 70 | + // 아무 처리도 하지 않는다. | |
| 71 | + } | |
| 72 | + } | |
| 73 | + //큐리스트의 끝까지 이동한 경우 처음으로 되돌린다. | |
| 74 | + if (queueIndex >= queuePool.size()) { | |
| 75 | + queueIndex = 0; | |
| 76 | + } | |
| 77 | + // 파일큐에 Push 한다. | |
| 78 | + queue = queuePool.get(queueIndex); | |
| 79 | + queue.pushMessageToBuffer(data); | |
| 80 | + // 큐인덱서를 증가시킨다. | |
| 81 | + queueIndex++; | |
| 82 | + } | |
| 83 | + } | |
| 84 | +} |
+++ src/main/java/com/munjaon/server/queue/pool/SmsQueuePool.java
... | ... | @@ -0,0 +1,84 @@ |
| 1 | +package com.munjaon.server.queue.pool; | |
| 2 | + | |
| 3 | +import com.munjaon.server.queue.dto.BasicMessageDto; | |
| 4 | +import com.munjaon.server.queue.service.SmsWriteQueue; | |
| 5 | + | |
| 6 | +import java.util.LinkedList; | |
| 7 | + | |
| 8 | +public class SmsQueuePool { | |
| 9 | + /** Lock Object */ | |
| 10 | + private final Object lockMonitor = new Object(); | |
| 11 | + /** File Queue Pool */ | |
| 12 | + private final LinkedList<SmsWriteQueue> queuePool = new LinkedList<>(); | |
| 13 | + /** File Queue */ | |
| 14 | + private SmsWriteQueue queue = null; | |
| 15 | + /** File Queue 분배를 위한 인덱서 */ | |
| 16 | + private int queueIndex = 0; | |
| 17 | + | |
| 18 | + /** Singleton Instance */ | |
| 19 | + private static SmsQueuePool fileQueue; | |
| 20 | + | |
| 21 | + public synchronized static SmsQueuePool getInstance(){ | |
| 22 | + if(fileQueue == null){ | |
| 23 | + fileQueue = new SmsQueuePool(); | |
| 24 | + } | |
| 25 | + return fileQueue; | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** Queue 존재하는지 조회 */ | |
| 29 | + public boolean isExistQueue(String name){ | |
| 30 | + synchronized(lockMonitor){ | |
| 31 | + boolean isExist = false; | |
| 32 | + for (SmsWriteQueue writeQueue : queuePool) { | |
| 33 | + if (name.equals(writeQueue.getQueueName())) { | |
| 34 | + isExist = true; | |
| 35 | + break; | |
| 36 | + } | |
| 37 | + } | |
| 38 | + return isExist; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + /** Queue 제거 */ | |
| 42 | + public void removeQueue(String name){ | |
| 43 | + synchronized(lockMonitor) { | |
| 44 | + for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) { | |
| 45 | + queue = queuePool.get(loopCnt); | |
| 46 | + if(name.equals(queue.getQueueName())){ | |
| 47 | + queuePool.remove(loopCnt); | |
| 48 | + System.out.println("[SMS Queue] [" + queue.getQueueName() + " is Removed]"); | |
| 49 | + break; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + } | |
| 53 | + } | |
| 54 | + /** Queue 등록 */ | |
| 55 | + public void addShortQueue(SmsWriteQueue queue){ | |
| 56 | + synchronized(lockMonitor){ | |
| 57 | + if (queue != null){ | |
| 58 | + queuePool.addLast(queue); | |
| 59 | + lockMonitor.notifyAll(); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + /** Queue 데이터 저장 */ | |
| 64 | + public void pushQueue(BasicMessageDto data) throws Exception{ | |
| 65 | + synchronized(lockMonitor) { | |
| 66 | + if (queuePool.isEmpty()) { | |
| 67 | + try{ | |
| 68 | + lockMonitor.wait(); | |
| 69 | + }catch(InterruptedException e){ | |
| 70 | + // 아무 처리도 하지 않는다. | |
| 71 | + } | |
| 72 | + } | |
| 73 | + //큐리스트의 끝까지 이동한 경우 처음으로 되돌린다. | |
| 74 | + if (queueIndex >= queuePool.size()) { | |
| 75 | + queueIndex = 0; | |
| 76 | + } | |
| 77 | + // 파일큐에 Push 한다. | |
| 78 | + queue = queuePool.get(queueIndex); | |
| 79 | + queue.pushMessageToBuffer(data); | |
| 80 | + // 큐인덱서를 증가시킨다. | |
| 81 | + queueIndex++; | |
| 82 | + } | |
| 83 | + } | |
| 84 | +} |
--- src/main/java/com/munjaon/server/queue/service/KakaoWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/service/KakaoWriteQueue.java
... | ... | @@ -1,9 +1,21 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 |
-import com.munjaon.server.queue.dto.KakaoMessageDto; |
|
| 3 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 4 | 4 |
|
| 5 | 5 |
public class KakaoWriteQueue extends WriteQueue {
|
| 6 |
- public void pushBuffer(KakaoMessageDto data) throws Exception {
|
|
| 6 |
+ |
|
| 7 |
+ @Override |
|
| 8 |
+ int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 9 |
+ return 0; |
|
| 10 |
+ } |
|
| 11 |
+ |
|
| 12 |
+ @Override |
|
| 13 |
+ void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 14 |
+ |
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ @Override |
|
| 18 |
+ void initDataBuffer() {
|
|
| 7 | 19 |
|
| 8 | 20 |
} |
| 9 | 21 |
} |
--- src/main/java/com/munjaon/server/queue/service/LmsWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/service/LmsWriteQueue.java
... | ... | @@ -1,9 +1,61 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 |
-import com.munjaon.server.queue.dto.LmsMessageDto; |
|
| 3 |
+import com.munjaon.server.config.ServiceCode; |
|
| 4 |
+import com.munjaon.server.queue.config.MediaBodyConfig; |
|
| 5 |
+import com.munjaon.server.queue.config.QueueConstants; |
|
| 6 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 7 |
+import com.munjaon.server.util.MessageUtil; |
|
| 8 |
+ |
|
| 9 |
+import java.nio.ByteBuffer; |
|
| 4 | 10 |
|
| 5 | 11 |
public class LmsWriteQueue extends WriteQueue {
|
| 6 |
- public void pushBuffer(LmsMessageDto data) throws Exception {
|
|
| 7 | 12 |
|
| 13 |
+ @Override |
|
| 14 |
+ public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 15 |
+ /* 13. 제목 */ |
|
| 16 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
|
| 17 |
+ return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode(); |
|
| 18 |
+ } |
|
| 19 |
+ /* 14. 메시지 */ |
|
| 20 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserMessage(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMessage(), MediaBodyConfig.MEDIA_MSG_BYTE_LENGTH, false)) {
|
|
| 21 |
+ return ServiceCode.MSG_ERROR_MEDIA_MESSAGE.getCode(); |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ return ServiceCode.OK.getCode(); |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ @Override |
|
| 28 |
+ public void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 29 |
+ if (isValidateMessage(messageDto) == ServiceCode.OK.getCode()) {
|
|
| 30 |
+ /* 1. dataBuffer 초기화 */ |
|
| 31 |
+ initDataBuffer(); |
|
| 32 |
+ /* 2. messageDto >> dataBuffer */ |
|
| 33 |
+ MessageUtil.setBytesForCommonMessage(this.dataBuffer, messageDto); |
|
| 34 |
+ MessageUtil.setBytesForMediaMessage(this.dataBuffer, messageDto); |
|
| 35 |
+ /* 3. 파일큐에 적재 */ |
|
| 36 |
+ /* 3.1 Header 정보 다시 일기 */ |
|
| 37 |
+ readHeader(); |
|
| 38 |
+ if (this.dataBuffer != null){
|
|
| 39 |
+ this.channel.position(MessageUtil.calcWritePosition(this.pushCounter, MediaBodyConfig.LMS_SUM_BYTE_LENGTH)); |
|
| 40 |
+ this.dataBuffer.flip(); |
|
| 41 |
+ this.channel.write(this.dataBuffer); |
|
| 42 |
+ /* 3.2 Push 카운터 증가 */ |
|
| 43 |
+ this.pushCounter = this.pushCounter + 1; |
|
| 44 |
+ /* 3.3 Header 정보 변경 */ |
|
| 45 |
+ writeHeader(); |
|
| 46 |
+ } |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ @Override |
|
| 51 |
+ public void initDataBuffer() {
|
|
| 52 |
+ if (this.dataBuffer == null) {
|
|
| 53 |
+ this.dataBuffer = ByteBuffer.allocateDirect(MediaBodyConfig.LMS_SUM_BYTE_LENGTH); |
|
| 54 |
+ } |
|
| 55 |
+ this.dataBuffer.clear(); |
|
| 56 |
+ for(int loopCnt = 0; loopCnt < MediaBodyConfig.LMS_SUM_BYTE_LENGTH; loopCnt++){
|
|
| 57 |
+ this.dataBuffer.put(QueueConstants.SET_DEFAULT_BYTE); |
|
| 58 |
+ } |
|
| 59 |
+ this.dataBuffer.position(0); |
|
| 8 | 60 |
} |
| 9 | 61 |
} |
--- src/main/java/com/munjaon/server/queue/service/MmsWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/service/MmsWriteQueue.java
... | ... | @@ -1,9 +1,62 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 |
-import com.munjaon.server.queue.dto.MmsMessageDto; |
|
| 3 |
+import com.munjaon.server.config.ServiceCode; |
|
| 4 |
+import com.munjaon.server.queue.config.MediaBodyConfig; |
|
| 5 |
+import com.munjaon.server.queue.config.QueueConstants; |
|
| 6 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 7 |
+import com.munjaon.server.util.MessageUtil; |
|
| 8 |
+ |
|
| 9 |
+import java.nio.ByteBuffer; |
|
| 4 | 10 |
|
| 5 | 11 |
public class MmsWriteQueue extends WriteQueue {
|
| 6 |
- public void pushBuffer(MmsMessageDto data) throws Exception {
|
|
| 7 | 12 |
|
| 13 |
+ @Override |
|
| 14 |
+ public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 15 |
+ /* 13. 제목 */ |
|
| 16 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
|
| 17 |
+ return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode(); |
|
| 18 |
+ } |
|
| 19 |
+ /* 14. 메시지 */ |
|
| 20 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserMessage(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMessage(), MediaBodyConfig.MEDIA_MSG_BYTE_LENGTH, false)) {
|
|
| 21 |
+ return ServiceCode.MSG_ERROR_MEDIA_MESSAGE.getCode(); |
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ return ServiceCode.OK.getCode(); |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ @Override |
|
| 28 |
+ public void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 29 |
+ if (isValidateMessage(messageDto) == ServiceCode.OK.getCode()) {
|
|
| 30 |
+ /* 1. dataBuffer 초기화 */ |
|
| 31 |
+ initDataBuffer(); |
|
| 32 |
+ /* 2. messageDto >> dataBuffer */ |
|
| 33 |
+ MessageUtil.setBytesForCommonMessage(this.dataBuffer, messageDto); |
|
| 34 |
+ MessageUtil.setBytesForMediaMessage(this.dataBuffer, messageDto); |
|
| 35 |
+ MessageUtil.setBytesForMmsMessage(this.dataBuffer, messageDto); |
|
| 36 |
+ /* 3. 파일큐에 적재 */ |
|
| 37 |
+ /* 3.1 Header 정보 다시 일기 */ |
|
| 38 |
+ readHeader(); |
|
| 39 |
+ if (this.dataBuffer != null){
|
|
| 40 |
+ this.channel.position(MessageUtil.calcWritePosition(this.pushCounter, MediaBodyConfig.MMS_SUM_BYTE_LENGTH)); |
|
| 41 |
+ this.dataBuffer.flip(); |
|
| 42 |
+ this.channel.write(this.dataBuffer); |
|
| 43 |
+ /* 3.2 Push 카운터 증가 */ |
|
| 44 |
+ this.pushCounter = this.pushCounter + 1; |
|
| 45 |
+ /* 3.3 Header 정보 변경 */ |
|
| 46 |
+ writeHeader(); |
|
| 47 |
+ } |
|
| 48 |
+ } |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ @Override |
|
| 52 |
+ public void initDataBuffer() {
|
|
| 53 |
+ if (this.dataBuffer == null) {
|
|
| 54 |
+ this.dataBuffer = ByteBuffer.allocateDirect(MediaBodyConfig.MMS_SUM_BYTE_LENGTH); |
|
| 55 |
+ } |
|
| 56 |
+ this.dataBuffer.clear(); |
|
| 57 |
+ for(int loopCnt = 0; loopCnt < MediaBodyConfig.MMS_SUM_BYTE_LENGTH; loopCnt++){
|
|
| 58 |
+ this.dataBuffer.put(QueueConstants.SET_DEFAULT_BYTE); |
|
| 59 |
+ } |
|
| 60 |
+ this.dataBuffer.position(0); |
|
| 8 | 61 |
} |
| 9 | 62 |
} |
+++ src/main/java/com/munjaon/server/queue/service/ReadQueue.java
... | ... | @@ -0,0 +1,197 @@ |
| 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/SmsWriteQueue.java
+++ src/main/java/com/munjaon/server/queue/service/SmsWriteQueue.java
... | ... | @@ -1,9 +1,63 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 |
+import com.munjaon.server.config.ServiceCode; |
|
| 4 |
+import com.munjaon.server.queue.config.QueueConstants; |
|
| 5 |
+import com.munjaon.server.queue.config.SmsBodyConfig; |
|
| 3 | 6 |
import com.munjaon.server.queue.dto.BasicMessageDto; |
| 7 |
+import com.munjaon.server.queue.dto.QueueInfo; |
|
| 8 |
+import com.munjaon.server.util.MessageUtil; |
|
| 9 |
+ |
|
| 10 |
+import java.nio.ByteBuffer; |
|
| 4 | 11 |
|
| 5 | 12 |
public class SmsWriteQueue extends WriteQueue {
|
| 6 |
- public void pushBuffer(BasicMessageDto data) throws Exception {
|
|
| 13 |
+ public SmsWriteQueue(QueueInfo queueInfo) throws Exception {
|
|
| 14 |
+ this.queueInfo = queueInfo; |
|
| 15 |
+ /* 큐초기화 */ |
|
| 16 |
+ initQueue(); |
|
| 17 |
+ } |
|
| 7 | 18 |
|
| 19 |
+ @Override |
|
| 20 |
+ public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
|
| 21 |
+ /* 13. 메시지 */ |
|
| 22 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserMessage(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMessage(), SmsBodyConfig.SMS_MSG_BYTE_LENGTH, false)) {
|
|
| 23 |
+ return ServiceCode.MSG_ERROR_SMS_MESSAGE.getCode(); |
|
| 24 |
+ } |
|
| 25 |
+ |
|
| 26 |
+ return ServiceCode.OK.getCode(); |
|
| 27 |
+ } |
|
| 28 |
+ |
|
| 29 |
+ @Override |
|
| 30 |
+ public void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
|
| 31 |
+ if (isValidateMessage(messageDto) == ServiceCode.OK.getCode()) {
|
|
| 32 |
+ /* 1. dataBuffer 초기화 */ |
|
| 33 |
+ initDataBuffer(); |
|
| 34 |
+ /* 2. messageDto >> dataBuffer */ |
|
| 35 |
+ MessageUtil.setBytesForCommonMessage(this.dataBuffer, messageDto); |
|
| 36 |
+ MessageUtil.setBytesForSmsMessage(this.dataBuffer, messageDto); |
|
| 37 |
+ /* 3. 파일큐에 적재 */ |
|
| 38 |
+ /* 3.1 Header 정보 다시 일기 */ |
|
| 39 |
+ readHeader(); |
|
| 40 |
+ if (this.dataBuffer != null){
|
|
| 41 |
+ this.channel.position(MessageUtil.calcWritePosition(this.pushCounter, SmsBodyConfig.SMS_SUM_BYTE_LENGTH)); |
|
| 42 |
+ this.dataBuffer.flip(); |
|
| 43 |
+ this.channel.write(this.dataBuffer); |
|
| 44 |
+ /* 3.2 Push 카운터 증가 */ |
|
| 45 |
+ this.pushCounter = this.pushCounter + 1; |
|
| 46 |
+ /* 3.3 Header 정보 변경 */ |
|
| 47 |
+ writeHeader(); |
|
| 48 |
+ } |
|
| 49 |
+ } |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ @Override |
|
| 53 |
+ public void initDataBuffer() {
|
|
| 54 |
+ if (this.dataBuffer == null) {
|
|
| 55 |
+ this.dataBuffer = ByteBuffer.allocateDirect(SmsBodyConfig.SMS_SUM_BYTE_LENGTH); |
|
| 56 |
+ } |
|
| 57 |
+ this.dataBuffer.clear(); |
|
| 58 |
+ for(int loopCnt = 0; loopCnt < SmsBodyConfig.SMS_SUM_BYTE_LENGTH; loopCnt++){
|
|
| 59 |
+ this.dataBuffer.put(QueueConstants.SET_DEFAULT_BYTE); |
|
| 60 |
+ } |
|
| 61 |
+ this.dataBuffer.position(0); |
|
| 8 | 62 |
} |
| 9 | 63 |
} |
--- src/main/java/com/munjaon/server/queue/service/WriteQueue.java
+++ src/main/java/com/munjaon/server/queue/service/WriteQueue.java
... | ... | @@ -1,8 +1,13 @@ |
| 1 | 1 |
package com.munjaon.server.queue.service; |
| 2 | 2 |
|
| 3 |
+import com.munjaon.server.config.ServiceCode; |
|
| 4 |
+import com.munjaon.server.queue.config.BodyCommonConfig; |
|
| 3 | 5 |
import com.munjaon.server.queue.config.QueueConstants; |
| 4 | 6 |
import com.munjaon.server.queue.config.QueueHeaderConfig; |
| 7 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 5 | 8 |
import com.munjaon.server.queue.dto.QueueInfo; |
| 9 |
+import com.munjaon.server.util.MessageUtil; |
|
| 10 |
+import lombok.Getter; |
|
| 6 | 11 |
|
| 7 | 12 |
import java.io.File; |
| 8 | 13 |
import java.io.IOException; |
... | ... | @@ -13,20 +18,22 @@ |
| 13 | 18 |
import java.time.format.DateTimeFormatter; |
| 14 | 19 |
|
| 15 | 20 |
public abstract class WriteQueue {
|
| 16 |
- /** Queue Header Size - [Create Date:10 Byte, Push Count:10 Byte] */ |
|
| 17 |
- protected static final int QUEUE_HEADER_LENGTH = 20; |
|
| 18 |
- /** Queue Create Date - [Format:YYYYMMDD] */ |
|
| 19 |
- protected String createDate = ""; |
|
| 20 |
- /** Queue Push Counter */ |
|
| 21 |
- protected int pushCounter = 0; |
|
| 22 | 21 |
/** Queue Header Buffer */ |
| 23 | 22 |
protected ByteBuffer headerBuffer = null; |
| 24 |
- /** Queue Information */ |
|
| 25 |
- protected QueueInfo queueInfo = null; |
|
| 26 |
- /** Queue File Channel */ |
|
| 27 |
- protected FileChannel channel = null; |
|
| 28 | 23 |
/** Header 에서 사용하는 변수 */ |
| 29 | 24 |
protected byte[] headerArray = null; |
| 25 |
+ /** Queue Create Date - [Format:YYYYMMDD] */ |
|
| 26 |
+ @Getter |
|
| 27 |
+ protected String createDate = ""; |
|
| 28 |
+ /** Queue Push Counter */ |
|
| 29 |
+ @Getter |
|
| 30 |
+ protected int pushCounter = 0; |
|
| 31 |
+ |
|
| 32 |
+ /** Queue File Channel */ |
|
| 33 |
+ protected FileChannel channel = null; |
|
| 34 |
+ /** Queue Information */ |
|
| 35 |
+ @Getter |
|
| 36 |
+ protected QueueInfo queueInfo = null; |
|
| 30 | 37 |
/** pushBuffer() 함수에서 사용하는 변수 */ |
| 31 | 38 |
protected ByteBuffer dataBuffer = null; |
| 32 | 39 |
|
... | ... | @@ -37,13 +44,13 @@ |
| 37 | 44 |
this.channel = new RandomAccessFile(file, "rw").getChannel(); |
| 38 | 45 |
//this.lock = this.channel.lock(); |
| 39 | 46 |
|
| 40 |
- if(file.length() == 0) {
|
|
| 47 |
+ if (file.length() == 0) {
|
|
| 41 | 48 |
// Push 및 Pop 카운트 초기화 |
| 42 | 49 |
this.createDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
| 43 | 50 |
this.pushCounter = 0; |
| 44 | 51 |
// 헤더 초기화 |
| 45 | 52 |
writeHeader(); |
| 46 |
- }else{
|
|
| 53 |
+ } else {
|
|
| 47 | 54 |
readHeader(); |
| 48 | 55 |
} |
| 49 | 56 |
}catch(Exception e){
|
... | ... | @@ -53,19 +60,19 @@ |
| 53 | 60 |
} |
| 54 | 61 |
} |
| 55 | 62 |
|
| 56 |
- public void readHeader() throws Exception {
|
|
| 63 |
+ protected void readHeader() throws Exception {
|
|
| 57 | 64 |
try {
|
| 58 | 65 |
initHeaderBuffer(); |
| 59 | 66 |
this.channel.position(0); |
| 60 | 67 |
this.channel.read(this.headerBuffer); |
| 61 |
- this.headerArray = new byte[10]; |
|
| 68 |
+ this.headerArray = new byte[QueueHeaderConfig.CREATE_DATE_LENGTH]; |
|
| 62 | 69 |
// 생성날짜 가져오기 - 생성날짜(10) / 읽은카운트(10) / 쓴카운트(10) |
| 63 |
- this.headerBuffer.position(0); |
|
| 70 |
+ this.headerBuffer.position(QueueHeaderConfig.CREATE_DATE_POSITION); |
|
| 64 | 71 |
this.headerBuffer.get(this.headerArray); |
| 65 | 72 |
this.createDate = (new String(this.headerArray)).trim(); |
| 66 | 73 |
// 쓴 카운트 가져오기 |
| 67 |
- this.headerArray = new byte[10]; |
|
| 68 |
- this.headerBuffer.position(10); |
|
| 74 |
+ this.headerArray = new byte[QueueHeaderConfig.PUSH_COUNT_LENGTH]; |
|
| 75 |
+ this.headerBuffer.position(QueueHeaderConfig.PUSH_COUNT_POSITION); |
|
| 69 | 76 |
this.headerBuffer.get(this.headerArray); |
| 70 | 77 |
this.pushCounter = Integer.parseInt((new String(this.headerArray)).trim()); |
| 71 | 78 |
} catch(Exception e) {
|
... | ... | @@ -73,12 +80,12 @@ |
| 73 | 80 |
} |
| 74 | 81 |
} |
| 75 | 82 |
|
| 76 |
- public void writeHeader() throws Exception {
|
|
| 83 |
+ protected void writeHeader() throws Exception {
|
|
| 77 | 84 |
try {
|
| 78 | 85 |
initHeaderBuffer(); |
| 79 |
- this.channel.position(0); |
|
| 86 |
+ this.channel.position(QueueHeaderConfig.CREATE_DATE_POSITION); |
|
| 80 | 87 |
this.headerBuffer.put(this.createDate.getBytes()); |
| 81 |
- this.headerBuffer.position(10); |
|
| 88 |
+ this.headerBuffer.position(QueueHeaderConfig.PUSH_COUNT_POSITION); |
|
| 82 | 89 |
this.headerBuffer.put(Integer.toString(this.pushCounter).getBytes()); |
| 83 | 90 |
this.headerBuffer.flip(); |
| 84 | 91 |
this.channel.write(this.headerBuffer); |
... | ... | @@ -87,7 +94,7 @@ |
| 87 | 94 |
} |
| 88 | 95 |
} |
| 89 | 96 |
|
| 90 |
- public void initHeaderBuffer(){
|
|
| 97 |
+ protected void initHeaderBuffer(){
|
|
| 91 | 98 |
this.headerBuffer.clear(); |
| 92 | 99 |
for(int loopCnt = 0; loopCnt < QueueHeaderConfig.QUEUE_HEADER_LENGTH; loopCnt++){
|
| 93 | 100 |
this.headerBuffer.put(QueueConstants.SET_DEFAULT_BYTE); |
... | ... | @@ -95,9 +102,9 @@ |
| 95 | 102 |
this.headerBuffer.position(0); |
| 96 | 103 |
} |
| 97 | 104 |
|
| 98 |
- public void close() throws IOException {
|
|
| 105 |
+ protected void close() throws IOException {
|
|
| 99 | 106 |
try {
|
| 100 |
- if(channel != null && channel.isOpen()) {
|
|
| 107 |
+ if (isOpen()) {
|
|
| 101 | 108 |
channel.close(); |
| 102 | 109 |
} |
| 103 | 110 |
} catch(IOException e) {
|
... | ... | @@ -105,27 +112,108 @@ |
| 105 | 112 |
} |
| 106 | 113 |
} |
| 107 | 114 |
|
| 108 |
- public void truncateQueue() throws Exception{
|
|
| 109 |
- try {
|
|
| 110 |
- //this.lock = this.channel.lock(); |
|
| 115 |
+ protected boolean isOpen() {
|
|
| 116 |
+ if (this.channel == null) {
|
|
| 117 |
+ return false; |
|
| 118 |
+ } |
|
| 111 | 119 |
|
| 112 |
- if(channel != null && channel.isOpen()) {
|
|
| 113 |
- // 헤더정보 읽기 |
|
| 120 |
+ return this.channel.isOpen(); |
|
| 121 |
+ } |
|
| 122 |
+ |
|
| 123 |
+ protected void truncateQueue() throws Exception{
|
|
| 124 |
+ try {
|
|
| 125 |
+ /* 1. 날짜가 지난경우와 더이상 읽을 데이터가 없을 경우 큐를 초기화 */ |
|
| 126 |
+ String thisDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
| 127 |
+ if (this.createDate.equals(thisDate)) {
|
|
| 128 |
+ return; |
|
| 129 |
+ } |
|
| 130 |
+ |
|
| 131 |
+ if (isOpen()) {
|
|
| 132 |
+ /* 2. 헤더정보 읽기 */ |
|
| 114 | 133 |
readHeader(); |
| 115 |
- String thisDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
| 116 |
- // 날짜가 지난경우와 더이상 읽을 데이터가 없을 경우 큐를 초기화 |
|
| 117 |
- if((this.createDate.equals(thisDate) == false)){
|
|
| 118 |
- // 파일 내용을 모두 지운다. |
|
| 119 |
- channel.truncate(0); |
|
| 120 |
- // 헤더 정보를 초기화한다. |
|
| 121 |
- this.createDate = thisDate; |
|
| 122 |
- this.pushCounter = 0; |
|
| 123 |
- // 헤더에 초기데이터를 저장 |
|
| 124 |
- writeHeader(); |
|
| 125 |
- } |
|
| 134 |
+ /* 3. 파일 내용을 모두 지운다. */ |
|
| 135 |
+ channel.truncate(0); |
|
| 136 |
+ /* 4. 헤더 정보를 초기화한다. */ |
|
| 137 |
+ this.createDate = thisDate; |
|
| 138 |
+ this.pushCounter = 0; |
|
| 139 |
+ /* 5. 헤더에 초기데이터를 저장 */ |
|
| 140 |
+ writeHeader(); |
|
| 126 | 141 |
} |
| 127 | 142 |
} catch(Exception e) {
|
| 128 | 143 |
throw e; |
| 129 | 144 |
} |
| 130 | 145 |
} |
| 146 |
+ |
|
| 147 |
+ public String getQueueName(){
|
|
| 148 |
+ if(this.queueInfo == null) |
|
| 149 |
+ return null; |
|
| 150 |
+ else |
|
| 151 |
+ return this.queueInfo.getQueueName(); |
|
| 152 |
+ } |
|
| 153 |
+ |
|
| 154 |
+ protected int isValidateMessage(BasicMessageDto messageDto) {
|
|
| 155 |
+ int result = isValidateMessageForCommon(messageDto); |
|
| 156 |
+ if (result != ServiceCode.OK.getCode()) {
|
|
| 157 |
+ return result; |
|
| 158 |
+ } |
|
| 159 |
+ |
|
| 160 |
+ return isisValidateMessageForExtend(messageDto); |
|
| 161 |
+ } |
|
| 162 |
+ |
|
| 163 |
+ protected int isValidateMessageForCommon(BasicMessageDto messageDto) {
|
|
| 164 |
+ /* 1. 사용자 아이디 */ |
|
| 165 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserId(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserId(), BodyCommonConfig.USERID_BYTE_LENGTH, true)) {
|
|
| 166 |
+ return ServiceCode.MSG_ERROR_USERID.getCode(); |
|
| 167 |
+ } |
|
| 168 |
+ /* 2. 요금제(선불 : P / 후불 : A) */ |
|
| 169 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getFeeType(), true) || MessageUtil.isOverByteForMessage(messageDto.getFeeType(), BodyCommonConfig.FEETYPE_BYTE_LENGTH, true)) {
|
|
| 170 |
+ return ServiceCode.MSG_ERROR_FEETYPE.getCode(); |
|
| 171 |
+ } |
|
| 172 |
+ /* 3. 단가 */ |
|
| 173 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUnitCost(), true) || MessageUtil.isOverByteForMessage(messageDto.getUnitCost(), BodyCommonConfig.UNITCOST_BYTE_LENGTH, true)) {
|
|
| 174 |
+ return ServiceCode.MSG_ERROR_UNITCOST.getCode(); |
|
| 175 |
+ } |
|
| 176 |
+ /* 4. MSG Group ID */ |
|
| 177 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getMsgGroupID(), true) || MessageUtil.isOverByteForMessage(messageDto.getMsgGroupID(), BodyCommonConfig.MSGGROUPID_BYTE_LENGTH, true)) {
|
|
| 178 |
+ return ServiceCode.MSG_ERROR_MSGGROUPID.getCode(); |
|
| 179 |
+ } |
|
| 180 |
+ /* 5. MSG ID */ |
|
| 181 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserMsgID(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMsgID(), BodyCommonConfig.MSGID_BYTE_LENGTH, true)) {
|
|
| 182 |
+ return ServiceCode.MSG_ERROR_USERMSGID.getCode(); |
|
| 183 |
+ } |
|
| 184 |
+ /* 6. Service Type */ |
|
| 185 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getServiceType(), true) || MessageUtil.isOverByteForMessage(messageDto.getServiceType(), BodyCommonConfig.SERVICETYPE_BYTE_LENGTH, true)) {
|
|
| 186 |
+ return ServiceCode.MSG_ERROR_SERVICETYPE.getCode(); |
|
| 187 |
+ } |
|
| 188 |
+ /* 7. 메시지 전송 결과 >> 성공 : 0 / 필터링 : 기타값 */ |
|
| 189 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getSendStatus(), true) || MessageUtil.isOverByteForMessage(messageDto.getSendStatus(), BodyCommonConfig.SENDSTATUS_BYTE_LENGTH, true)) {
|
|
| 190 |
+ return ServiceCode.MSG_ERROR_SENDSTATUS.getCode(); |
|
| 191 |
+ } |
|
| 192 |
+ /* 8. 회신번호 */ |
|
| 193 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserSender(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSender(), BodyCommonConfig.SENDER_BYTE_LENGTH, true)) {
|
|
| 194 |
+ return ServiceCode.MSG_ERROR_USERSENDER.getCode(); |
|
| 195 |
+ } |
|
| 196 |
+ /* 9. 수신번호 */ |
|
| 197 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getUserReceiver(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserReceiver(), BodyCommonConfig.RECEIVER_BYTE_LENGTH, true)) {
|
|
| 198 |
+ return ServiceCode.MSG_ERROR_USERRECEIVER.getCode(); |
|
| 199 |
+ } |
|
| 200 |
+ /* 10. 요청시간 */ |
|
| 201 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getRequestDt(), true) || MessageUtil.isOverByteForMessage(messageDto.getRequestDt(), BodyCommonConfig.REQUESTDT_BYTE_LENGTH, true)) {
|
|
| 202 |
+ return ServiceCode.MSG_ERROR_REQUESTDT.getCode(); |
|
| 203 |
+ } |
|
| 204 |
+ /* 11. 원격 주소 */ |
|
| 205 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getRemoteIP(), true) || MessageUtil.isOverByteForMessage(messageDto.getRemoteIP(), BodyCommonConfig.REMOTEIP_BYTE_LENGTH, true)) {
|
|
| 206 |
+ return ServiceCode.MSG_ERROR_REMOTEIP.getCode(); |
|
| 207 |
+ } |
|
| 208 |
+ /* 12. 발송망 */ |
|
| 209 |
+ if (MessageUtil.isEmptyForMessage(messageDto.getRouterSeq(), true) || MessageUtil.isOverByteForMessage(messageDto.getRouterSeq(), BodyCommonConfig.AGENT_CODE_BYTE_LENGTH, true)) {
|
|
| 210 |
+ return ServiceCode.MSG_ERROR_ROUTERSEQ.getCode(); |
|
| 211 |
+ } |
|
| 212 |
+ |
|
| 213 |
+ return ServiceCode.OK.getCode(); |
|
| 214 |
+ } |
|
| 215 |
+ |
|
| 216 |
+ abstract int isisValidateMessageForExtend(BasicMessageDto messageDto); |
|
| 217 |
+ abstract void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception; |
|
| 218 |
+ abstract void initDataBuffer(); |
|
| 131 | 219 |
} |
+++ src/main/java/com/munjaon/server/server/service/BaseService.java
... | ... | @@ -0,0 +1,208 @@ |
| 1 | +package com.munjaon.server.server.service; | |
| 2 | + | |
| 3 | +import com.munjaon.server.util.LogUtil; | |
| 4 | + | |
| 5 | +import java.sql.SQLException; | |
| 6 | +import java.text.SimpleDateFormat; | |
| 7 | +import java.time.LocalDateTime; | |
| 8 | +import java.time.format.DateTimeFormatter; | |
| 9 | + | |
| 10 | +public abstract class BaseService extends Thread { | |
| 11 | + boolean bEndProcess = false; | |
| 12 | + | |
| 13 | + public static SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]"); | |
| 14 | + public static String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]"; | |
| 15 | + | |
| 16 | + public boolean ready; | |
| 17 | + private boolean KILL_FLAG; | |
| 18 | + private boolean STOP_FLAG; | |
| 19 | + private boolean RUN_FLAG; | |
| 20 | + private String LOG_FILE; | |
| 21 | + public LogUtil logger; | |
| 22 | + | |
| 23 | + public BaseService() {} | |
| 24 | + | |
| 25 | + public BaseService(String ServiceID) { | |
| 26 | + super(ServiceID); | |
| 27 | + | |
| 28 | + LOG_FILE = getProp("LOG_FILE"); | |
| 29 | + } | |
| 30 | + | |
| 31 | + protected void checkRun() { | |
| 32 | + RUN_FLAG = "1".equals(getProp("RUN_FLAG")) ? true : false; | |
| 33 | + } | |
| 34 | + | |
| 35 | + protected boolean isRun() { | |
| 36 | + return RUN_FLAG && !STOP_FLAG && !KILL_FLAG; | |
| 37 | + } | |
| 38 | + | |
| 39 | + protected void setLogFile(String sLogFile) { | |
| 40 | + if( logger != null ) { | |
| 41 | + logger.close(); | |
| 42 | + logger = null; | |
| 43 | + } | |
| 44 | + | |
| 45 | + logger = new LogUtil( sLogFile ); | |
| 46 | + } | |
| 47 | + | |
| 48 | + protected void Init() throws Exception { | |
| 49 | + LOG_FILE = getProp("LOG_FILE"); | |
| 50 | + | |
| 51 | + setLogFile( LOG_FILE ); | |
| 52 | + | |
| 53 | + SystemLog("Service Initializing..."); | |
| 54 | + | |
| 55 | + ready = true; | |
| 56 | + } | |
| 57 | + | |
| 58 | + public synchronized void Start() { | |
| 59 | + super.start(); | |
| 60 | + } | |
| 61 | + | |
| 62 | + protected synchronized void Stop() { | |
| 63 | + STOP_FLAG = true; | |
| 64 | + | |
| 65 | + SystemLog("Service Stoping..."); | |
| 66 | + } | |
| 67 | + | |
| 68 | + protected synchronized void Kill() { | |
| 69 | + if( !KILL_FLAG ) SystemLog("Service Killing..."); | |
| 70 | + | |
| 71 | + KILL_FLAG = true; | |
| 72 | + } | |
| 73 | + | |
| 74 | + protected void startService() throws Exception { | |
| 75 | + Log("startService() called."); | |
| 76 | + } | |
| 77 | + | |
| 78 | + protected void stopService() throws Exception { | |
| 79 | + Log("stopService() called."); | |
| 80 | + } | |
| 81 | + | |
| 82 | + protected synchronized void Reload() throws Exception { | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Override | |
| 86 | + public void run() { | |
| 87 | + while (!KILL_FLAG) { | |
| 88 | + STOP_FLAG = false; | |
| 89 | + | |
| 90 | + if (isRun()) { | |
| 91 | + try { | |
| 92 | + Init(); | |
| 93 | + | |
| 94 | + SystemLog("Service Starting."); | |
| 95 | + | |
| 96 | + startService(); | |
| 97 | + } catch (SQLException e) { | |
| 98 | + STOP_FLAG = true; | |
| 99 | + SystemLog("SQLErrorCode = "+e.getErrorCode()); | |
| 100 | + SystemLog(e); | |
| 101 | + } catch (Exception e) { | |
| 102 | + STOP_FLAG = true; | |
| 103 | + SystemLog(e); | |
| 104 | + } finally { | |
| 105 | + ready = false; | |
| 106 | + SystemLog("Service Stoped."); | |
| 107 | + if( logger != null ) { logger.close(); logger = null; } | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | + if( !KILL_FLAG ) { | |
| 112 | + try { | |
| 113 | + Thread.sleep(5000); | |
| 114 | + } catch (Exception e) { | |
| 115 | + } | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + try { | |
| 120 | + stopService(); | |
| 121 | + } catch (Exception e) { | |
| 122 | + | |
| 123 | + } | |
| 124 | + SystemLog("Service Killed."); | |
| 125 | + | |
| 126 | + ServiceRunner.SERVICES.remove(getName()); | |
| 127 | + bEndProcess = true; | |
| 128 | + } | |
| 129 | + | |
| 130 | + public void stopThread() { | |
| 131 | + SystemLog("kill signal has been received."); | |
| 132 | + SystemLog("remaining tasks are handled."); | |
| 133 | + | |
| 134 | + bEndProcess = true; | |
| 135 | + Kill(); | |
| 136 | + | |
| 137 | + int i=0; | |
| 138 | + while (true) { | |
| 139 | + try { | |
| 140 | + Thread.sleep(1*1000); | |
| 141 | + } catch(InterruptedException e) { | |
| 142 | + e.printStackTrace(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + if(bEndProcess) { | |
| 146 | + break; | |
| 147 | + } | |
| 148 | + | |
| 149 | + SystemLog("remaining tasks - processing " + (++i) + " secs."); | |
| 150 | + } | |
| 151 | + | |
| 152 | + this.interrupt(); | |
| 153 | + try { | |
| 154 | + Thread.sleep(100); | |
| 155 | + } catch(InterruptedException e) { | |
| 156 | + e.printStackTrace(); | |
| 157 | + } | |
| 158 | + SystemLog("Service was interrupted."); | |
| 159 | + } | |
| 160 | + | |
| 161 | + protected void SystemLog(Object obj) { | |
| 162 | + Log(obj, true); | |
| 163 | + } | |
| 164 | + | |
| 165 | + protected void Log(Object obj) { | |
| 166 | + Log(obj, false); | |
| 167 | + } | |
| 168 | + | |
| 169 | + protected void Log(Object obj, boolean bOut) { | |
| 170 | + if( bOut ) { | |
| 171 | + System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern(LOG_DATE_FORMAT)) + " {{"+ getName() +"}} "+obj); | |
| 172 | + } | |
| 173 | + | |
| 174 | + if( logger != null ) { | |
| 175 | + logger.log(obj); | |
| 176 | + } | |
| 177 | + else { | |
| 178 | + if( obj instanceof Throwable ) { | |
| 179 | + LogUtil.log(LOG_FILE, obj); | |
| 180 | + } | |
| 181 | + else { | |
| 182 | + LogUtil.log(LOG_FILE, "{{"+ getName() +"}} "+obj); | |
| 183 | + } | |
| 184 | + } | |
| 185 | + } | |
| 186 | + | |
| 187 | + protected String getProp(String name) { | |
| 188 | + return getProp(getName(), name); | |
| 189 | + } | |
| 190 | + | |
| 191 | + public static String getProp(String svc, String name) { | |
| 192 | + return PropertyLoader.getProp(svc, name); | |
| 193 | + } | |
| 194 | +} | |
| 195 | + | |
| 196 | +class ShutdownService extends Thread { | |
| 197 | + private BaseService service = null; | |
| 198 | + | |
| 199 | + public ShutdownService(BaseService service) { | |
| 200 | + super(); | |
| 201 | + this.service = service; | |
| 202 | + } | |
| 203 | + | |
| 204 | + @Override | |
| 205 | + public void run() { | |
| 206 | + service.stopThread(); | |
| 207 | + } | |
| 208 | +} |
+++ src/main/java/com/munjaon/server/server/service/PropertyLoader.java
... | ... | @@ -0,0 +1,79 @@ |
| 1 | +package com.munjaon.server.server.service; | |
| 2 | + | |
| 3 | +import java.io.FileInputStream; | |
| 4 | +import java.util.Properties; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * PropertyLoader | |
| 8 | + * @author JDS | |
| 9 | + */ | |
| 10 | +public class PropertyLoader extends Thread { | |
| 11 | + | |
| 12 | + private static Properties props = load(); | |
| 13 | + private static PropertyLoader loader; | |
| 14 | + | |
| 15 | + public static String getProp(String key, String sub) { | |
| 16 | + return get(key+"."+sub); | |
| 17 | + } | |
| 18 | + | |
| 19 | + public static String get(String key) { | |
| 20 | + return get(key, null); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public static String get(String key, String dflt) { | |
| 24 | + if( props == null ) return null; | |
| 25 | + | |
| 26 | + String value = props.getProperty(key, dflt); | |
| 27 | + | |
| 28 | + if( value == null ) { | |
| 29 | + value = dflt; | |
| 30 | + System.err.println("Not Defined : [" + key + "]"); | |
| 31 | + } | |
| 32 | + else { | |
| 33 | + value = value.replaceAll("\\$WORK_HOME", System.getProperty("WORK_HOME")); | |
| 34 | + } | |
| 35 | + | |
| 36 | + return value; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public synchronized static Properties load() { | |
| 40 | + String propFile = System.getProperty("PROPS"); | |
| 41 | + try { | |
| 42 | + Properties properties = new Properties(); | |
| 43 | + properties.load( new FileInputStream (propFile) ); | |
| 44 | + | |
| 45 | + props = properties; | |
| 46 | + } catch(Exception e) { | |
| 47 | + Log(e); | |
| 48 | + } | |
| 49 | + | |
| 50 | + if( loader == null ) { | |
| 51 | + loader = new PropertyLoader(); | |
| 52 | + loader.start(); | |
| 53 | + } | |
| 54 | + | |
| 55 | + return props; | |
| 56 | + } | |
| 57 | + | |
| 58 | + private synchronized static void Log(Object oLog) { | |
| 59 | + if ( oLog instanceof Exception ) { | |
| 60 | + System.out.println( (new java.util.Date()) ); | |
| 61 | + ((Exception)oLog).printStackTrace(); | |
| 62 | + } else { | |
| 63 | + System.out.println( (new java.util.Date()) + (String) oLog ); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public void run() { | |
| 69 | + while( true ) { | |
| 70 | + try { | |
| 71 | + Thread.sleep(1000); | |
| 72 | + load(); | |
| 73 | + } catch(Exception e) { | |
| 74 | + Log(e); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | +} |
+++ src/main/java/com/munjaon/server/server/service/ServiceRunner.java
... | ... | @@ -0,0 +1,124 @@ |
| 1 | +package com.munjaon.server.server.service; | |
| 2 | + | |
| 3 | +import java.io.File; | |
| 4 | +import java.net.URI; | |
| 5 | +import java.net.URL; | |
| 6 | +import java.net.URLClassLoader; | |
| 7 | +import java.util.Enumeration; | |
| 8 | +import java.util.Hashtable; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * | |
| 12 | + * @author JDS | |
| 13 | + */ | |
| 14 | +public class ServiceRunner extends Thread { | |
| 15 | + | |
| 16 | + public static String CLASS_DIR = PropertyLoader.get("SERVICE.CLASS_DIR"); | |
| 17 | + | |
| 18 | + public static Hashtable SERVICES = new Hashtable(); | |
| 19 | + | |
| 20 | + public void run() { | |
| 21 | + while(true) { | |
| 22 | + check(); | |
| 23 | + | |
| 24 | + try { | |
| 25 | + int iCheckCycle = Integer.parseInt(PropertyLoader.get("SERVICE.CHECK_CYCLE","3000")); | |
| 26 | + Thread.sleep( iCheckCycle ); | |
| 27 | + } catch (Exception e) { | |
| 28 | + } | |
| 29 | + } | |
| 30 | + } | |
| 31 | + | |
| 32 | + private void check() { | |
| 33 | + try { | |
| 34 | + String[] svcs = PropertyLoader.get("SERVICE.LISTS").split(","); | |
| 35 | + String svc_name; | |
| 36 | + | |
| 37 | + Hashtable map = new Hashtable(); | |
| 38 | + | |
| 39 | + for( int i=0; i<svcs.length; i++ ) { | |
| 40 | + svc_name = svcs[i].trim(); | |
| 41 | + | |
| 42 | + if( svc_name.length() == 0 || svc_name.startsWith("#") ) { | |
| 43 | + continue; | |
| 44 | + } | |
| 45 | + | |
| 46 | + map.put( svc_name, svc_name ); | |
| 47 | + } | |
| 48 | + | |
| 49 | + Enumeration enums = SERVICES.elements(); | |
| 50 | + | |
| 51 | + while( enums.hasMoreElements() ) { | |
| 52 | + BaseService svc = (BaseService) enums.nextElement(); | |
| 53 | + svc_name = svc.getName(); | |
| 54 | + | |
| 55 | + if( map.containsKey(svc_name) ) { | |
| 56 | + svc.checkRun(); | |
| 57 | + if( svc.isRun() && svc.ready ) { | |
| 58 | + svc.Reload(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + map.remove(svc_name); | |
| 62 | + } | |
| 63 | + else { | |
| 64 | + svc.Kill(); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + enums = map.elements(); | |
| 69 | + | |
| 70 | + ShutdownService shutdownService = null; | |
| 71 | + while ( enums.hasMoreElements() ) { | |
| 72 | + svc_name = (String) enums.nextElement(); | |
| 73 | + | |
| 74 | + if( SERVICES.containsKey(svc_name) ) { | |
| 75 | + System.err.println("Already Started Service: "+ svc_name); | |
| 76 | + continue; | |
| 77 | + } | |
| 78 | + | |
| 79 | + String className = PropertyLoader.get(svc_name + ".CLASS"); | |
| 80 | + | |
| 81 | + Class cls = LoadClass( CLASS_DIR, className ); | |
| 82 | + | |
| 83 | + BaseService svc = (BaseService) cls.newInstance(); | |
| 84 | + svc.setName(svc_name); | |
| 85 | + svc.checkRun(); | |
| 86 | + if( svc.isRun() && svc.ready ) svc.Reload(); | |
| 87 | + | |
| 88 | + SERVICES.put(svc_name, svc); | |
| 89 | + | |
| 90 | + shutdownService = new ShutdownService(svc); | |
| 91 | + Runtime.getRuntime().addShutdownHook(shutdownService); | |
| 92 | + svc.Start(); | |
| 93 | + | |
| 94 | + Thread.sleep(500); | |
| 95 | + } | |
| 96 | + } catch(Exception e) { | |
| 97 | + e.printStackTrace(); | |
| 98 | + } | |
| 99 | + } | |
| 100 | + | |
| 101 | + public static Class LoadClass(String className) throws Exception { | |
| 102 | + Class cls = Class.forName(className.trim()); | |
| 103 | + | |
| 104 | + return cls; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public static Class LoadClass(String path, String className) throws Exception { | |
| 108 | + /** | |
| 109 | + URL url = new File(path).toURL(); | |
| 110 | + URL[] urls = new URL[]{url}; | |
| 111 | + ClassLoader loader = new URLClassLoader(urls); | |
| 112 | + */ | |
| 113 | + URI uri = new File(path).toURI(); | |
| 114 | + URL[] urls = new URL[]{uri.toURL()}; | |
| 115 | + ClassLoader loader = new URLClassLoader(urls); | |
| 116 | + | |
| 117 | + return loader.loadClass(className); | |
| 118 | + } | |
| 119 | + | |
| 120 | + public static void main(String[] args) throws Exception { | |
| 121 | + new ServiceRunner().start(); | |
| 122 | + } | |
| 123 | + | |
| 124 | +} |
+++ src/main/java/com/munjaon/server/util/FileUtil.java
... | ... | @@ -0,0 +1,37 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +import java.io.File; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * 파일 관련 유틸리티 클래스 | |
| 7 | + * @author JDS | |
| 8 | + */ | |
| 9 | +public class FileUtil { | |
| 10 | + | |
| 11 | + public static boolean exists(String sFile) { | |
| 12 | + return exists( new File(sFile) ); | |
| 13 | + } | |
| 14 | + | |
| 15 | + public static boolean exists(File file) { | |
| 16 | + return file.exists(); | |
| 17 | + } | |
| 18 | + | |
| 19 | + public static boolean mkdirs(String sPath) { | |
| 20 | + return mkdirs(sPath, false); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public static boolean mkdirs(String sPath, boolean isFilePath) { | |
| 24 | + File file = new File(sPath); | |
| 25 | + | |
| 26 | + if( isFilePath ) { | |
| 27 | + file = file.getParentFile(); | |
| 28 | + } | |
| 29 | + | |
| 30 | + if( file.exists() ) { | |
| 31 | + return true; | |
| 32 | + } | |
| 33 | + | |
| 34 | + return file.mkdirs(); | |
| 35 | + } | |
| 36 | + | |
| 37 | +} |
+++ src/main/java/com/munjaon/server/util/LogUtil.java
... | ... | @@ -0,0 +1,95 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +import java.io.BufferedWriter; | |
| 4 | +import java.io.FileWriter; | |
| 5 | +import java.io.PrintWriter; | |
| 6 | +import java.text.SimpleDateFormat; | |
| 7 | +import java.util.Date; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 로깅 관련 유틸리티 클래스 | |
| 11 | + * @author JDS | |
| 12 | + */ | |
| 13 | +public class LogUtil { | |
| 14 | + | |
| 15 | + private final static String sTimeFormat = "[HH:mm:ss.SSS] "; | |
| 16 | + private final static String sDateFormat = "_yyyyMMdd"; | |
| 17 | + private final static String sFileExt = ".log"; | |
| 18 | + | |
| 19 | + private PrintWriter out; | |
| 20 | + private String sLogFile; | |
| 21 | + private String sDate; | |
| 22 | + | |
| 23 | + public LogUtil(String sLogFile) { | |
| 24 | + this.sLogFile = sLogFile; | |
| 25 | + | |
| 26 | + if ( sLogFile != null ) { | |
| 27 | + FileUtil.mkdirs(sLogFile, true); | |
| 28 | + } | |
| 29 | + } | |
| 30 | + | |
| 31 | + private void open() { | |
| 32 | + close(); | |
| 33 | + | |
| 34 | + if (sLogFile != null) { | |
| 35 | + try { | |
| 36 | + out = new PrintWriter( new BufferedWriter( new FileWriter(sLogFile + sDate + sFileExt, true) ), true ); | |
| 37 | + } catch(Exception e) { | |
| 38 | + out = null; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + | |
| 42 | + if( out == null ) { | |
| 43 | + out = new PrintWriter(System.out, true); | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + public void close() { | |
| 48 | + if (sLogFile != null && out != null) { | |
| 49 | + try { | |
| 50 | + out.close(); | |
| 51 | + out = null; | |
| 52 | + } catch (Exception e) { | |
| 53 | + } | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + public static void log(String sFile, Object oLog) { | |
| 58 | + LogUtil logger = new LogUtil(sFile); | |
| 59 | + logger.log(oLog); | |
| 60 | + logger.close(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + public synchronized void log(Object oLog) { | |
| 64 | + SimpleDateFormat sdf = new SimpleDateFormat(); | |
| 65 | + Date date = new Date(); | |
| 66 | + | |
| 67 | + sdf.applyPattern(sDateFormat); | |
| 68 | + String sDates = sdf.format(date); | |
| 69 | + | |
| 70 | + sdf.applyPattern(sTimeFormat); | |
| 71 | + String sTime = sdf.format(date); | |
| 72 | + | |
| 73 | + try { | |
| 74 | + if (!sDates.equals(this.sDate)) { | |
| 75 | + this.sDate = sDates; | |
| 76 | + open(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + if (oLog instanceof Exception) { | |
| 80 | + out.print( sTime ); | |
| 81 | + ((Exception)oLog).printStackTrace(out); | |
| 82 | + | |
| 83 | + if (sLogFile == null) { | |
| 84 | + ((Exception)oLog).printStackTrace(); | |
| 85 | + } | |
| 86 | + } else { | |
| 87 | + out.println( sTime + oLog ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + out.flush(); | |
| 91 | + } catch ( Exception e ) { | |
| 92 | + close(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | +} |
--- src/main/java/com/munjaon/server/util/MessageUtil.java
+++ src/main/java/com/munjaon/server/util/MessageUtil.java
... | ... | @@ -1,5 +1,12 @@ |
| 1 | 1 |
package com.munjaon.server.util; |
| 2 | 2 |
|
| 3 |
+import com.munjaon.server.queue.config.BodyCommonConfig; |
|
| 4 |
+import com.munjaon.server.queue.config.MediaBodyConfig; |
|
| 5 |
+import com.munjaon.server.queue.config.QueueHeaderConfig; |
|
| 6 |
+import com.munjaon.server.queue.config.SmsBodyConfig; |
|
| 7 |
+import com.munjaon.server.queue.dto.BasicMessageDto; |
|
| 8 |
+ |
|
| 9 |
+import java.nio.ByteBuffer; |
|
| 3 | 10 |
import java.time.LocalDateTime; |
| 4 | 11 |
import java.time.format.DateTimeFormatter; |
| 5 | 12 |
|
... | ... | @@ -25,22 +32,22 @@ |
| 25 | 32 |
} |
| 26 | 33 |
|
| 27 | 34 |
public static String doNumber(String spell){
|
| 28 |
- String phoneNumber = ""; |
|
| 29 |
- if(spell == null){
|
|
| 30 |
- return phoneNumber; |
|
| 35 |
+ StringBuilder phoneNumber = new StringBuilder(); |
|
| 36 |
+ if (spell == null){
|
|
| 37 |
+ return phoneNumber.toString(); |
|
| 31 | 38 |
} |
| 32 | 39 |
spell = spell.trim(); |
| 33 | 40 |
int spell_Length = spell.length(); |
| 34 |
- if(spell_Length < 1){
|
|
| 35 |
- return phoneNumber; |
|
| 41 |
+ if (spell_Length < 1){
|
|
| 42 |
+ return phoneNumber.toString(); |
|
| 36 | 43 |
} |
| 37 |
- for(int i=0;i<spell_Length;i++){
|
|
| 44 |
+ for (int i=0; i<spell_Length; i++){
|
|
| 38 | 45 |
char eachChar = spell.charAt(i); |
| 39 | 46 |
if( 0x30 <= eachChar && eachChar <= 0x39 ){
|
| 40 |
- phoneNumber += eachChar; |
|
| 47 |
+ phoneNumber.append(eachChar); |
|
| 41 | 48 |
} |
| 42 | 49 |
} |
| 43 |
- return phoneNumber; |
|
| 50 |
+ return phoneNumber.toString(); |
|
| 44 | 51 |
} |
| 45 | 52 |
|
| 46 | 53 |
// 소수점 뒤에 해당하는 자리만큼 자르기 |
... | ... | @@ -49,15 +56,15 @@ |
| 49 | 56 |
String tailNum = ""; |
| 50 | 57 |
String retNum = ""; |
| 51 | 58 |
|
| 52 |
- if(!(srcNum == null || srcNum.trim().equals(""))){
|
|
| 59 |
+ if(!(srcNum == null || srcNum.trim().isEmpty())){
|
|
| 53 | 60 |
srcNum = srcNum.trim(); |
| 54 | 61 |
int index = srcNum.indexOf(".");
|
| 55 | 62 |
// 소수점 위치가 0보다 큰경우만 처리 |
| 56 | 63 |
if(index > 0){
|
| 57 | 64 |
headNum = srcNum.substring(0, index); |
| 58 |
- tailNum = srcNum.substring((index + 1), srcNum.length()); |
|
| 65 |
+ tailNum = srcNum.substring((index + 1)); |
|
| 59 | 66 |
|
| 60 |
- if(tailNum.length() == 0){
|
|
| 67 |
+ if (tailNum.isEmpty()) {
|
|
| 61 | 68 |
tailNum = "0"; |
| 62 | 69 |
} |
| 63 | 70 |
if(tailNum.length() > digit){
|
... | ... | @@ -71,19 +78,120 @@ |
| 71 | 78 |
} |
| 72 | 79 |
|
| 73 | 80 |
// 수신번호 체크하기 |
| 74 |
- public static boolean CheckPhone(String src) {
|
|
| 81 |
+ public static boolean checkPhone(String src) {
|
|
| 75 | 82 |
if(src == null || src.trim().length() < 10) {
|
| 76 | 83 |
return false; |
| 77 | 84 |
} |
| 78 | 85 |
|
| 79 |
- if(!src.startsWith("0")) {
|
|
| 80 |
- return false; |
|
| 81 |
- } |
|
| 82 |
- |
|
| 83 |
- return true; |
|
| 86 |
+ return src.startsWith("0");
|
|
| 84 | 87 |
} |
| 85 | 88 |
// 문자열 공백 제거 |
| 86 | 89 |
public static String trim(String obj) {
|
| 87 | 90 |
return StringUtil.trim(obj); |
| 88 | 91 |
} |
| 92 |
+ |
|
| 93 |
+ public static boolean isEmptyForMessage(String obj, boolean trimFlag) {
|
|
| 94 |
+ if (trimFlag) |
|
| 95 |
+ return obj == null || obj.trim().isEmpty(); |
|
| 96 |
+ else |
|
| 97 |
+ return obj == null || obj.isEmpty(); |
|
| 98 |
+ } |
|
| 99 |
+ |
|
| 100 |
+ public static boolean isEmptyForMessage(String obj) {
|
|
| 101 |
+ return isEmptyForMessage(obj, false); |
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) {
|
|
| 105 |
+ if (isEmptyForMessage(obj, trimFlag)) {
|
|
| 106 |
+ return true; |
|
| 107 |
+ } |
|
| 108 |
+ |
|
| 109 |
+ return obj.getBytes().length > limitCount; |
|
| 110 |
+ } |
|
| 111 |
+ |
|
| 112 |
+ public static boolean isOverByteForMessage(String obj, int limitCount) {
|
|
| 113 |
+ return isOverByteForMessage(obj, limitCount, false); |
|
| 114 |
+ } |
|
| 115 |
+ |
|
| 116 |
+ public static int calcWritePosition(int pushCounter, int dataByteLength) {
|
|
| 117 |
+ return pushCounter < 0 ? QueueHeaderConfig.QUEUE_HEADER_LENGTH : (QueueHeaderConfig.QUEUE_HEADER_LENGTH + pushCounter + dataByteLength); |
|
| 118 |
+ } |
|
| 119 |
+ |
|
| 120 |
+ public static void setBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 121 |
+ /* 1. 사용자 아이디 */ |
|
| 122 |
+ buffer.position(BodyCommonConfig.USERID_BYTE_POSITION); |
|
| 123 |
+ buffer.put(messageDto.getUserId().getBytes()); |
|
| 124 |
+ /* 2. 요금제(선불 : P / 후불 : A) */ |
|
| 125 |
+ buffer.position(BodyCommonConfig.FEETYPE_BYTE_POSITION); |
|
| 126 |
+ buffer.put(messageDto.getFeeType().getBytes()); |
|
| 127 |
+ /* 3. 단가 */ |
|
| 128 |
+ buffer.position(BodyCommonConfig.UNITCOST_BYTE_POSITION); |
|
| 129 |
+ buffer.put(messageDto.getUnitCost().getBytes()); |
|
| 130 |
+ /* 4. MSG Group ID */ |
|
| 131 |
+ buffer.position(BodyCommonConfig.MSGGROUPID_BYTE_POSITION); |
|
| 132 |
+ buffer.put(messageDto.getMsgGroupID().getBytes()); |
|
| 133 |
+ /* 5. MSG ID */ |
|
| 134 |
+ buffer.position(BodyCommonConfig.MSGID_BYTE_POSITION); |
|
| 135 |
+ buffer.put(messageDto.getUserMsgID().getBytes()); |
|
| 136 |
+ /* 6. Service Type */ |
|
| 137 |
+ buffer.position(BodyCommonConfig.SERVICETYPE_BYTE_POSITION); |
|
| 138 |
+ buffer.put(messageDto.getServiceType().getBytes()); |
|
| 139 |
+ /* 7. 메시지 전송 결과 >> 성공 : 0 / 필터링 : 기타값 */ |
|
| 140 |
+ buffer.position(BodyCommonConfig.SENDSTATUS_BYTE_POSITION); |
|
| 141 |
+ buffer.put(messageDto.getSendStatus().getBytes()); |
|
| 142 |
+ /* 8. 회신번호 */ |
|
| 143 |
+ buffer.position(BodyCommonConfig.SENDER_BYTE_POSITION); |
|
| 144 |
+ buffer.put(messageDto.getUserSender().getBytes()); |
|
| 145 |
+ /* 9. 수신번호 */ |
|
| 146 |
+ buffer.position(BodyCommonConfig.RECEIVER_BYTE_POSITION); |
|
| 147 |
+ buffer.put(messageDto.getUserReceiver().getBytes()); |
|
| 148 |
+ /* 10. 예약시간 */ |
|
| 149 |
+ buffer.position(BodyCommonConfig.RESERVEDT_BYTE_POSITION); |
|
| 150 |
+ buffer.put(messageDto.getReserveDt().getBytes()); |
|
| 151 |
+ /* 11. 요청시간 */ |
|
| 152 |
+ buffer.position(BodyCommonConfig.REQUESTDT_BYTE_POSITION); |
|
| 153 |
+ buffer.put(messageDto.getRequestDt().getBytes()); |
|
| 154 |
+ /* 12. 원격 주소 */ |
|
| 155 |
+ buffer.position(BodyCommonConfig.REMOTEIP_BYTE_POSITION); |
|
| 156 |
+ buffer.put(messageDto.getRemoteIP().getBytes()); |
|
| 157 |
+ /* 13. 발송망 */ |
|
| 158 |
+ buffer.position(BodyCommonConfig.AGENT_CODE_BYTE_POSITION); |
|
| 159 |
+ buffer.put(messageDto.getRouterSeq().getBytes()); |
|
| 160 |
+ } |
|
| 161 |
+ |
|
| 162 |
+ public static void setBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 163 |
+ /* 14. 메시지 */ |
|
| 164 |
+ buffer.position(SmsBodyConfig.SMS_MSG_BYTE_POSITION); |
|
| 165 |
+ buffer.put(messageDto.getUserMessage().getBytes()); |
|
| 166 |
+ } |
|
| 167 |
+ |
|
| 168 |
+ public static void setBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 169 |
+ /* 14. 제목 */ |
|
| 170 |
+ buffer.position(MediaBodyConfig.SUBJECT_BYTE_POSITION); |
|
| 171 |
+ buffer.put(messageDto.getUserSubject().getBytes()); |
|
| 172 |
+ /* 15. 메시지 */ |
|
| 173 |
+ buffer.position(MediaBodyConfig.MEDIA_MSG_BYTE_POSITION); |
|
| 174 |
+ buffer.put(messageDto.getUserMessage().getBytes()); |
|
| 175 |
+ } |
|
| 176 |
+ |
|
| 177 |
+ public static void setBytesForMmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
|
| 178 |
+ /* 16. 파일카운트 */ |
|
| 179 |
+ buffer.position(MediaBodyConfig.FILECNT_BYTE_POSITION); |
|
| 180 |
+ buffer.put(Integer.toString(messageDto.getUserFileCnt()).getBytes()); |
|
| 181 |
+ /* 17. 파일명 #1 */ |
|
| 182 |
+ buffer.position(MediaBodyConfig.FILENAME_ONE_BYTE_POSITION); |
|
| 183 |
+ if (messageDto.getUserFileName01() != null) {
|
|
| 184 |
+ buffer.put(messageDto.getUserFileName01().getBytes()); |
|
| 185 |
+ } |
|
| 186 |
+ /* 18. 파일명 #2 */ |
|
| 187 |
+ buffer.position(MediaBodyConfig.FILENAME_TWO_BYTE_POSITION); |
|
| 188 |
+ if (messageDto.getUserFileName02() != null) {
|
|
| 189 |
+ buffer.put(messageDto.getUserFileName02().getBytes()); |
|
| 190 |
+ } |
|
| 191 |
+ /* 19. 파일명 #3 */ |
|
| 192 |
+ buffer.position(MediaBodyConfig.FILENAME_THREE_BYTE_POSITION); |
|
| 193 |
+ if (messageDto.getUserFileName03() != null) {
|
|
| 194 |
+ buffer.put(messageDto.getUserFileName03().getBytes()); |
|
| 195 |
+ } |
|
| 196 |
+ } |
|
| 89 | 197 |
} |
+++ src/main/java/com/munjaon/server/util/XmlUtil.java
... | ... | @@ -0,0 +1,31 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +import org.w3c.dom.Document; | |
| 4 | +import org.xml.sax.SAXException; | |
| 5 | + | |
| 6 | +import javax.xml.parsers.DocumentBuilder; | |
| 7 | +import javax.xml.parsers.DocumentBuilderFactory; | |
| 8 | +import javax.xml.parsers.ParserConfigurationException; | |
| 9 | +import java.io.File; | |
| 10 | +import java.io.IOException; | |
| 11 | + | |
| 12 | +public class XmlUtil { | |
| 13 | + private static Document getDOMParsedDocument(final String fileName) { | |
| 14 | + Document document = null; | |
| 15 | + try { | |
| 16 | + | |
| 17 | + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
| 18 | + //If want to make namespace aware. | |
| 19 | + //factory.setNamespaceAware(true); | |
| 20 | + DocumentBuilder documentBuilder = factory.newDocumentBuilder(); | |
| 21 | + document = documentBuilder.parse(new File("employee.xml")); | |
| 22 | + } | |
| 23 | + catch (IOException | SAXException | ParserConfigurationException e) { | |
| 24 | + e.printStackTrace(); | |
| 25 | + } | |
| 26 | + return document; | |
| 27 | + } | |
| 28 | + public static void main(String[] args) { | |
| 29 | + | |
| 30 | + } | |
| 31 | +} |
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?