큐설정, 통신 규격, 배치 수정
This commit is contained in:
parent
47f9eab3d3
commit
e857310b62
@ -9,9 +9,8 @@ import lombok.ToString;
|
||||
@ToString
|
||||
public class MemberDto {
|
||||
private String mberId;
|
||||
private String esntlId;
|
||||
private String accessKey;
|
||||
private String mberSttus;
|
||||
private String dept;
|
||||
private float shortPrice;
|
||||
private float longPrice;
|
||||
private float picturePrice;
|
||||
@ -21,6 +20,23 @@ public class MemberDto {
|
||||
private float kakaoFtPrice;
|
||||
private float kakaoFtImgPrice;
|
||||
private float kakaoFtWideImgPrice;
|
||||
private float faxPrice;
|
||||
private float userMoney;
|
||||
|
||||
private String smsUseYn;
|
||||
private String lmsUseYn;
|
||||
private String mmsUseYn;
|
||||
private String kakaoAtUseYn;
|
||||
private String kakaoFtUseYn;
|
||||
private int smsLimitCount;
|
||||
private int lmsLimitCount;
|
||||
private int mmsLimitCount;
|
||||
private int kakaoAtLimitCount;
|
||||
private int kakaoFtLimitCount;
|
||||
private String smsAgentCode;
|
||||
private String lmsAgentCode;
|
||||
private String mmsAgentCode;
|
||||
private String kakaoAtAgentCode;
|
||||
private String kakaoFtAgentCode;
|
||||
private String ipLimitYn;
|
||||
private String allowIpBasic;
|
||||
private String allowIpExtend;
|
||||
}
|
||||
|
||||
@ -11,7 +11,8 @@ public interface MemberMapper {
|
||||
* 회원테이블 마지막으로 변경된 시간 조회
|
||||
* @return
|
||||
*/
|
||||
String getLastModifiedTime(String tableSchema);
|
||||
String getMemberLastModifiedTime(String tableSchema);
|
||||
String getConfigLastModifiedTime(String tableSchema);
|
||||
|
||||
/**
|
||||
* 회원 전체 목록
|
||||
|
||||
@ -21,8 +21,12 @@ public class MemberService {
|
||||
* 회원테이블 마지막으로 변경된 시간 조회
|
||||
* @return
|
||||
*/
|
||||
public String getLastModifiedTime(String tableSchema) {
|
||||
return memberMapper.getLastModifiedTime(tableSchema);
|
||||
public String getMemberLastModifiedTime(String tableSchema) {
|
||||
return memberMapper.getMemberLastModifiedTime(tableSchema);
|
||||
}
|
||||
|
||||
public String getConfigLastModifiedTime(String tableSchema) {
|
||||
return memberMapper.getConfigLastModifiedTime(tableSchema);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -17,6 +17,7 @@ public class RunnerConfiguration {
|
||||
@Order(1)
|
||||
public CommandLineRunner getRunnerBeanForProperty() {
|
||||
System.setProperty("PROPS", serverConfig.getServerProperyFile());
|
||||
System.setProperty("ROOTPATH", serverConfig.getServerRootPath());
|
||||
PropertyLoader.load();
|
||||
try {
|
||||
String[] array = serverConfig.getStringArray("test.list");
|
||||
|
||||
@ -24,6 +24,10 @@ public class ServerConfig {
|
||||
@Value("${agent.server-property-file}")
|
||||
private String serverProperyFile;
|
||||
|
||||
@Getter
|
||||
@Value("${agent.root-path}")
|
||||
private String serverRootPath;
|
||||
|
||||
private ReloadingFileBasedConfigurationBuilder<PropertiesConfiguration> builder;
|
||||
|
||||
@PostConstruct
|
||||
|
||||
@ -12,7 +12,8 @@ import lombok.ToString;
|
||||
public class QueueInfo {
|
||||
private String queueName = "";
|
||||
private String queueFileName = "";
|
||||
private int queueDataLength = 0;
|
||||
// private int queueDataLength = 0;
|
||||
private String serviceType = "";
|
||||
private String readXMLFileName = "";
|
||||
private boolean isRun;
|
||||
}
|
||||
|
||||
@ -4,10 +4,11 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum QueueService {
|
||||
SMS_QUEUE,
|
||||
LMS_QUEUE,
|
||||
MMS_QUEUE,
|
||||
KAKAO_QUEUE;
|
||||
SMS_QUEUE_SERVICE,
|
||||
LMS_QUEUE_SERVICE,
|
||||
MMS_QUEUE_SERVICE,
|
||||
KAT_QUEUE_SERVICE,
|
||||
KFT_QUEUE_SERVICE;
|
||||
|
||||
private Object service;
|
||||
|
||||
|
||||
@ -0,0 +1,189 @@
|
||||
package com.munjaon.server.queue.enums;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import com.munjaon.server.queue.service.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Getter
|
||||
public enum QueueTypeWorker {
|
||||
MSG_TYPE_SMS("SMS") {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService();
|
||||
return smsQueueService.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService();
|
||||
smsQueueService.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService();
|
||||
smsQueueService.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService();
|
||||
smsQueueService.pushQueue(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
SmsQueueService smsQueueService = (SmsQueueService) QueueService.SMS_QUEUE_SERVICE.getService();
|
||||
return smsQueueService.saveMessageToTable(data);
|
||||
}
|
||||
},
|
||||
MSG_TYPE_LMS("LMS") {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService();
|
||||
return lmsQueueService.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService();
|
||||
lmsQueueService.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService();
|
||||
lmsQueueService.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService();
|
||||
lmsQueueService.pushQueue(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
LmsQueueService lmsQueueService = (LmsQueueService) QueueService.LMS_QUEUE_SERVICE.getService();
|
||||
return lmsQueueService.saveMessageToTable(data);
|
||||
}
|
||||
},
|
||||
MSG_TYPE_MMS("MMS") {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService();
|
||||
return mmsQueueService.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService();
|
||||
mmsQueueService.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService();
|
||||
mmsQueueService.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService();
|
||||
mmsQueueService.pushQueue(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
MmsQueueService mmsQueueService = (MmsQueueService) QueueService.MMS_QUEUE_SERVICE.getService();
|
||||
return mmsQueueService.saveMessageToTable(data);
|
||||
}
|
||||
},
|
||||
MSG_TYPE_KAT("KAT") {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService();
|
||||
return kakaoAlarmQueueService.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService();
|
||||
kakaoAlarmQueueService.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService();
|
||||
kakaoAlarmQueueService.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService();
|
||||
kakaoAlarmQueueService.pushQueue(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
KakaoAlarmQueueService kakaoAlarmQueueService = (KakaoAlarmQueueService) QueueService.KAT_QUEUE_SERVICE.getService();
|
||||
return kakaoAlarmQueueService.saveMessageToTable(data);
|
||||
}
|
||||
},
|
||||
MSG_TYPE_KFT("KFT") {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService();
|
||||
return kakaoFriendQueueService.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService();
|
||||
kakaoFriendQueueService.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService();
|
||||
kakaoFriendQueueService.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService();
|
||||
kakaoFriendQueueService.pushQueue(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
KakaoFriendQueueService kakaoFriendQueueService = (KakaoFriendQueueService) QueueService.KFT_QUEUE_SERVICE.getService();
|
||||
return kakaoFriendQueueService.saveMessageToTable(data);
|
||||
}
|
||||
};
|
||||
|
||||
QueueTypeWorker(final String name) {
|
||||
this.type = name;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
public static QueueTypeWorker find(String type) {
|
||||
for (QueueTypeWorker queueTypeWorker : EnumSet.allOf(QueueTypeWorker.class)) {
|
||||
if (type.equals(queueTypeWorker.getType())) {
|
||||
return queueTypeWorker;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean isExistQueue(String name);
|
||||
public abstract void removeQueue(String name);
|
||||
public abstract void addQueue(WriteQueue queue);
|
||||
public abstract void pushQueue(BasicMessageDto data);
|
||||
public abstract int saveMessageToTable(BasicMessageDto data);
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
public class KakaoAlarmQueuePool extends QueuePool {
|
||||
/** Singleton Instance */
|
||||
private static KakaoAlarmQueuePool queueInstance;
|
||||
|
||||
private KakaoAlarmQueuePool() {}
|
||||
|
||||
public synchronized static KakaoAlarmQueuePool getInstance(){
|
||||
if(queueInstance == null){
|
||||
queueInstance = new KakaoAlarmQueuePool();
|
||||
}
|
||||
return queueInstance;
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
|
||||
public class KakaoWriteQueue extends WriteQueue {
|
||||
public class KakaoAlarmWriteQueue extends WriteQueue {
|
||||
|
||||
@Override
|
||||
int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
public class KakaoFriendQueuePool extends QueuePool {
|
||||
/** Singleton Instance */
|
||||
private static KakaoFriendQueuePool queueInstance;
|
||||
|
||||
private KakaoFriendQueuePool() {}
|
||||
|
||||
public synchronized static KakaoFriendQueuePool getInstance(){
|
||||
if(queueInstance == null){
|
||||
queueInstance = new KakaoFriendQueuePool();
|
||||
}
|
||||
return queueInstance;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
|
||||
public class KakaoFriendWriteQueue extends WriteQueue {
|
||||
@Override
|
||||
int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
void initDataBuffer() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,84 +1,15 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.service.LmsWriteQueue;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class LmsQueuePool {
|
||||
/** Lock Object */
|
||||
private final Object lockMonitor = new Object();
|
||||
/** File Queue Pool */
|
||||
private final LinkedList<LmsWriteQueue> queuePool = new LinkedList<>();
|
||||
/** File Queue */
|
||||
private LmsWriteQueue queue = null;
|
||||
/** File Queue 분배를 위한 인덱서 */
|
||||
private int queueIndex = 0;
|
||||
|
||||
public class LmsQueuePool extends QueuePool {
|
||||
/** Singleton Instance */
|
||||
private static SmsQueuePool fileQueue;
|
||||
private static LmsQueuePool queueInstance;
|
||||
|
||||
public synchronized static SmsQueuePool getInstance(){
|
||||
if(fileQueue == null){
|
||||
fileQueue = new SmsQueuePool();
|
||||
}
|
||||
return fileQueue;
|
||||
}
|
||||
private LmsQueuePool() {}
|
||||
|
||||
/** Queue 존재하는지 조회 */
|
||||
public boolean isExistQueue(String name){
|
||||
synchronized(lockMonitor){
|
||||
boolean isExist = false;
|
||||
for (LmsWriteQueue writeQueue : queuePool) {
|
||||
if (name.equals(writeQueue.getQueueName())) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
}
|
||||
/** Queue 제거 */
|
||||
public void removeQueue(String name){
|
||||
synchronized(lockMonitor) {
|
||||
for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) {
|
||||
queue = queuePool.get(loopCnt);
|
||||
if(name.equals(queue.getQueueName())){
|
||||
queuePool.remove(loopCnt);
|
||||
System.out.println("[LMS Queue] [" + queue.getQueueName() + " is Removed]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 등록 */
|
||||
public void addShortQueue(LmsWriteQueue queue){
|
||||
synchronized(lockMonitor){
|
||||
if (queue != null){
|
||||
queuePool.addLast(queue);
|
||||
lockMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 데이터 저장 */
|
||||
public void pushQueue(BasicMessageDto data) throws Exception{
|
||||
synchronized(lockMonitor) {
|
||||
if (queuePool.isEmpty()) {
|
||||
try{
|
||||
lockMonitor.wait();
|
||||
}catch(InterruptedException e){
|
||||
// 아무 처리도 하지 않는다.
|
||||
}
|
||||
}
|
||||
//큐리스트의 끝까지 이동한 경우 처음으로 되돌린다.
|
||||
if (queueIndex >= queuePool.size()) {
|
||||
queueIndex = 0;
|
||||
}
|
||||
// 파일큐에 Push 한다.
|
||||
queue = queuePool.get(queueIndex);
|
||||
queue.pushMessageToBuffer(data);
|
||||
// 큐인덱서를 증가시킨다.
|
||||
queueIndex++;
|
||||
public synchronized static LmsQueuePool getInstance(){
|
||||
if(queueInstance == null){
|
||||
queueInstance = new LmsQueuePool();
|
||||
}
|
||||
return queueInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.MediaBodyConfig;
|
||||
@ -11,7 +11,7 @@ import java.nio.ByteBuffer;
|
||||
public class LmsWriteQueue extends WriteQueue {
|
||||
|
||||
@Override
|
||||
public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
@ -1,84 +1,15 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.service.MmsWriteQueue;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class MmsQueuePool {
|
||||
/** Lock Object */
|
||||
private final Object lockMonitor = new Object();
|
||||
/** File Queue Pool */
|
||||
private final LinkedList<MmsWriteQueue> queuePool = new LinkedList<>();
|
||||
/** File Queue */
|
||||
private MmsWriteQueue queue = null;
|
||||
/** File Queue 분배를 위한 인덱서 */
|
||||
private int queueIndex = 0;
|
||||
|
||||
public class MmsQueuePool extends QueuePool {
|
||||
/** Singleton Instance */
|
||||
private static SmsQueuePool fileQueue;
|
||||
private static MmsQueuePool queueInstance;
|
||||
|
||||
public synchronized static SmsQueuePool getInstance(){
|
||||
if(fileQueue == null){
|
||||
fileQueue = new SmsQueuePool();
|
||||
}
|
||||
return fileQueue;
|
||||
}
|
||||
private MmsQueuePool() {}
|
||||
|
||||
/** Queue 존재하는지 조회 */
|
||||
public boolean isExistQueue(String name){
|
||||
synchronized(lockMonitor){
|
||||
boolean isExist = false;
|
||||
for (MmsWriteQueue writeQueue : queuePool) {
|
||||
if (name.equals(writeQueue.getQueueName())) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
}
|
||||
/** Queue 제거 */
|
||||
public void removeQueue(String name){
|
||||
synchronized(lockMonitor) {
|
||||
for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) {
|
||||
queue = queuePool.get(loopCnt);
|
||||
if(name.equals(queue.getQueueName())){
|
||||
queuePool.remove(loopCnt);
|
||||
System.out.println("[MMS Queue] [" + queue.getQueueName() + " is Removed]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 등록 */
|
||||
public void addShortQueue(MmsWriteQueue queue){
|
||||
synchronized(lockMonitor){
|
||||
if (queue != null){
|
||||
queuePool.addLast(queue);
|
||||
lockMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 데이터 저장 */
|
||||
public void pushQueue(BasicMessageDto data) throws Exception{
|
||||
synchronized(lockMonitor) {
|
||||
if (queuePool.isEmpty()) {
|
||||
try{
|
||||
lockMonitor.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// 아무 처리도 하지 않는다.
|
||||
}
|
||||
}
|
||||
//큐리스트의 끝까지 이동한 경우 처음으로 되돌린다.
|
||||
if (queueIndex >= queuePool.size()) {
|
||||
queueIndex = 0;
|
||||
}
|
||||
// 파일큐에 Push 한다.
|
||||
queue = queuePool.get(queueIndex);
|
||||
queue.pushMessageToBuffer(data);
|
||||
// 큐인덱서를 증가시킨다.
|
||||
queueIndex++;
|
||||
public synchronized static MmsQueuePool getInstance(){
|
||||
if(queueInstance == null){
|
||||
queueInstance = new MmsQueuePool();
|
||||
}
|
||||
return queueInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.MediaBodyConfig;
|
||||
@ -11,7 +11,7 @@ import java.nio.ByteBuffer;
|
||||
public class MmsWriteQueue extends WriteQueue {
|
||||
|
||||
@Override
|
||||
public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
77
src/main/java/com/munjaon/server/queue/pool/QueuePool.java
Normal file
77
src/main/java/com/munjaon/server/queue/pool/QueuePool.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public abstract class QueuePool {
|
||||
/** Lock Object */
|
||||
protected final Object lockMonitor = new Object();
|
||||
/** File Queue Pool */
|
||||
protected final LinkedList<WriteQueue> queuePool = new LinkedList<>();
|
||||
/** File Queue */
|
||||
protected WriteQueue queue = null;
|
||||
/** File Queue 분배를 위한 인덱서 */
|
||||
protected int queueIndex = 0;
|
||||
|
||||
/** Queue 존재하는지 조회 */
|
||||
public boolean isExistQueue(String name){
|
||||
synchronized (lockMonitor) {
|
||||
boolean isExist = false;
|
||||
for (WriteQueue writeQueue : queuePool) {
|
||||
if (name.equals(writeQueue.getQueueName())) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isExist;
|
||||
}
|
||||
}
|
||||
|
||||
/** Queue 제거 */
|
||||
public void removeQueue(String name) {
|
||||
synchronized (lockMonitor) {
|
||||
for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) {
|
||||
queue = queuePool.get(loopCnt);
|
||||
if(name.equals(queue.getQueueName())){
|
||||
queuePool.remove(loopCnt);
|
||||
System.out.println("[" + queue.getQueueInfo().getServiceType() + " Queue] [" + queue.getQueueName() + " is Removed]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Queue 등록 */
|
||||
public void addQueue(WriteQueue queue) {
|
||||
synchronized(lockMonitor){
|
||||
if (queue != null){
|
||||
queuePool.addLast(queue);
|
||||
lockMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Queue 데이터 저장 */
|
||||
public void pushQueue(BasicMessageDto data) throws Exception {
|
||||
synchronized(lockMonitor) {
|
||||
if (queuePool.isEmpty()) {
|
||||
try{
|
||||
lockMonitor.wait();
|
||||
}catch(InterruptedException e){
|
||||
// 아무 처리도 하지 않는다.
|
||||
}
|
||||
}
|
||||
//큐리스트의 끝까지 이동한 경우 처음으로 되돌린다.
|
||||
if (queueIndex >= queuePool.size()) {
|
||||
queueIndex = 0;
|
||||
}
|
||||
// 파일큐에 Push 한다.
|
||||
queue = queuePool.get(queueIndex);
|
||||
queue.pushMessageToBuffer(data);
|
||||
// 큐인덱서를 증가시킨다.
|
||||
queueIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,84 +1,15 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.service.SmsWriteQueue;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class SmsQueuePool {
|
||||
/** Lock Object */
|
||||
private final Object lockMonitor = new Object();
|
||||
/** File Queue Pool */
|
||||
private final LinkedList<SmsWriteQueue> queuePool = new LinkedList<>();
|
||||
/** File Queue */
|
||||
private SmsWriteQueue queue = null;
|
||||
/** File Queue 분배를 위한 인덱서 */
|
||||
private int queueIndex = 0;
|
||||
|
||||
public class SmsQueuePool extends QueuePool {
|
||||
/** Singleton Instance */
|
||||
private static SmsQueuePool fileQueue;
|
||||
private static SmsQueuePool queueInstance = null;
|
||||
|
||||
private SmsQueuePool() {}
|
||||
|
||||
public synchronized static SmsQueuePool getInstance(){
|
||||
if(fileQueue == null){
|
||||
fileQueue = new SmsQueuePool();
|
||||
}
|
||||
return fileQueue;
|
||||
}
|
||||
|
||||
/** Queue 존재하는지 조회 */
|
||||
public boolean isExistQueue(String name){
|
||||
synchronized(lockMonitor){
|
||||
boolean isExist = false;
|
||||
for (SmsWriteQueue writeQueue : queuePool) {
|
||||
if (name.equals(writeQueue.getQueueName())) {
|
||||
isExist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
}
|
||||
/** Queue 제거 */
|
||||
public void removeQueue(String name){
|
||||
synchronized(lockMonitor) {
|
||||
for (int loopCnt = 0; loopCnt < queuePool.size(); loopCnt++) {
|
||||
queue = queuePool.get(loopCnt);
|
||||
if(name.equals(queue.getQueueName())){
|
||||
queuePool.remove(loopCnt);
|
||||
System.out.println("[SMS Queue] [" + queue.getQueueName() + " is Removed]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 등록 */
|
||||
public void addShortQueue(SmsWriteQueue queue){
|
||||
synchronized(lockMonitor){
|
||||
if (queue != null){
|
||||
queuePool.addLast(queue);
|
||||
lockMonitor.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
/** Queue 데이터 저장 */
|
||||
public void pushQueue(BasicMessageDto data) throws Exception{
|
||||
synchronized(lockMonitor) {
|
||||
if (queuePool.isEmpty()) {
|
||||
try{
|
||||
lockMonitor.wait();
|
||||
}catch(InterruptedException e){
|
||||
// 아무 처리도 하지 않는다.
|
||||
}
|
||||
}
|
||||
//큐리스트의 끝까지 이동한 경우 처음으로 되돌린다.
|
||||
if (queueIndex >= queuePool.size()) {
|
||||
queueIndex = 0;
|
||||
}
|
||||
// 파일큐에 Push 한다.
|
||||
queue = queuePool.get(queueIndex);
|
||||
queue.pushMessageToBuffer(data);
|
||||
// 큐인덱서를 증가시킨다.
|
||||
queueIndex++;
|
||||
if(queueInstance == null){
|
||||
queueInstance = new SmsQueuePool();
|
||||
}
|
||||
return queueInstance;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.QueueConstants;
|
||||
@ -17,7 +17,7 @@ public class SmsWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isisValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
/* 13. 메시지 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserMessage(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMessage(), SmsBodyConfig.SMS_MSG_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_SMS_MESSAGE.getCode();
|
||||
@ -1,4 +1,4 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.BodyCommonConfig;
|
||||
@ -157,7 +157,7 @@ public abstract class WriteQueue {
|
||||
return result;
|
||||
}
|
||||
|
||||
return isisValidateMessageForExtend(messageDto);
|
||||
return isValidateMessageForExtend(messageDto);
|
||||
}
|
||||
|
||||
protected int isValidateMessageForCommon(BasicMessageDto messageDto) {
|
||||
@ -213,7 +213,7 @@ public abstract class WriteQueue {
|
||||
return ServiceCode.OK.getCode();
|
||||
}
|
||||
|
||||
abstract int isisValidateMessageForExtend(BasicMessageDto messageDto);
|
||||
abstract int isValidateMessageForExtend(BasicMessageDto messageDto);
|
||||
abstract void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception;
|
||||
abstract void initDataBuffer();
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KakaoAlarmQueueService implements QueueAction {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KakaoFriendQueueService implements QueueAction {
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KakaoQueueService {
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.LmsQueuePool;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -7,5 +10,40 @@ import org.springframework.stereotype.Service;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LmsQueueService {
|
||||
public class LmsQueueService implements QueueAction {
|
||||
private final LmsQueuePool queueInstance = LmsQueuePool.getInstance();
|
||||
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
return queueInstance.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
queueInstance.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
queueInstance.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
boolean isError = false;
|
||||
try {
|
||||
queueInstance.pushQueue(data);
|
||||
} catch (Exception e) {
|
||||
isError = true;
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
if (isError) {
|
||||
log.error("Push queue failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.MmsQueuePool;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -7,5 +10,39 @@ import org.springframework.stereotype.Service;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MmsQueueService {
|
||||
public class MmsQueueService implements QueueAction {
|
||||
private final MmsQueuePool queueInstance = MmsQueuePool.getInstance();
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
return queueInstance.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
queueInstance.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
queueInstance.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
boolean isError = false;
|
||||
try {
|
||||
queueInstance.pushQueue(data);
|
||||
} catch (Exception e) {
|
||||
isError = true;
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
if (isError) {
|
||||
log.error("Push queue failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
|
||||
public interface QueueAction {
|
||||
boolean isExistQueue(String name);
|
||||
void removeQueue(String name);
|
||||
void addQueue(WriteQueue queue);
|
||||
void pushQueue(BasicMessageDto data);
|
||||
int saveMessageToTable(BasicMessageDto data);
|
||||
}
|
||||
@ -16,19 +16,23 @@ public class QueueServiceInjector {
|
||||
@Autowired
|
||||
private MmsQueueService mmsQueueService;
|
||||
@Autowired
|
||||
private KakaoQueueService kakaoQueueService;
|
||||
private KakaoAlarmQueueService kakaoAlarmQueueService;
|
||||
@Autowired
|
||||
private KakaoFriendQueueService kakaoFriendQueueService;
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
for (QueueService svc : EnumSet.allOf(QueueService.class)) {
|
||||
switch (svc) {
|
||||
case SMS_QUEUE: svc.setService(smsQueueService);
|
||||
case SMS_QUEUE_SERVICE: svc.setService(smsQueueService);
|
||||
break;
|
||||
case LMS_QUEUE: svc.setService(lmsQueueService);
|
||||
case LMS_QUEUE_SERVICE: svc.setService(lmsQueueService);
|
||||
break;
|
||||
case MMS_QUEUE: svc.setService(mmsQueueService);
|
||||
case MMS_QUEUE_SERVICE: svc.setService(mmsQueueService);
|
||||
break;
|
||||
case KAKAO_QUEUE: svc.setService(kakaoQueueService);
|
||||
case KAT_QUEUE_SERVICE: svc.setService(kakaoAlarmQueueService);
|
||||
break;
|
||||
case KFT_QUEUE_SERVICE: svc.setService(kakaoFriendQueueService);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.server.queue.service;
|
||||
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.pool.SmsQueuePool;
|
||||
import com.munjaon.server.queue.pool.WriteQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -7,5 +10,40 @@ import org.springframework.stereotype.Service;
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsQueueService {
|
||||
public class SmsQueueService implements QueueAction {
|
||||
private final SmsQueuePool queueInstance = SmsQueuePool.getInstance();
|
||||
|
||||
@Override
|
||||
public boolean isExistQueue(String name) {
|
||||
return queueInstance.isExistQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeQueue(String name) {
|
||||
queueInstance.removeQueue(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addQueue(WriteQueue queue) {
|
||||
queueInstance.addQueue(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushQueue(BasicMessageDto data) {
|
||||
boolean isError = false;
|
||||
try {
|
||||
queueInstance.pushQueue(data);
|
||||
} catch (Exception e) {
|
||||
isError = true;
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
if (isError) {
|
||||
log.error("Push queue failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMessageToTable(BasicMessageDto data) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,8 @@ public class CacheScheduleService {
|
||||
private String tableSchema;
|
||||
/* 사용자 테이블 마지막 업데이트 시간 */
|
||||
private String member_last_modified_time = null;
|
||||
/* 사용자 설정 테이블 마지막 업데이트 시간 */
|
||||
private String config_last_modified_time = null;
|
||||
|
||||
@Scheduled(cron="0/5 * * * * *")
|
||||
public void doService() throws Exception {
|
||||
@ -24,18 +26,19 @@ public class CacheScheduleService {
|
||||
}
|
||||
|
||||
private void doMemberService() {
|
||||
if (member_last_modified_time == null) {
|
||||
if (member_last_modified_time == null || config_last_modified_time == null) {
|
||||
log.info("Member List Info is First Caching~~~");
|
||||
memberService.deleteAllMember();
|
||||
// memberService.list();
|
||||
|
||||
/* 회원 정보 마지막 변경시간 저장 */
|
||||
member_last_modified_time = memberService.getLastModifiedTime(tableSchema);
|
||||
member_last_modified_time = memberService.getMemberLastModifiedTime(tableSchema);
|
||||
config_last_modified_time = memberService.getConfigLastModifiedTime(tableSchema);
|
||||
return;
|
||||
}
|
||||
|
||||
/* 변경이 없는 경우 */
|
||||
if (member_last_modified_time.equals(memberService.getLastModifiedTime(tableSchema))) {
|
||||
if (member_last_modified_time.equals(memberService.getMemberLastModifiedTime(tableSchema)) && config_last_modified_time.equals(memberService.getConfigLastModifiedTime(tableSchema))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -44,6 +47,7 @@ public class CacheScheduleService {
|
||||
memberService.deleteAllMember();
|
||||
// memberService.list();
|
||||
/* 회원 정보 마지막 변경시간 저장 */
|
||||
member_last_modified_time = memberService.getLastModifiedTime(tableSchema);
|
||||
member_last_modified_time = memberService.getMemberLastModifiedTime(tableSchema);
|
||||
config_last_modified_time = memberService.getConfigLastModifiedTime(tableSchema);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package com.munjaon.server.server.config;
|
||||
|
||||
public final class ServerConfig {
|
||||
/* 서버 타임아웃 체크 시간 */
|
||||
public static final int CYCLE_SOCKET_TIMEOUT = 3000;
|
||||
/* 서버 연결후 로그인 만료 시간 */
|
||||
public static final int LIMIT_BIND_TIMEOUT = 5000;
|
||||
/* Session Check 만료 시간 */
|
||||
public static final int LIMIT_LINK_CHECK_TIMEOUT = 35000;
|
||||
|
||||
/* 서버 프로퍼티 reload interval 시간 */
|
||||
public static final Long INTERVAL_PROPERTY_RELOAD_TIME = 3000L;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.munjaon.server.server.dto;
|
||||
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@ToString
|
||||
public class ConnectUserDto {
|
||||
/* 로그인여부 */
|
||||
private boolean isLogin;
|
||||
/* 마지막 통신 시간 */
|
||||
private Long lastTrafficTime;
|
||||
/* 서비스 유형 */
|
||||
private String serviceType;
|
||||
/* 사용자 ID */
|
||||
private String userId;
|
||||
/* 사용자 접속 IP */
|
||||
private String remoteIP;
|
||||
/* 요금제(선불 : P / 후불 : A) */
|
||||
private final String feeType = "A";
|
||||
|
||||
public int isAlive() {
|
||||
if (isLogin) {
|
||||
if (System.currentTimeMillis() - lastTrafficTime > ServerConfig.LIMIT_LINK_CHECK_TIMEOUT) {
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
if (System.currentTimeMillis() - lastTrafficTime > ServerConfig.LIMIT_BIND_TIMEOUT) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void updateLastTrafficTime() {
|
||||
this.lastTrafficTime = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.munjaon.server.server.sample;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class ExecutorServiceTest3 {
|
||||
public static void main(String args[]) {
|
||||
final int maxCore = Runtime.getRuntime().availableProcessors();
|
||||
System.out.println("maxCore : " + maxCore);
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(maxCore);
|
||||
final List<Future<String>> futures = new ArrayList<>();
|
||||
|
||||
for (int i = 1; i < 5; i++) {
|
||||
final int index = i;
|
||||
futures.add(executor.submit(() -> {
|
||||
System.out.println("finished job" + index);
|
||||
return "job" + index + " " + Thread.currentThread().getName();
|
||||
}));
|
||||
}
|
||||
|
||||
for (Future<String> future : futures) {
|
||||
String result = null;
|
||||
try {
|
||||
result = future.get();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
executor.shutdownNow();
|
||||
System.out.println("end");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.munjaon.server.server.sample;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class ExecutorServiceTest4 {
|
||||
public static void main(String args[]) {
|
||||
ParallelExcutorService service = new ParallelExcutorService();
|
||||
service.submit("job1");
|
||||
service.submit("job2");
|
||||
service.submit("job3");
|
||||
service.submit("job4");
|
||||
|
||||
for (int i = 0 ; i < 4; i++) {
|
||||
String result = service.take();
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
System.out.println("end");
|
||||
service.close();
|
||||
}
|
||||
|
||||
private static class ParallelExcutorService {
|
||||
private final int maxCore = Runtime.getRuntime().availableProcessors();
|
||||
private final ExecutorService executor = Executors.newFixedThreadPool(maxCore);
|
||||
private final BlockingQueue<String> queue = new ArrayBlockingQueue<>(10);
|
||||
|
||||
public ParallelExcutorService() {
|
||||
}
|
||||
|
||||
public void submit(String job) {
|
||||
executor.submit(() -> {
|
||||
String threadName = Thread.currentThread().getName();
|
||||
System.out.println("finished " + job);
|
||||
String result = job + ", " + threadName;
|
||||
try {
|
||||
queue.put(result);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String take() {
|
||||
try {
|
||||
return queue.take();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
List<Runnable> unfinishedTasks = executor.shutdownNow();
|
||||
if (!unfinishedTasks.isEmpty()) {
|
||||
System.out.println("Not all tasks finished before calling close: " + unfinishedTasks.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,208 +0,0 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public abstract class BaseService extends Thread {
|
||||
boolean bEndProcess = false;
|
||||
|
||||
public static SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
public static String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]";
|
||||
|
||||
public boolean ready;
|
||||
private boolean KILL_FLAG;
|
||||
private boolean STOP_FLAG;
|
||||
private boolean RUN_FLAG;
|
||||
private String LOG_FILE;
|
||||
public LogUtil logger;
|
||||
|
||||
public BaseService() {}
|
||||
|
||||
public BaseService(String ServiceID) {
|
||||
super(ServiceID);
|
||||
|
||||
LOG_FILE = getProp("LOG_FILE");
|
||||
}
|
||||
|
||||
protected void checkRun() {
|
||||
RUN_FLAG = "1".equals(getProp("RUN_FLAG")) ? true : false;
|
||||
}
|
||||
|
||||
protected boolean isRun() {
|
||||
return RUN_FLAG && !STOP_FLAG && !KILL_FLAG;
|
||||
}
|
||||
|
||||
protected void setLogFile(String sLogFile) {
|
||||
if( logger != null ) {
|
||||
logger.close();
|
||||
logger = null;
|
||||
}
|
||||
|
||||
logger = new LogUtil( sLogFile );
|
||||
}
|
||||
|
||||
protected void Init() throws Exception {
|
||||
LOG_FILE = getProp("LOG_FILE");
|
||||
|
||||
setLogFile( LOG_FILE );
|
||||
|
||||
SystemLog("Service Initializing...");
|
||||
|
||||
ready = true;
|
||||
}
|
||||
|
||||
public synchronized void Start() {
|
||||
super.start();
|
||||
}
|
||||
|
||||
protected synchronized void Stop() {
|
||||
STOP_FLAG = true;
|
||||
|
||||
SystemLog("Service Stoping...");
|
||||
}
|
||||
|
||||
protected synchronized void Kill() {
|
||||
if( !KILL_FLAG ) SystemLog("Service Killing...");
|
||||
|
||||
KILL_FLAG = true;
|
||||
}
|
||||
|
||||
protected void startService() throws Exception {
|
||||
Log("startService() called.");
|
||||
}
|
||||
|
||||
protected void stopService() throws Exception {
|
||||
Log("stopService() called.");
|
||||
}
|
||||
|
||||
protected synchronized void Reload() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!KILL_FLAG) {
|
||||
STOP_FLAG = false;
|
||||
|
||||
if (isRun()) {
|
||||
try {
|
||||
Init();
|
||||
|
||||
SystemLog("Service Starting.");
|
||||
|
||||
startService();
|
||||
} catch (SQLException e) {
|
||||
STOP_FLAG = true;
|
||||
SystemLog("SQLErrorCode = "+e.getErrorCode());
|
||||
SystemLog(e);
|
||||
} catch (Exception e) {
|
||||
STOP_FLAG = true;
|
||||
SystemLog(e);
|
||||
} finally {
|
||||
ready = false;
|
||||
SystemLog("Service Stoped.");
|
||||
if( logger != null ) { logger.close(); logger = null; }
|
||||
}
|
||||
}
|
||||
|
||||
if( !KILL_FLAG ) {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
stopService();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
SystemLog("Service Killed.");
|
||||
|
||||
ServiceRunner.SERVICES.remove(getName());
|
||||
bEndProcess = true;
|
||||
}
|
||||
|
||||
public void stopThread() {
|
||||
SystemLog("kill signal has been received.");
|
||||
SystemLog("remaining tasks are handled.");
|
||||
|
||||
bEndProcess = true;
|
||||
Kill();
|
||||
|
||||
int i=0;
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(1*1000);
|
||||
} catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(bEndProcess) {
|
||||
break;
|
||||
}
|
||||
|
||||
SystemLog("remaining tasks - processing " + (++i) + " secs.");
|
||||
}
|
||||
|
||||
this.interrupt();
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
SystemLog("Service was interrupted.");
|
||||
}
|
||||
|
||||
protected void SystemLog(Object obj) {
|
||||
Log(obj, true);
|
||||
}
|
||||
|
||||
protected void Log(Object obj) {
|
||||
Log(obj, false);
|
||||
}
|
||||
|
||||
protected void Log(Object obj, boolean bOut) {
|
||||
if( bOut ) {
|
||||
System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern(LOG_DATE_FORMAT)) + " {{"+ getName() +"}} "+obj);
|
||||
}
|
||||
|
||||
if( logger != null ) {
|
||||
logger.log(obj);
|
||||
}
|
||||
else {
|
||||
if( obj instanceof Throwable ) {
|
||||
LogUtil.log(LOG_FILE, obj);
|
||||
}
|
||||
else {
|
||||
LogUtil.log(LOG_FILE, "{{"+ getName() +"}} "+obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getProp(String name) {
|
||||
return getProp(getName(), name);
|
||||
}
|
||||
|
||||
public static String getProp(String svc, String name) {
|
||||
return PropertyLoader.getProp(svc, name);
|
||||
}
|
||||
}
|
||||
|
||||
class ShutdownService extends Thread {
|
||||
private BaseService service = null;
|
||||
|
||||
public ShutdownService(BaseService service) {
|
||||
super();
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
service.stopThread();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QueueServerService extends Service {
|
||||
private int SMS_QUEUE_SIZE = 0;
|
||||
private int LMS_QUEUE_SIZE = 0;
|
||||
private int MMS_QUEUE_SIZE = 0;
|
||||
private int KAT_QUEUE_SIZE = 0;
|
||||
private int KFT_QUEUE_SIZE = 0;
|
||||
|
||||
private Map<String, String> queueConfigMap = new HashMap<String, String>();
|
||||
|
||||
|
||||
@Override
|
||||
public void checkReady() {
|
||||
this.IS_READY_YN = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initResources() {
|
||||
SMS_QUEUE_SIZE =
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseResources() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject monitorService() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
117
src/main/java/com/munjaon/server/server/service/Server.java
Normal file
117
src/main/java/com/munjaon/server/server/service/Server.java
Normal file
@ -0,0 +1,117 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.dto.ConnectUserDto;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class Server {
|
||||
private InetSocketAddress listenAddress;
|
||||
private Selector selector;
|
||||
/* 마지막 통신 시간 */
|
||||
private Long lastTrafficCheckTime = System.currentTimeMillis();
|
||||
|
||||
private Server(InetSocketAddress listenAddress) {
|
||||
this.listenAddress = listenAddress;
|
||||
}
|
||||
|
||||
protected Server(String address, int port) throws IOException {
|
||||
this(new InetSocketAddress(address, port));
|
||||
selector = Selector.open();
|
||||
/* 채널 생성 */
|
||||
ServerSocketChannel serverChannel = ServerSocketChannel.open();
|
||||
/* non-Blocking 설정 */
|
||||
serverChannel.configureBlocking(false);
|
||||
/* 서버 ip, port 설정 */
|
||||
serverChannel.socket().bind(listenAddress);
|
||||
/* 채널에 accept 대기 설정 */
|
||||
serverChannel.register(selector, SelectionKey.OP_ACCEPT);
|
||||
}
|
||||
|
||||
protected Iterator<SelectionKey> selectInterest() throws IOException {
|
||||
if (selector.select(1000) == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return selector.selectedKeys().iterator();
|
||||
}
|
||||
|
||||
protected void execInterest(Iterator<SelectionKey> keys) throws IOException {
|
||||
while (keys != null && keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
/* 키 셋에서 제거. */
|
||||
keys.remove();
|
||||
if (!key.isValid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key.isAcceptable()) { // 접속일 경우..
|
||||
this.accept(selector, key);
|
||||
} else if (key.isReadable()) { // 수신일 경우..
|
||||
this.receive(selector, key);
|
||||
} else if (key.isWritable()) { // 발신일 경우..
|
||||
this.send(selector, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept(Selector selector, SelectionKey key) throws IOException {
|
||||
/* 키 채널을 가져온다. */
|
||||
ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel();
|
||||
/* accept을 해서 Socket 채널을 가져온다. */
|
||||
SocketChannel channel = serverChannel.accept();
|
||||
channel.configureBlocking(false);
|
||||
/* 소켓 취득 */
|
||||
Socket socket = channel.socket();
|
||||
SocketAddress remoteAddr = socket.getRemoteSocketAddress();
|
||||
System.out.println("Connected to: " + remoteAddr);
|
||||
// Socket 채널을 channel에 수신 등록한다
|
||||
channel.register(selector, SelectionKey.OP_READ, ConnectUserDto.builder().lastTrafficTime(System.currentTimeMillis()).remoteIP(remoteAddr.toString()).build());
|
||||
}
|
||||
|
||||
protected void checkInterest() throws IOException {
|
||||
if (lastTrafficCheckTime - System.currentTimeMillis() < ServerConfig.CYCLE_SOCKET_TIMEOUT) {
|
||||
return;
|
||||
}
|
||||
Iterator<SelectionKey> keys = selector.keys().iterator();
|
||||
while (keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
if (key.interestOps() == SelectionKey.OP_READ) {
|
||||
ConnectUserDto userDto = (ConnectUserDto) key.attachment();
|
||||
|
||||
if (userDto != null) {
|
||||
if (userDto.isAlive() != 0) {
|
||||
System.out.println("userDto is disconnet");
|
||||
// 키 채널을 가져온다.
|
||||
SocketChannel channel = (SocketChannel) key.channel();
|
||||
// 소켓 취득
|
||||
Socket socket = channel.socket();
|
||||
// 소켓 채널 닫기
|
||||
channel.close();
|
||||
// 소켓 닫기
|
||||
socket.close();
|
||||
// 키 닫기
|
||||
key.attach(null);
|
||||
key.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lastTrafficCheckTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
protected void releaseServer() throws IOException {
|
||||
selector.close();
|
||||
}
|
||||
|
||||
protected abstract void receive(Selector selector, SelectionKey key) throws IOException;
|
||||
protected abstract void send(Selector selector, SelectionKey key) throws IOException;
|
||||
}
|
||||
139
src/main/java/com/munjaon/server/server/service/Service.java
Normal file
139
src/main/java/com/munjaon/server/server/service/Service.java
Normal file
@ -0,0 +1,139 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public abstract class Service extends Thread {
|
||||
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]";
|
||||
|
||||
private String LOG_FILE;
|
||||
protected LogUtil logger;
|
||||
private Long LAST_PROPERTY_LOAD_TIME = 0L;
|
||||
|
||||
protected boolean IS_SERVER_RUN; // 서버가 구동중인지 여부
|
||||
protected boolean IS_READY_YN; // 서비스 구동준비가 완료되었는지 체크
|
||||
protected boolean IS_RUN_YN;
|
||||
protected boolean IS_STOP_YN;
|
||||
|
||||
public Service() {}
|
||||
public Service(String serviceName) {
|
||||
super(serviceName);
|
||||
LOG_FILE = getProp("LOG_FILE");
|
||||
}
|
||||
|
||||
protected String getProp(String name) {
|
||||
return getProp(getName(), name);
|
||||
}
|
||||
|
||||
public static String getProp(String svc, String name) {
|
||||
return PropertyLoader.getProp(svc, name);
|
||||
}
|
||||
|
||||
protected void checkRun() {
|
||||
this.IS_RUN_YN = getProp("RUN_FLAG") != null && "Y".equals(getProp("RUN_FLAG"));
|
||||
}
|
||||
|
||||
protected void checkServerRun() {
|
||||
this.IS_SERVER_RUN = getProp("server", "run") != null && "Y".equals(getProp("server", "run"));
|
||||
}
|
||||
|
||||
public void reloadCheckRun() {
|
||||
if ((System.currentTimeMillis() - this.LAST_PROPERTY_LOAD_TIME) > ServerConfig.INTERVAL_PROPERTY_RELOAD_TIME) {
|
||||
checkRun();
|
||||
checkServerRun();
|
||||
this.LAST_PROPERTY_LOAD_TIME = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRun() {
|
||||
return IS_SERVER_RUN && IS_RUN_YN && !IS_STOP_YN;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return IS_READY_YN;
|
||||
}
|
||||
|
||||
protected void setLogFile(String sLogFile) {
|
||||
if ( logger != null ) {
|
||||
logger.close();
|
||||
logger = null;
|
||||
}
|
||||
|
||||
logger = new LogUtil( sLogFile );
|
||||
}
|
||||
|
||||
protected void saveSystemLog(Object obj) {
|
||||
saveLog(obj, true);
|
||||
}
|
||||
|
||||
protected void saveLog(Object obj) {
|
||||
saveLog(obj, false);
|
||||
}
|
||||
|
||||
protected void saveLog(Object obj, boolean isConsoleOutput) {
|
||||
if(isConsoleOutput) {
|
||||
System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern(LOG_DATE_FORMAT)) + " {{"+ getName() +"}} "+obj);
|
||||
}
|
||||
if (logger != null) {
|
||||
logger.log(obj);
|
||||
} else {
|
||||
if (obj instanceof Throwable) {
|
||||
LogUtil.log(LOG_FILE, obj);
|
||||
} else {
|
||||
LogUtil.log(LOG_FILE, "{{"+ getName() +"}} "+obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initLogFile() {
|
||||
LOG_FILE = getProp("LOG_FILE");
|
||||
setLogFile( LOG_FILE );
|
||||
saveSystemLog("Service Log Initializing ... ...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
/* 1. 서비스간의 dependency에 따른 체크 */
|
||||
checkReady();
|
||||
if (isRun() && isReady()) {
|
||||
/* 2. 로그 초기화 */
|
||||
initLogFile();
|
||||
/* 3. 서비스 초기화 */
|
||||
initResources();
|
||||
/* 4. 서비스 시작 */
|
||||
doService();
|
||||
/* 5. 서비스 자원 해제 */
|
||||
releaseResources();
|
||||
saveSystemLog("Service Stopped.");
|
||||
} else {
|
||||
saveSystemLog("Service is Not Running.");
|
||||
}
|
||||
/* 6. 3초간 sleep */
|
||||
Thread.sleep(3000);
|
||||
} catch (Exception e) {
|
||||
saveSystemLog(e);
|
||||
} finally {
|
||||
if(logger != null) { logger.close(); logger = null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 서비스간의 dependency에 따른 체크 */
|
||||
public abstract void checkReady();
|
||||
/* 추가적인 프로퍼티, 서비스 자원 초기화 */
|
||||
public abstract void initResources();
|
||||
/* 서비스 자원 해제 */
|
||||
public abstract void releaseResources();
|
||||
/* 서비스 */
|
||||
public abstract void doService();
|
||||
/* 모니터링을 위한 메소드 */
|
||||
public abstract JSONObject monitorService();
|
||||
}
|
||||
@ -1,124 +0,0 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JDS
|
||||
*/
|
||||
public class ServiceRunner extends Thread {
|
||||
|
||||
public static String CLASS_DIR = PropertyLoader.get("SERVICE.CLASS_DIR");
|
||||
|
||||
public static Hashtable SERVICES = new Hashtable();
|
||||
|
||||
public void run() {
|
||||
while(true) {
|
||||
check();
|
||||
|
||||
try {
|
||||
int iCheckCycle = Integer.parseInt(PropertyLoader.get("SERVICE.CHECK_CYCLE","3000"));
|
||||
Thread.sleep( iCheckCycle );
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void check() {
|
||||
try {
|
||||
String[] svcs = PropertyLoader.get("SERVICE.LISTS").split(",");
|
||||
String svc_name;
|
||||
|
||||
Hashtable map = new Hashtable();
|
||||
|
||||
for( int i=0; i<svcs.length; i++ ) {
|
||||
svc_name = svcs[i].trim();
|
||||
|
||||
if( svc_name.length() == 0 || svc_name.startsWith("#") ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
map.put( svc_name, svc_name );
|
||||
}
|
||||
|
||||
Enumeration enums = SERVICES.elements();
|
||||
|
||||
while( enums.hasMoreElements() ) {
|
||||
BaseService svc = (BaseService) enums.nextElement();
|
||||
svc_name = svc.getName();
|
||||
|
||||
if( map.containsKey(svc_name) ) {
|
||||
svc.checkRun();
|
||||
if( svc.isRun() && svc.ready ) {
|
||||
svc.Reload();
|
||||
}
|
||||
|
||||
map.remove(svc_name);
|
||||
}
|
||||
else {
|
||||
svc.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
enums = map.elements();
|
||||
|
||||
ShutdownService shutdownService = null;
|
||||
while ( enums.hasMoreElements() ) {
|
||||
svc_name = (String) enums.nextElement();
|
||||
|
||||
if( SERVICES.containsKey(svc_name) ) {
|
||||
System.err.println("Already Started Service: "+ svc_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
String className = PropertyLoader.get(svc_name + ".CLASS");
|
||||
|
||||
Class cls = LoadClass( CLASS_DIR, className );
|
||||
|
||||
BaseService svc = (BaseService) cls.newInstance();
|
||||
svc.setName(svc_name);
|
||||
svc.checkRun();
|
||||
if( svc.isRun() && svc.ready ) svc.Reload();
|
||||
|
||||
SERVICES.put(svc_name, svc);
|
||||
|
||||
shutdownService = new ShutdownService(svc);
|
||||
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||
svc.Start();
|
||||
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Class LoadClass(String className) throws Exception {
|
||||
Class cls = Class.forName(className.trim());
|
||||
|
||||
return cls;
|
||||
}
|
||||
|
||||
public static Class LoadClass(String path, String className) throws Exception {
|
||||
/**
|
||||
URL url = new File(path).toURL();
|
||||
URL[] urls = new URL[]{url};
|
||||
ClassLoader loader = new URLClassLoader(urls);
|
||||
*/
|
||||
URI uri = new File(path).toURI();
|
||||
URL[] urls = new URL[]{uri.toURL()};
|
||||
ClassLoader loader = new URLClassLoader(urls);
|
||||
|
||||
return loader.loadClass(className);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ServiceRunner().start();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class SocketServerService extends Service {
|
||||
@Override
|
||||
public void checkReady() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initResources() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseResources() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject monitorService() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,31 +1,124 @@
|
||||
package com.munjaon.server.util;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.jdom2.Document;
|
||||
import org.jdom2.Element;
|
||||
import org.jdom2.JDOMException;
|
||||
import org.jdom2.input.SAXBuilder;
|
||||
import org.jdom2.output.Format;
|
||||
import org.jdom2.output.XMLOutputter;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
public class XmlUtil {
|
||||
private static Document getDOMParsedDocument(final String fileName) {
|
||||
// private static Document getDOMParsedDocument(final String fileName) {
|
||||
// Document document = null;
|
||||
// try {
|
||||
//
|
||||
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
// //If want to make namespace aware.
|
||||
// //factory.setNamespaceAware(true);
|
||||
// DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
// document = documentBuilder.parse(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"));
|
||||
//
|
||||
// NodeList nodeList = document.getDocumentElement().getChildNodes();
|
||||
// for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
// Node node = nodeList.item(i);
|
||||
// if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||
// Element elem = (Element) node;
|
||||
// System.out.println("createDate : " + elem.getAttribute("createDate"));
|
||||
// System.out.println("getTagName : " + elem.getTagName());
|
||||
// System.out.println("getNodeName : " + elem.getNodeName());
|
||||
// System.out.println("getTextContent : " + elem.getTextContent());
|
||||
//// String createDate = elem.getElementsByTagName("createDate").item(0).getChildNodes().item(0).getNodeValue();
|
||||
//// System.out.println("createDate : " + createDate);
|
||||
//// String PopCounter = elem.getElementsByTagName("PopCounter").item(0).getChildNodes().item(0).getNodeValue();
|
||||
//// System.out.println("PopCounter : " + PopCounter);
|
||||
//// Double salary = Double.parseDouble(elem.getElementsByTagName("salary").item(0).getChildNodes().item(0).getNodeValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return document;
|
||||
// }
|
||||
|
||||
private static Document getSaxParsedDocument(final String fileName) {
|
||||
Document document = null;
|
||||
|
||||
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
+ " <catalog>\r\n"
|
||||
+ " <book id=\"bk101\">"
|
||||
+ " <author>Gambardella, Matthew</author> "
|
||||
+ "<title>XML Developer's Guide</title>"
|
||||
+ " <genre>Computer</genre>"
|
||||
+ " <price>44.95</price> "
|
||||
+ "<publish_date>2000-10-01</publish_date> "
|
||||
+ "<description>An in-depth look at creating applications with XML.</description> "
|
||||
+ "</book>"
|
||||
+ " <book id=\"bk102\">"
|
||||
+ " <author>Ralls, Kim</author>"
|
||||
+ " <title>Midnight Rain</title>"
|
||||
+ " <genre>Fantasy</genre>"
|
||||
+ " <price>5.95</price>"
|
||||
+ " <publish_date>2000-12-16</publish_date>"
|
||||
+ " <description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description>"
|
||||
+ " </book> \r\n"
|
||||
+ "</catalog>\r\n";
|
||||
try {
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
//If want to make namespace aware.
|
||||
//factory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
document = documentBuilder.parse(new File("employee.xml"));
|
||||
SAXBuilder sax = new SAXBuilder();
|
||||
// String that contains XML
|
||||
Document doc = (Document) sax.build(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"));
|
||||
// org.jdom2.Document doc = sax.build(new StringReader(xml));
|
||||
|
||||
Element rootNode = doc.getRootElement();
|
||||
List<Element> bookElements = rootNode.getChildren();
|
||||
System.out.println("bookElements: " + bookElements);
|
||||
for(Element bookElement : bookElements){
|
||||
String name = bookElement.getName();
|
||||
String value = bookElement.getValue();
|
||||
System.out.println(name + " : " + value);
|
||||
}
|
||||
catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
} catch (IOException | JDOMException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return document;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
|
||||
private static void writeSimpleXml() throws JDOMException, IOException {
|
||||
|
||||
String xml = "<root><child id=\"100\">mkyong</child></root>";
|
||||
SAXBuilder sb = new SAXBuilder();
|
||||
Document doc = sb.build(new StringReader(xml));
|
||||
|
||||
|
||||
Document docFile = new Document();
|
||||
|
||||
Element rootElement = new Element("ReadQueue");
|
||||
rootElement.addContent(new Element("createDate").setText("20240527"));
|
||||
rootElement.addContent(new Element("PopCounter").setText(Integer.toString(0)));
|
||||
|
||||
docFile.setRootElement(rootElement);
|
||||
|
||||
// default in compact mode
|
||||
// XMLOutputter xmlOutputter = new XMLOutputter();
|
||||
|
||||
// pretty print format
|
||||
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
|
||||
|
||||
// output to console
|
||||
FileOutputStream fileOutputStream = new FileOutputStream("C:\\Docs\\JDS\\ITN\\file.xml");
|
||||
xmlOutputter.output(docFile, fileOutputStream);
|
||||
|
||||
}
|
||||
public static void main(String[] args) throws IOException, JDOMException {
|
||||
// XmlUtil.getDOMParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml");
|
||||
XmlUtil.getSaxParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml");
|
||||
XmlUtil.writeSimpleXml();
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,5 +12,6 @@ server:
|
||||
|
||||
# ### 에이전트 설정 관련 ####################################################################################
|
||||
agent:
|
||||
root-path: C:/apps/agent_server
|
||||
server-property-file: C:/apps/agent_server/config/server.properties
|
||||
db-name: mjon_agent_back
|
||||
@ -12,5 +12,6 @@ server:
|
||||
|
||||
# ### 에이전트 설정 관련 ####################################################################################
|
||||
agent:
|
||||
root-path: C:/apps/agent_server
|
||||
server-property-file: C:/apps/agent_server/config/server.properties
|
||||
db-name: mjon_agent_back
|
||||
@ -12,5 +12,6 @@ server:
|
||||
|
||||
# ### 에이전트 설정 관련 ####################################################################################
|
||||
agent:
|
||||
root-path: C:/apps/agent_server
|
||||
server-property-file: C:/apps/agent_server/config/server.properties
|
||||
db-name: mjon_agent_back
|
||||
|
||||
@ -1,19 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.munjaon.server.cache.mapper.MemberMapper">
|
||||
<select id="getLastModifiedTime" resultType="String">
|
||||
<select id="getMemberLastModifiedTime" resultType="String">
|
||||
/* MemberMapper.getLastModifiedTime */
|
||||
SELECT CASE WHEN UPDATE_TIME IS NULL THEN '0' ELSE DATE_FORMAT(UPDATE_TIME, '%Y%m%d%H%i%s') END AS last_modify_time
|
||||
FROM information_schema.tables
|
||||
WHERE TABLE_SCHEMA = #{tableSchema} AND TABLE_NAME = 'lettngnrlmber'
|
||||
</select>
|
||||
<select id="getConfigLastModifiedTime" resultType="String">
|
||||
/* MemberMapper.getLastModifiedTime */
|
||||
SELECT CASE WHEN UPDATE_TIME IS NULL THEN '0' ELSE DATE_FORMAT(UPDATE_TIME, '%Y%m%d%H%i%s') END AS last_modify_time
|
||||
FROM information_schema.tables
|
||||
WHERE TABLE_SCHEMA = #{tableSchema} AND TABLE_NAME = 'mj_agent_mber_config'
|
||||
</select>
|
||||
<select id="list" resultType="MemberDto">
|
||||
/* MemberMapper.list */
|
||||
SELECT
|
||||
MBER.*
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.SMS_USE_YN IS NULL OR CONF.SMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS SMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.LMS_USE_YN IS NULL OR CONF.LMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS LMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.MMS_USE_YN IS NULL OR CONF.MMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS MMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.KAKAO_AT_USE_YN IS NULL OR CONF.KAKAO_AT_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS KAKAO_AT_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.KAKAO_FT_USE_YN IS NULL OR CONF.KAKAO_FT_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS KAKAO_FT_USE_YN
|
||||
, CASE WHEN CONF.SMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.SMS_LIMIT_COUNT END AS SMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.LMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.LMS_LIMIT_COUNT END AS LMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.MMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.MMS_LIMIT_COUNT END AS MMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.KAKAO_AT_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.KAKAO_AT_LIMIT_COUNT END AS KAKAO_AT_LIMIT_COUNT
|
||||
, CASE WHEN CONF.KAKAO_FT_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.KAKAO_FT_LIMIT_COUNT END AS KAKAO_FT_LIMIT_COUNT
|
||||
, CASE WHEN CONF.IP_LIMIT_YN IS NULL THEN 'Y' ELSE CONF.IP_LIMIT_YN END AS IP_LIMIT_YN
|
||||
, CASE WHEN CONF.ALLOW_IP_BASIC IS NULL THEN '0.0.0.0' ELSE CONF.ALLOW_IP_BASIC END AS ALLOW_IP_BASIC
|
||||
, CASE WHEN CONF.ALLOW_IP_EXTEND IS NULL THEN '0.0.0.0' ELSE CONF.ALLOW_IP_EXTEND END AS ALLOW_IP_EXTEND
|
||||
, CONF.SMS_AGENT_CODE
|
||||
, CONF.LMS_AGENT_CODE
|
||||
, CONF.MMS_AGENT_CODE
|
||||
, CONF.KAKAO_AT_AGENT_CODE
|
||||
, CONF.KAKAO_FT_AGENT_CODE
|
||||
FROM (
|
||||
SELECT
|
||||
MBER_ID
|
||||
, ESNTL_ID
|
||||
, ACCESS_KEY
|
||||
, MBER_STTUS
|
||||
, DEPT
|
||||
, SHORT_PRICE
|
||||
, LONG_PRICE
|
||||
, PICTURE_PRICE
|
||||
@ -23,17 +49,38 @@
|
||||
, KAKAO_FT_PRICE
|
||||
, KAKAO_FT_IMG_PRICE
|
||||
, KAKAO_FT_WIDE_IMG_PRICE
|
||||
, FAX_PRICE
|
||||
, USER_MONEY
|
||||
FROM lettngnrlmber
|
||||
) MBER
|
||||
LEFT JOIN mj_agent_mber_config CONF
|
||||
ON MBER.MBER_ID = CONF.MBER_ID
|
||||
</select>
|
||||
<select id="get" resultType="MemberDto">
|
||||
/* MemberMapper.get */
|
||||
SELECT
|
||||
MBER.*
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.SMS_USE_YN IS NULL OR CONF.SMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS SMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.LMS_USE_YN IS NULL OR CONF.LMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS LMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.MMS_USE_YN IS NULL OR CONF.MMS_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS MMS_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.KAKAO_AT_USE_YN IS NULL OR CONF.KAKAO_AT_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS KAKAO_AT_USE_YN
|
||||
, CASE WHEN MBER.MBER_STTUS = 'Y' THEN (CASE WHEN CONF.KAKAO_FT_USE_YN IS NULL OR CONF.KAKAO_FT_USE_YN = 'N' THEN 'N' ELSE 'Y' END) ELSE 'N' END AS KAKAO_FT_USE_YN
|
||||
, CASE WHEN CONF.SMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.SMS_LIMIT_COUNT END AS SMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.LMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.LMS_LIMIT_COUNT END AS LMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.MMS_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.MMS_LIMIT_COUNT END AS MMS_LIMIT_COUNT
|
||||
, CASE WHEN CONF.KAKAO_AT_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.KAKAO_AT_LIMIT_COUNT END AS KAKAO_AT_LIMIT_COUNT
|
||||
, CASE WHEN CONF.KAKAO_FT_LIMIT_COUNT IS NULL THEN 0 ELSE CONF.KAKAO_FT_LIMIT_COUNT END AS KAKAO_FT_LIMIT_COUNT
|
||||
, CASE WHEN CONF.IP_LIMIT_YN IS NULL THEN 'Y' ELSE CONF.IP_LIMIT_YN END AS IP_LIMIT_YN
|
||||
, CASE WHEN CONF.ALLOW_IP_BASIC IS NULL THEN '0.0.0.0' ELSE CONF.ALLOW_IP_BASIC END AS ALLOW_IP_BASIC
|
||||
, CASE WHEN CONF.ALLOW_IP_EXTEND IS NULL THEN '0.0.0.0' ELSE CONF.ALLOW_IP_EXTEND END AS ALLOW_IP_EXTEND
|
||||
, CONF.SMS_AGENT_CODE
|
||||
, CONF.LMS_AGENT_CODE
|
||||
, CONF.MMS_AGENT_CODE
|
||||
, CONF.KAKAO_AT_AGENT_CODE
|
||||
, CONF.KAKAO_FT_AGENT_CODE
|
||||
FROM (
|
||||
SELECT
|
||||
MBER_ID
|
||||
, ESNTL_ID
|
||||
, ACCESS_KEY
|
||||
, MBER_STTUS
|
||||
, DEPT
|
||||
, SHORT_PRICE
|
||||
, LONG_PRICE
|
||||
, PICTURE_PRICE
|
||||
@ -43,10 +90,11 @@
|
||||
, KAKAO_FT_PRICE
|
||||
, KAKAO_FT_IMG_PRICE
|
||||
, KAKAO_FT_WIDE_IMG_PRICE
|
||||
, FAX_PRICE
|
||||
, USER_MONEY
|
||||
FROM lettngnrlmber
|
||||
WHERE MBER_ID = #{mberId}
|
||||
) MBER
|
||||
LEFT JOIN (SELECT * FROM mj_agent_mber_config WHERE MBER_ID = #{mberId}) CONF
|
||||
ON MBER.MBER_ID = CONF.MBER_ID
|
||||
</select>
|
||||
<update id="updateStts" parameterType="MemberDto">
|
||||
UPDATE lettngnrlmber SET MBER_STTUS = #{mberSttus} WHERE MBER_ID = #{mberId}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user