인코딩캐릭터셋 변경, 리포트 프로세스 분리
This commit is contained in:
parent
893417a994
commit
0e3b0fd1c7
@ -27,7 +27,7 @@ public class DataSourceConfig {
|
||||
|
||||
@Primary
|
||||
@Bean(name = "datasource")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.hikari")
|
||||
@ConfigurationProperties(prefix = "spring.datasource.server")
|
||||
public DataSource dataSource() {
|
||||
return DataSourceBuilder.create().type(HikariDataSource.class).build();
|
||||
}
|
||||
|
||||
@ -277,4 +277,17 @@ public class RunnerConfiguration {
|
||||
}
|
||||
return args -> System.out.println("Runner Bean ReporterQueue #4");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order(5)
|
||||
public CommandLineRunner getRunnerBeanForMonitor() {
|
||||
try {
|
||||
String serviceName = "HEALTH";
|
||||
HealthCheckServer healthCheckServer = new HealthCheckServer(serviceName);
|
||||
healthCheckServer.start();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return args -> System.out.println("Runner Bean Monitor #5");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package com.munjaon.server.queue.config;
|
||||
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public final class QueueConstants {
|
||||
/** Queue File Header Length - [Create Date:10 Byte, Push Count:10 Byte] */
|
||||
public static final int QUEUE_HEADER_LENGTH = 20;
|
||||
@ -78,7 +82,7 @@ public final class QueueConstants {
|
||||
// 큐에 저장하기전에 바이트를 채울 문자
|
||||
public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
|
||||
|
||||
public static String getString(byte[] srcArray) {
|
||||
public static String getString(byte[] srcArray) throws UnsupportedEncodingException {
|
||||
if (srcArray == null) {
|
||||
return null;
|
||||
}
|
||||
@ -101,6 +105,6 @@ public final class QueueConstants {
|
||||
}
|
||||
}
|
||||
|
||||
return destArray == null ? null : new String(destArray);
|
||||
return destArray == null ? null : new String(destArray, Packet.AGENT_CHARACTER_SET);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class KakaoAlarmReadQueue extends ReadQueue {
|
||||
@ -21,7 +22,7 @@ public class KakaoAlarmReadQueue extends ReadQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) {
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
MessageUtil.getBytesForKakaoMessage(this.dataBuffer, messageDto);
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class KakaoAlarmWriteQueue extends WriteQueue {
|
||||
@ -17,7 +18,7 @@ public class KakaoAlarmWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), KakaoBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class KakaoFriendReadQueue extends ReadQueue {
|
||||
@ -21,7 +22,7 @@ public class KakaoFriendReadQueue extends ReadQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) {
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
MessageUtil.getBytesForKakaoMessage(this.dataBuffer, messageDto);
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class KakaoFriendWriteQueue extends WriteQueue {
|
||||
@ -17,7 +18,7 @@ public class KakaoFriendWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), KakaoBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class LmsReadQueue extends ReadQueue {
|
||||
@ -21,7 +22,7 @@ public class LmsReadQueue extends ReadQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) {
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
MessageUtil.getBytesForMediaMessage(this.dataBuffer, messageDto);
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class LmsWriteQueue extends WriteQueue {
|
||||
@ -17,7 +18,7 @@ public class LmsWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class MmsReadQueue extends ReadQueue {
|
||||
@ -21,7 +22,7 @@ public class MmsReadQueue extends ReadQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) {
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
MessageUtil.getBytesForMediaMessage(this.dataBuffer, messageDto);
|
||||
MessageUtil.getBytesForMmsMessage(this.dataBuffer, messageDto);
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class MmsWriteQueue extends WriteQueue {
|
||||
@ -17,7 +18,7 @@ public class MmsWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 13. 제목 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserSubject(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserSubject(), MediaBodyConfig.SUBJECT_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_MEDIA_SUBJECT.getCode();
|
||||
|
||||
@ -14,10 +14,7 @@ import org.jdom2.input.SAXBuilder;
|
||||
import org.jdom2.output.Format;
|
||||
import org.jdom2.output.XMLOutputter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.time.LocalDateTime;
|
||||
@ -206,6 +203,6 @@ public abstract class ReadQueue {
|
||||
}
|
||||
|
||||
abstract void popBuffer() throws Exception;
|
||||
abstract void getBytesForExtendMessage(BasicMessageDto messageDto);
|
||||
abstract void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException;
|
||||
abstract void initDataBuffer();
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.QueueConstants;
|
||||
import com.munjaon.server.queue.config.ReportConfig;
|
||||
import com.munjaon.server.server.dto.ReportDto;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.util.FileUtil;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
import lombok.Getter;
|
||||
@ -151,11 +152,11 @@ public class ReportQueue {
|
||||
private void writeHeader() throws Exception {
|
||||
initHeadBuffer();
|
||||
this.channel.position(ReportConfig.USER_ID_POSITION);
|
||||
this.headBuffer.put(this.userId.getBytes());
|
||||
this.headBuffer.put(this.userId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.headBuffer.position(ReportConfig.WRITE_COUNT_POSITION);
|
||||
this.headBuffer.put(Integer.toString(this.writeCounter).getBytes());
|
||||
this.headBuffer.put(Integer.toString(this.writeCounter).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.headBuffer.position(ReportConfig.READ_COUNT_POSITION);
|
||||
this.headBuffer.put(Integer.toString(this.readCounter).getBytes());
|
||||
this.headBuffer.put(Integer.toString(this.readCounter).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.headBuffer.flip();
|
||||
this.channel.write(this.headBuffer);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.munjaon.server.queue.pool;
|
||||
|
||||
import com.munjaon.server.queue.config.QueueConstants;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.server.service.PropertyLoader;
|
||||
import com.munjaon.server.util.FileUtil;
|
||||
import lombok.Getter;
|
||||
@ -94,7 +95,7 @@ public class SerialQueue {
|
||||
try {
|
||||
initDataBuffer();
|
||||
this.channel.position(0);
|
||||
this.dataBuffer.put(String.valueOf(serialNo).getBytes());
|
||||
this.dataBuffer.put(String.valueOf(serialNo).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.dataBuffer.flip();
|
||||
this.channel.write(this.dataBuffer);
|
||||
} catch(Exception e) {
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SmsReadQueue extends ReadQueue {
|
||||
@ -21,7 +22,7 @@ public class SmsReadQueue extends ReadQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) {
|
||||
void getBytesForExtendMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
MessageUtil.getBytesForSmsMessage(this.dataBuffer, messageDto);
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class SmsWriteQueue extends WriteQueue {
|
||||
@ -17,7 +18,7 @@ public class SmsWriteQueue extends WriteQueue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) {
|
||||
public int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 13. 메시지 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserMessage(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserMessage(), SmsBodyConfig.SMS_MSG_BYTE_LENGTH, false)) {
|
||||
return ServiceCode.MSG_ERROR_SMS_MESSAGE.getCode();
|
||||
|
||||
@ -6,6 +6,7 @@ import com.munjaon.server.queue.config.QueueConstants;
|
||||
import com.munjaon.server.queue.config.QueueHeaderConfig;
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.queue.dto.QueueInfo;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.util.FileUtil;
|
||||
import com.munjaon.server.util.JobFileFactory;
|
||||
import com.munjaon.server.util.MessageUtil;
|
||||
@ -14,6 +15,7 @@ import lombok.Getter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.time.LocalDateTime;
|
||||
@ -108,9 +110,9 @@ public abstract class WriteQueue {
|
||||
try {
|
||||
initHeaderBuffer();
|
||||
this.channel.position(QueueHeaderConfig.CREATE_DATE_POSITION);
|
||||
this.headerBuffer.put(this.createDate.getBytes());
|
||||
this.headerBuffer.put(this.createDate.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.headerBuffer.position(QueueHeaderConfig.PUSH_COUNT_POSITION);
|
||||
this.headerBuffer.put(Integer.toString(this.pushCounter).getBytes());
|
||||
this.headerBuffer.put(Integer.toString(this.pushCounter).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
this.headerBuffer.flip();
|
||||
this.channel.write(this.headerBuffer);
|
||||
} catch(Exception e) {
|
||||
@ -175,7 +177,7 @@ public abstract class WriteQueue {
|
||||
return this.queueInfo.getQueueName();
|
||||
}
|
||||
|
||||
protected int isValidateMessage(BasicMessageDto messageDto) {
|
||||
protected int isValidateMessage(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
int result = isValidateMessageForCommon(messageDto);
|
||||
if (result != ServiceCode.OK.getCode()) {
|
||||
return result;
|
||||
@ -184,7 +186,7 @@ public abstract class WriteQueue {
|
||||
return isValidateMessageForExtend(messageDto);
|
||||
}
|
||||
|
||||
protected int isValidateMessageForCommon(BasicMessageDto messageDto) {
|
||||
protected int isValidateMessageForCommon(BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 1. 사용자 아이디 */
|
||||
if (MessageUtil.isEmptyForMessage(messageDto.getUserId(), true) || MessageUtil.isOverByteForMessage(messageDto.getUserId(), BodyCommonConfig.USERID_BYTE_LENGTH, true)) {
|
||||
return ServiceCode.MSG_ERROR_USERID.getCode();
|
||||
@ -237,7 +239,7 @@ public abstract class WriteQueue {
|
||||
return ServiceCode.OK.getCode();
|
||||
}
|
||||
|
||||
public abstract int isValidateMessageForExtend(BasicMessageDto messageDto);
|
||||
public abstract int isValidateMessageForExtend(BasicMessageDto messageDto) throws UnsupportedEncodingException;
|
||||
public abstract void pushMessageToBuffer(BasicMessageDto messageDto) throws Exception;
|
||||
public abstract void initDataBuffer();
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.munjaon.server.server.packet.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Bind {
|
||||
@ -18,37 +19,37 @@ public final class Bind {
|
||||
|
||||
public static final String ENCRYPTION = "0";
|
||||
|
||||
public static ByteBuffer makeBindBuffer(String id, String pwd) {
|
||||
public static ByteBuffer makeBindBuffer(String id, String pwd) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_BIND, BIND_BODY_LENGTH);
|
||||
/* ID */
|
||||
if (id != null) {
|
||||
buffer.put(BIND_ID_POSITION, id.getBytes());
|
||||
buffer.put(BIND_ID_POSITION, id.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* PWD */
|
||||
if (pwd != null) {
|
||||
buffer.put(BIND_PWD_POSITION, pwd.getBytes());
|
||||
buffer.put(BIND_PWD_POSITION, pwd.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* ENCRYPTION */
|
||||
buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes());
|
||||
buffer.put(BIND_ENCRYPTION_POSITION, ENCRYPTION.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer makeBindAckBuffer(String resultCode) {
|
||||
public static ByteBuffer makeBindAckBuffer(String resultCode) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + BIND_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_BIND_ACK, BIND_ACK_BODY_LENGTH);
|
||||
/* resultCode */
|
||||
if (resultCode != null) {
|
||||
buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes());
|
||||
buffer.put(BIND_ACK_RESULT_CODE_POSITION, resultCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static String getBindId(final ByteBuffer buffer) {
|
||||
public static String getBindId(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -60,7 +61,7 @@ public final class Bind {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getBindPwd(final ByteBuffer buffer) {
|
||||
public static String getBindPwd(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -72,7 +73,7 @@ public final class Bind {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getBindEncryption(final ByteBuffer buffer) {
|
||||
public static String getBindEncryption(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -84,7 +85,7 @@ public final class Bind {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getBindAckResultCode(final ByteBuffer buffer) {
|
||||
public static String getBindAckResultCode(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class CommonMessage {
|
||||
@ -33,13 +34,13 @@ public final class CommonMessage {
|
||||
public static final int DELIVER_ACK_RESULT_LENGTH = 1;
|
||||
public static final int DELIVER_ACK_RESULT_POSITION = DELIVER_ACK_MESSAGE_ID_POSITION + DELIVER_ACK_MESSAGE_ID_LENGTH;
|
||||
|
||||
public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) {
|
||||
public static void putMessageIdForDeliver(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || messageId == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageIdForDeliver(ByteBuffer buffer) {
|
||||
public static String getMessageIdForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -51,14 +52,14 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putSenderForDeliver(ByteBuffer buffer, String sender) {
|
||||
public static void putSenderForDeliver(ByteBuffer buffer, String sender) throws UnsupportedEncodingException {
|
||||
if (buffer == null || sender == null) {
|
||||
return;
|
||||
}
|
||||
sender = CommonUtil.cutString(CommonUtil.doNumber(sender), DELIVER_SENDER_LENGTH);
|
||||
buffer.put(DELIVER_SENDER_POSITION, sender.getBytes());
|
||||
buffer.put(DELIVER_SENDER_POSITION, sender.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSenderForDeliver(ByteBuffer buffer) {
|
||||
public static String getSenderForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -70,14 +71,14 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) {
|
||||
public static void putReceiverForDeliver(ByteBuffer buffer, String receiver) throws UnsupportedEncodingException {
|
||||
if (buffer == null || receiver == null) {
|
||||
return;
|
||||
}
|
||||
receiver = CommonUtil.cutString(CommonUtil.doNumber(receiver), DELIVER_RECEIVER_LENGTH);
|
||||
buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes());
|
||||
buffer.put(DELIVER_RECEIVER_POSITION, receiver.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getReceiverForDeliver(ByteBuffer buffer) {
|
||||
public static String getReceiverForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -89,13 +90,13 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) {
|
||||
public static void putReserveTimeForDeliver(ByteBuffer buffer, String reserveTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || reserveTime == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes());
|
||||
buffer.put(DELIVER_RESERVE_TIME_POSITION, reserveTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getReserveTimeForDeliver(ByteBuffer buffer) {
|
||||
public static String getReserveTimeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -107,13 +108,13 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) {
|
||||
public static void putRequestTimeForDeliver(ByteBuffer buffer, String requestTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || requestTime == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes());
|
||||
buffer.put(DELIVER_REQUEST_TIME_POSITION, requestTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getRequestTimeForDeliver(ByteBuffer buffer) {
|
||||
public static String getRequestTimeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -125,13 +126,13 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) {
|
||||
public static void putMsgTypeForDeliver(ByteBuffer buffer, String msgType) throws UnsupportedEncodingException {
|
||||
if (buffer == null || msgType == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes());
|
||||
buffer.put(DELIVER_MSG_TYPE_POSITION, msgType.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMsgTypeForDeliver(ByteBuffer buffer) {
|
||||
public static String getMsgTypeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -144,13 +145,13 @@ public final class CommonMessage {
|
||||
}
|
||||
|
||||
|
||||
public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) {
|
||||
public static void putMessageIdForDeliverAck(ByteBuffer buffer, String messageId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || messageId == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes());
|
||||
buffer.put(DELIVER_ACK_MESSAGE_ID_POSITION, messageId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageIdForDeliverAck(ByteBuffer buffer) {
|
||||
public static String getMessageIdForDeliverAck(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -162,13 +163,13 @@ public final class CommonMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putResultForDeliverAck(ByteBuffer buffer, String result) {
|
||||
public static void putResultForDeliverAck(ByteBuffer buffer, String result) throws UnsupportedEncodingException {
|
||||
if (buffer == null || result == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes());
|
||||
buffer.put(DELIVER_ACK_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getResultForDeliverAck(ByteBuffer buffer) {
|
||||
public static String getResultForDeliverAck(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.ByteUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Header {
|
||||
@ -39,13 +40,13 @@ public final class Header {
|
||||
public static final int BODY_REPORT_LENGTH = 58;
|
||||
public static final int BODY_REPORT_ACK_LENGTH = 1;
|
||||
|
||||
public static void putVersion(final ByteBuffer buffer) {
|
||||
public static void putVersion(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(VERSION_POSITION, VERSION.getBytes());
|
||||
buffer.put(VERSION_POSITION, VERSION.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getVersion(final ByteBuffer buffer) {
|
||||
public static String getVersion(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -58,13 +59,13 @@ public final class Header {
|
||||
// return new String(destArray);
|
||||
}
|
||||
|
||||
public static void putCommand(final ByteBuffer buffer, String command) {
|
||||
public static void putCommand(final ByteBuffer buffer, String command) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(COMMAND_POSITION, command.getBytes());
|
||||
buffer.put(COMMAND_POSITION, command.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getCommand(final ByteBuffer buffer) {
|
||||
public static String getCommand(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -76,10 +77,10 @@ public final class Header {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putBodyLength(final ByteBuffer buffer, int bodyLength) {
|
||||
public static void putBodyLength(final ByteBuffer buffer, int bodyLength) throws UnsupportedEncodingException {
|
||||
putBodyLength(buffer, Integer.toString(bodyLength));
|
||||
}
|
||||
public static String getBodyLength(final ByteBuffer buffer) {
|
||||
public static String getBodyLength(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -92,16 +93,16 @@ public final class Header {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putBodyLength(final ByteBuffer buffer, String bodyLength) {
|
||||
public static void putBodyLength(final ByteBuffer buffer, String bodyLength) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(BODY_POSITION, bodyLength.getBytes());
|
||||
buffer.put(BODY_POSITION, bodyLength.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) {
|
||||
public static void putHeader(final ByteBuffer buffer, String command, int bodyLength) throws UnsupportedEncodingException {
|
||||
putHeader(buffer, command, Integer.toString(bodyLength));
|
||||
}
|
||||
public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) {
|
||||
public static void putHeader(final ByteBuffer buffer, String command, String bodyLength) throws UnsupportedEncodingException {
|
||||
putVersion(buffer);
|
||||
putCommand(buffer, command);
|
||||
putBodyLength(buffer, bodyLength);
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class KakaoMessage {
|
||||
@ -30,14 +31,14 @@ public final class KakaoMessage {
|
||||
public static final int DELIVER_KAKAO_TEMPLATE_CODE_LENGTH = 64;
|
||||
public static final int DELIVER_KAKAO_TEMPLATE_CODE_POSITION = DELIVER_KAKAO_SENDER_KEY_POSITION + DELIVER_KAKAO_SENDER_KEY_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -49,14 +50,14 @@ public final class KakaoMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -67,14 +68,14 @@ public final class KakaoMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) {
|
||||
public static void putKakaoSenderKeyForDeliver(ByteBuffer buffer, String kakaoSenderKey) throws UnsupportedEncodingException {
|
||||
if (buffer == null || kakaoSenderKey == null) {
|
||||
return;
|
||||
}
|
||||
kakaoSenderKey = CommonUtil.cutString(kakaoSenderKey, DELIVER_KAKAO_SENDER_KEY_LENGTH);
|
||||
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes());
|
||||
buffer.put(DELIVER_KAKAO_SENDER_KEY_POSITION, kakaoSenderKey.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) {
|
||||
public static String getKakaoSenderKeyForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -85,14 +86,14 @@ public final class KakaoMessage {
|
||||
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) {
|
||||
public static void putKakaoTemplateCodeForDeliver(ByteBuffer buffer, String kakaoTemplateCode) throws UnsupportedEncodingException {
|
||||
if (buffer == null || kakaoTemplateCode == null) {
|
||||
return;
|
||||
}
|
||||
kakaoTemplateCode = CommonUtil.cutString(kakaoTemplateCode, DELIVER_KAKAO_TEMPLATE_CODE_LENGTH);
|
||||
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes());
|
||||
buffer.put(DELIVER_KAKAO_TEMPLATE_CODE_POSITION, kakaoTemplateCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) {
|
||||
public static String getKakaoTemplateCodeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -104,7 +105,7 @@ public final class KakaoMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getFileNameForDeliver(ByteBuffer buffer) {
|
||||
public static String getFileNameForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -116,7 +117,7 @@ public final class KakaoMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getFileSizeForDeliver(ByteBuffer buffer) {
|
||||
public static String getFileSizeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -128,12 +129,12 @@ public final class KakaoMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) {
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + DELIVER_KAKAO_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_DELIVER_ACK, DELIVER_KAKAO_ACK_BODY_LENGTH);
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.munjaon.server.server.packet.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class LinkCheck {
|
||||
@ -11,20 +12,20 @@ public final class LinkCheck {
|
||||
public static String LINK_CHECK_VALUE = "100";
|
||||
public static String LINK_CHECK_ACK_VALUE = "100";
|
||||
|
||||
public static ByteBuffer makeLinkCheckBuffer() {
|
||||
public static ByteBuffer makeLinkCheckBuffer() throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK, LINK_CHECK_BODY_LENGTH);
|
||||
buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes());
|
||||
buffer.put(LINK_CHECK_BODY_POSITION, LINK_CHECK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static ByteBuffer makeLinkCheckAckBuffer() {
|
||||
public static ByteBuffer makeLinkCheckAckBuffer() throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + LINK_CHECK_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_LINK_CHECK_ACK, LINK_CHECK_ACK_BODY_LENGTH);
|
||||
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes());
|
||||
buffer.put(LINK_CHECK_ACK_BODY_POSITION, LINK_CHECK_ACK_VALUE.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class LmsMessage {
|
||||
@ -16,14 +17,14 @@ public final class LmsMessage {
|
||||
public static final int DELIVER_MESSAGE_LENGTH = 2000;
|
||||
public static final int DELIVER_MESSAGE_POSITION = DELIVER_SUBJECT_POSITION + DELIVER_SUBJECT_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -35,14 +36,14 @@ public final class LmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -54,12 +55,12 @@ public final class LmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) {
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + DELIVER_LMS_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_DELIVER_ACK, DELIVER_LMS_ACK_BODY_LENGTH);
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class MmsMessage {
|
||||
@ -27,14 +28,14 @@ public final class MmsMessage {
|
||||
public static final int DELIVER_MMS_FILESIZE_LENGTH = 8;
|
||||
public static final int DELIVER_MMS_FILESIZE_POSITION = DELIVER_MMS_FILENAME_POSITION + DELIVER_MMS_FILENAME_LENGTH;
|
||||
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) {
|
||||
public static void putSubjectForDeliver(ByteBuffer buffer, String subject) throws UnsupportedEncodingException {
|
||||
if (buffer == null || subject == null) {
|
||||
return;
|
||||
}
|
||||
subject = CommonUtil.cutString(subject, DELIVER_SUBJECT_LENGTH);
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes());
|
||||
buffer.put(DELIVER_SUBJECT_POSITION, subject.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) {
|
||||
public static String getSubjectForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -46,14 +47,14 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -65,17 +66,17 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) {
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, int fileCount) throws UnsupportedEncodingException {
|
||||
putFileCountForDeliver(buffer, Integer.toString(fileCount));
|
||||
}
|
||||
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) {
|
||||
public static void putFileCountForDeliver(ByteBuffer buffer, String fileCount) throws UnsupportedEncodingException {
|
||||
if (buffer == null || fileCount == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes());
|
||||
buffer.put(DELIVER_FILECOUNT_POSITION, fileCount.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getFileCountForDeliver(ByteBuffer buffer) {
|
||||
public static String getFileCountForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -87,7 +88,7 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getFileNameForDeliver(ByteBuffer buffer) {
|
||||
public static String getFileNameForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -99,7 +100,7 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static String getFileSizeForDeliver(ByteBuffer buffer) {
|
||||
public static String getFileSizeForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -111,12 +112,12 @@ public final class MmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) {
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + DELIVER_MMS_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_DELIVER_ACK, DELIVER_MMS_ACK_BODY_LENGTH);
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package com.munjaon.server.server.packet.common;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Packet {
|
||||
public static final String AGENT_CHARACTER_SET = "EUC-KR";
|
||||
public static final byte SET_DEFAULT_BYTE = (byte) 0x00;
|
||||
/* LinkCheck 전송 체크 시간 간격 */
|
||||
public static final long LINK_CHECK_CYCLE = 10000L;
|
||||
@ -18,7 +20,7 @@ public final class Packet {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getString(byte[] srcArray) {
|
||||
public static String getString(byte[] srcArray) throws UnsupportedEncodingException {
|
||||
if (srcArray == null) {
|
||||
return null;
|
||||
}
|
||||
@ -41,7 +43,7 @@ public final class Packet {
|
||||
}
|
||||
}
|
||||
|
||||
return destArray == null ? null : new String(destArray);
|
||||
return destArray == null ? null : new String(destArray, Packet.AGENT_CHARACTER_SET);
|
||||
}
|
||||
|
||||
public static void mergeBuffers(ByteBuffer dest, ByteBuffer srcHead, ByteBuffer srcBody) {
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.server.dto.ReportDto;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class Report {
|
||||
@ -34,7 +35,7 @@ public final class Report {
|
||||
|
||||
public static final int REPORT_ACK_BODY_LENGTH = REPORT_ACK_RESULT_POSITION + REPORT_ACK_RESULT_LENGTH;
|
||||
|
||||
public static void putReport(final ByteBuffer buffer, final ReportDto reportDto) {
|
||||
public static void putReport(final ByteBuffer buffer, final ReportDto reportDto) throws UnsupportedEncodingException {
|
||||
if (reportDto == null) {
|
||||
return;
|
||||
}
|
||||
@ -44,14 +45,14 @@ public final class Report {
|
||||
putTelecom(buffer, reportDto.getRsltNet());
|
||||
putResult(buffer, reportDto.getRsltCode());
|
||||
}
|
||||
public static void putMsgId(final ByteBuffer buffer, String msgId) {
|
||||
public static void putMsgId(final ByteBuffer buffer, String msgId) throws UnsupportedEncodingException {
|
||||
if (buffer == null || msgId == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(REPORT_MSG_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getMsgId(final ByteBuffer buffer) {
|
||||
public static String getMsgId(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -63,14 +64,14 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putAgentCode(final ByteBuffer buffer, String agentCode) {
|
||||
public static void putAgentCode(final ByteBuffer buffer, String agentCode) throws UnsupportedEncodingException {
|
||||
if (buffer == null || agentCode == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes());
|
||||
buffer.put(REPORT_AGENT_CODE_POSITION, agentCode.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getAgentCode(final ByteBuffer buffer) {
|
||||
public static String getAgentCode(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -82,14 +83,14 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putSendTime(final ByteBuffer buffer, String sendTime) {
|
||||
public static void putSendTime(final ByteBuffer buffer, String sendTime) throws UnsupportedEncodingException {
|
||||
if (buffer == null || sendTime == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes());
|
||||
buffer.put(REPORT_SEND_TIME_POSITION, sendTime.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getSendTime(final ByteBuffer buffer) {
|
||||
public static String getSendTime(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -101,14 +102,14 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putTelecom(final ByteBuffer buffer, String telecom) {
|
||||
public static void putTelecom(final ByteBuffer buffer, String telecom) throws UnsupportedEncodingException {
|
||||
if (buffer == null || telecom == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes());
|
||||
buffer.put(REPORT_TELECOM_POSITION, telecom.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getTelecom(final ByteBuffer buffer) {
|
||||
public static String getTelecom(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -120,14 +121,14 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putResult(final ByteBuffer buffer, String result) {
|
||||
public static void putResult(final ByteBuffer buffer, String result) throws UnsupportedEncodingException {
|
||||
if (buffer == null || result == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_RESULT_POSITION, result.getBytes());
|
||||
buffer.put(REPORT_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getResult(final ByteBuffer buffer) {
|
||||
public static String getResult(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -139,14 +140,14 @@ public final class Report {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static void putResultAck(final ByteBuffer buffer, String result) {
|
||||
public static void putResultAck(final ByteBuffer buffer, String result) throws UnsupportedEncodingException {
|
||||
if (buffer == null || result == null) {
|
||||
return;
|
||||
}
|
||||
buffer.put(REPORT_ACK_RESULT_POSITION, result.getBytes());
|
||||
buffer.put(REPORT_ACK_RESULT_POSITION, result.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static String getResultAck(final ByteBuffer buffer) {
|
||||
public static String getResultAck(final ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.munjaon.server.server.packet.common;
|
||||
|
||||
import com.munjaon.server.util.CommonUtil;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public final class SmsMessage {
|
||||
@ -13,14 +14,14 @@ public final class SmsMessage {
|
||||
public static final int DELIVER_MESSAGE_LENGTH = 160;
|
||||
public static final int DELIVER_MESSAGE_POSITION = CommonMessage.DELIVER_MSG_TYPE_POSITION + CommonMessage.DELIVER_MSG_TYPE_LENGTH;
|
||||
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) {
|
||||
public static void putMessageForDeliver(ByteBuffer buffer, String message) throws UnsupportedEncodingException {
|
||||
if (buffer == null || message == null) {
|
||||
return;
|
||||
}
|
||||
message = CommonUtil.cutString(message, DELIVER_MESSAGE_LENGTH);
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes());
|
||||
buffer.put(DELIVER_MESSAGE_POSITION, message.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) {
|
||||
public static String getMessageForDeliver(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -32,12 +33,12 @@ public final class SmsMessage {
|
||||
return Packet.getString(destArray);
|
||||
}
|
||||
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) {
|
||||
public static ByteBuffer makeDeliverAckBuffer(String msgId, String status) throws UnsupportedEncodingException {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH + DELIVER_SMS_ACK_BODY_LENGTH);
|
||||
Packet.setDefaultByte(buffer);
|
||||
Header.putHeader(buffer, Header.COMMAND_DELIVER_ACK, DELIVER_SMS_ACK_BODY_LENGTH);
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes());
|
||||
buffer.put(CommonMessage.DELIVER_ACK_MESSAGE_ID_POSITION, msgId.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
buffer.put(CommonMessage.DELIVER_ACK_RESULT_POSITION, status.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import lombok.Getter;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
@ -339,7 +340,7 @@ public class CollectBackServerService extends Service {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private HeaderDto getHeader(SocketChannel channel) {
|
||||
private HeaderDto getHeader(SocketChannel channel) throws UnsupportedEncodingException {
|
||||
HeaderDto headerDto = HeaderDto.builder().build();
|
||||
int size = -1;
|
||||
ByteBuffer buffer = ByteBuffer.allocate(Header.HEADER_LENGTH);
|
||||
|
||||
@ -191,6 +191,8 @@ public class CollectServer extends Service {
|
||||
saveSystemLog("[CLIENT USER IS DISCONNECT : " + userDto.toString() + "]");
|
||||
collectUserQueue.removeUser(this.serviceType, userDto.getUserId());
|
||||
key.attach(null);
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[COLLECT SERVER][SERVICE TYPE : " + this.serviceType + "][ID : " + userDto.getUserId() + "][EXPIRE CONNECT USER]");
|
||||
}
|
||||
// 소켓 채널 닫기
|
||||
channel.close();
|
||||
|
||||
@ -0,0 +1,222 @@
|
||||
package com.munjaon.server.server.service;
|
||||
|
||||
import com.slack.api.Slack;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HealthCheckServer extends Service {
|
||||
private static List<String> monitorLog = new ArrayList<>();
|
||||
/** Lock Object */
|
||||
private static final Object msgMonitor = new Object();
|
||||
|
||||
/** 설정 모니터링(10초단위로 체크한다.) */
|
||||
private long CONFIG_CHECK_TIME = 0;
|
||||
private String slackYn;
|
||||
private String slackUrl;
|
||||
private int serverCycle;
|
||||
|
||||
private long LAST_QUEUE_CHECK_TIME = 0;
|
||||
private long LAST_SERVER_CHECK_TIME = 0;
|
||||
|
||||
public HealthCheckServer(String serviceName) {
|
||||
super(serviceName);
|
||||
}
|
||||
|
||||
public static void saveMonitorLog(String log) {
|
||||
if (log == null) {
|
||||
return;
|
||||
}
|
||||
synchronized(msgMonitor){
|
||||
monitorLog.add(log);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmptyMonitorLog() {
|
||||
synchronized(msgMonitor){
|
||||
return monitorLog.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public static String popMonitorLog() {
|
||||
synchronized(msgMonitor){
|
||||
return monitorLog.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkReady() {
|
||||
this.IS_READY_YN = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initResources() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseResources() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() {
|
||||
saveSystemLog("HEALTH_CHECK_SERVER : SERVER SERVICE STARTED ... ...");
|
||||
while (isRun()) {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
loadMonitorConfig();
|
||||
serverMonitor();
|
||||
sendMonitorLog();
|
||||
} catch (Exception e) {
|
||||
saveSystemLog(e.toString());
|
||||
}
|
||||
}
|
||||
saveSystemLog("HEALTH_CHECK_SERVER : SERVER SERVICE STOPPED ... ...");
|
||||
}
|
||||
|
||||
private void loadMonitorConfig() {
|
||||
if (System.currentTimeMillis() - CONFIG_CHECK_TIME < 10000) {
|
||||
return;
|
||||
}
|
||||
slackYn = getProp("SLACK_FLAG");
|
||||
slackUrl = getProp("SLACK_URL");
|
||||
serverCycle = Integer.parseInt(getProp("SERVER_CYCLE")) * 60000;
|
||||
CONFIG_CHECK_TIME = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void sendMonitorLog() {
|
||||
Slack slack = Slack.getInstance();
|
||||
try {
|
||||
while (true) {
|
||||
if (isEmptyMonitorLog()) {
|
||||
break;
|
||||
}
|
||||
|
||||
String msg = popMonitorLog();
|
||||
if (msg == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
saveSystemLog(msg);
|
||||
if ("Y".equals(slackYn)) {
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("text", msg);
|
||||
slack.send(slackUrl, String.valueOf(payload));
|
||||
}
|
||||
}
|
||||
Thread.sleep(3000);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
saveSystemLog(e);
|
||||
} finally {
|
||||
if (slack != null) {
|
||||
try {
|
||||
slack.close();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void serverMonitor() {
|
||||
if (System.currentTimeMillis() - LAST_SERVER_CHECK_TIME < serverCycle) {
|
||||
return;
|
||||
}
|
||||
boolean isConnected = false;
|
||||
int port;
|
||||
|
||||
/* 1. SMS */
|
||||
port = Integer.parseInt(getProp("SMS_COLLECTOR", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[SMS SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[SMS SERVER is Shutdown]");
|
||||
}
|
||||
/* 2. LMS */
|
||||
port = Integer.parseInt(getProp("LMS_COLLECTOR", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[LMS SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[LMS SERVER is Shutdown]");
|
||||
}
|
||||
/* 3. MMS */
|
||||
port = Integer.parseInt(getProp("MMS_COLLECTOR", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[MMS SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[MMS SERVER is Shutdown]");
|
||||
}
|
||||
/* 4. 알림톡 */
|
||||
port = Integer.parseInt(getProp("KAT_COLLECTOR", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[KAT SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[KAT SERVER is Shutdown]");
|
||||
}
|
||||
/* 5. 친구톡 */
|
||||
port = Integer.parseInt(getProp("KFT_COLLECTOR", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[KFT SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[KFT SERVER is Shutdown]");
|
||||
}
|
||||
/* 6. 리포트 */
|
||||
port = Integer.parseInt(getProp("REPORTER", "SERVICE_PORT"));
|
||||
isConnected = connectTest(port);
|
||||
if (isConnected) {
|
||||
saveMonitorLog("[REPORT SERVER is Connectable]");
|
||||
} else {
|
||||
saveMonitorLog("[REPORT SERVER is Shutdown]");
|
||||
}
|
||||
|
||||
LAST_SERVER_CHECK_TIME = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private boolean connectTest(int port) {
|
||||
boolean isConnected = false;
|
||||
SocketChannel socketChannel = null;
|
||||
try {
|
||||
socketChannel = SocketChannel.open(new InetSocketAddress(port));
|
||||
socketChannel.configureBlocking(false);
|
||||
|
||||
long connectStartTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
if (socketChannel.finishConnect()) {
|
||||
isConnected = true;
|
||||
break;
|
||||
}
|
||||
if (System.currentTimeMillis() - connectStartTime > 3000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
saveSystemLog("Connect Fail to [PORT : " + port + "]");
|
||||
saveSystemLog("ERROR [" + e.getMessage() + "]");
|
||||
} finally {
|
||||
if (socketChannel != null) {
|
||||
try {
|
||||
socketChannel.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject monitorService() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -25,6 +25,9 @@ public class QueueServerService extends Service {
|
||||
private long QUEUE_INIT_CHECK_TIME = 0;
|
||||
/** Commit 누적 카운트 */
|
||||
private long SUM_COMMIT_COUNT = 0;
|
||||
/** 큐모니터링 체크 사이클 */
|
||||
private int QUEUE_MONITOR_CYCLE;
|
||||
private long QUEUE_MONITOR_CHECK_TIME = 0;
|
||||
SerialQueuePool queueInstance = SerialQueuePool.getInstance();
|
||||
/* 쓰기큐 */
|
||||
private WriteQueue writeQueue;
|
||||
@ -49,6 +52,8 @@ public class QueueServerService extends Service {
|
||||
QUEUE_MODE = QUEUE_MODE.toUpperCase();
|
||||
// 읽은 시간 업데이트
|
||||
QUEUE_MODE_CHECK_TIME = System.currentTimeMillis();
|
||||
// 큐모니터링 체크 사이클
|
||||
QUEUE_MONITOR_CYCLE = Integer.parseInt(getProp("HEALTH", "QUEUE_CYCLE")) * 60000;
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,6 +259,7 @@ public class QueueServerService extends Service {
|
||||
checkMode();
|
||||
checkQueue();
|
||||
messageService();
|
||||
monitorService();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -262,6 +268,11 @@ public class QueueServerService extends Service {
|
||||
|
||||
@Override
|
||||
public JSONObject monitorService() {
|
||||
if (System.currentTimeMillis() - QUEUE_MONITOR_CHECK_TIME < QUEUE_MONITOR_CYCLE) {
|
||||
return null;
|
||||
}
|
||||
HealthCheckServer.saveMonitorLog("[QUEUE MONITOR][" + getName() + "] [WRITE POSITION : " + writeQueue.getPushCounter() + "][READ POSITION : " + readQueue.getPopCounter() + "]");
|
||||
QUEUE_MONITOR_CHECK_TIME = System.currentTimeMillis();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@ package com.munjaon.server.server.service;
|
||||
import com.munjaon.server.queue.pool.ReportQueue;
|
||||
import com.munjaon.server.server.dto.ReportUserDto;
|
||||
import com.munjaon.server.server.queue.ReportUserQueue;
|
||||
import com.munjaon.server.server.task.ReportBindTask;
|
||||
import com.munjaon.server.server.task.ReportLinkCheckTask;
|
||||
import com.munjaon.server.server.task.ReportResultTask;
|
||||
import com.munjaon.server.server.task.ReportServerTask;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@ -81,7 +84,7 @@ public class ReportServer extends Service {
|
||||
saveSystemLog("REPORT_SERVER : SERVER SERVICE STARTED ... ...");
|
||||
while (isRun()) {
|
||||
try {
|
||||
execInterest();
|
||||
bindInterest();
|
||||
checkInterest();
|
||||
} catch (Exception e) {
|
||||
saveSystemLog(e.toString());
|
||||
@ -91,6 +94,48 @@ public class ReportServer extends Service {
|
||||
}
|
||||
|
||||
private void checkInterest() throws IOException, InterruptedException {
|
||||
Iterator<SelectionKey> keys = selector.keys().iterator();
|
||||
while (keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
if (key.isValid()) {
|
||||
ReportUserDto reportUserDto = (ReportUserDto) key.attachment();
|
||||
if (reportUserDto == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (reportUserDto.isLogin()) {
|
||||
if (reportUserDto.isAlive() == 2) {
|
||||
if (reportUserDto.isRunningMode()) {
|
||||
continue;
|
||||
}
|
||||
/* 로그인이 된경우 Link Check를 위해 실행 */
|
||||
reportUserDto.setRunningMode(true);
|
||||
/* 사용자별 Link Check Thread 실행 */
|
||||
new ReportLinkCheckTask(key, getName(), logger).run();
|
||||
} else {
|
||||
ReportQueue reportQueue = reportUserDto.getReportQueue();
|
||||
if (reportQueue != null && reportQueue.isRemainReport()) {
|
||||
if (reportUserDto.isRunningMode()) {
|
||||
continue;
|
||||
}
|
||||
reportUserDto.setRunningMode(true);
|
||||
/* 사용자별 Report Thread 실행 */
|
||||
new ReportResultTask(key, getName(), logger).start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (reportUserDto.isRunningMode()) {
|
||||
continue;
|
||||
}
|
||||
if (reportUserDto.isAlive() == 1) { // 로그인이 완료되지 않은 경우
|
||||
expireConnectUser(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInterest_bak() throws IOException, InterruptedException {
|
||||
Iterator<SelectionKey> keys = selector.keys().iterator();
|
||||
while (keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
@ -105,9 +150,12 @@ public class ReportServer extends Service {
|
||||
if (reportUserDto.isRunningMode()) {
|
||||
continue;
|
||||
}
|
||||
reportUserDto.setRunningMode(true);
|
||||
/* 사용자별 Report Thread 실행 */
|
||||
new ReportServerTask(selector, key, getName(), logger).run();
|
||||
/* 로그인이 된경우 Link Check를 위해 실행 */
|
||||
if (reportUserDto.isLogin()) {
|
||||
reportUserDto.setRunningMode(true);
|
||||
/* 사용자별 Report Thread 실행 */
|
||||
new ReportServerTask(selector, key, getName(), logger).run();
|
||||
}
|
||||
} else {
|
||||
ReportQueue reportQueue = reportUserDto.getReportQueue();
|
||||
if (reportUserDto.isLogin() && reportQueue != null && reportQueue.isRemainReport()) {
|
||||
@ -125,12 +173,44 @@ public class ReportServer extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void bindInterest() throws IOException {
|
||||
if (selector.select(300) == 0) {
|
||||
return ;
|
||||
}
|
||||
Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
|
||||
while (keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
/* 키 셋에서 제거. */
|
||||
keys.remove();
|
||||
|
||||
if (key.isValid()) {
|
||||
if (key.isAcceptable()) { // 접속일 경우..
|
||||
saveSystemLog("CONNECTION IS ACCEPTABLE ... ...");
|
||||
accept(selector, key);
|
||||
} else if (key.isReadable()) { // 수신일 경우..
|
||||
ReportUserDto reportUserDto = (ReportUserDto) key.attachment();
|
||||
if (reportUserDto == null) {
|
||||
continue;
|
||||
}
|
||||
if (reportUserDto.isRunningMode()) {
|
||||
continue;
|
||||
}
|
||||
if (reportUserDto.isLogin()) {
|
||||
continue;
|
||||
}
|
||||
reportUserDto.setRunningMode(true);
|
||||
/* 사용자별 Report Thread 실행 */
|
||||
new ReportBindTask(key, getName(), logger).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void execInterest() throws IOException {
|
||||
if (selector.select(1000) == 0) {
|
||||
return ;
|
||||
}
|
||||
Iterator<SelectionKey> keys = selector.selectedKeys().iterator();
|
||||
List<Future<ReportUserDto>> list = new ArrayList<>();
|
||||
while (keys.hasNext()) {
|
||||
SelectionKey key = keys.next();
|
||||
/* 키 셋에서 제거. */
|
||||
@ -186,6 +266,8 @@ public class ReportServer extends Service {
|
||||
reportUserQueue.removeUser(userDto.getUserId());
|
||||
// connectUserMap.remove(userDto.getUserId());
|
||||
key.attach(null);
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[REPORT SERVER][ID : " + userDto.getUserId() + "][EXPIRE CONNECT USER]");
|
||||
}
|
||||
// 소켓 채널 닫기
|
||||
channel.close();
|
||||
|
||||
@ -12,6 +12,7 @@ import com.munjaon.server.util.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
@ -136,7 +137,7 @@ public class CollectReadTask implements Callable<ConnectUserDto> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) {
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) throws UnsupportedEncodingException {
|
||||
if (deliverBuffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -9,11 +9,13 @@ import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.dto.ConnectUserDto;
|
||||
import com.munjaon.server.server.packet.common.*;
|
||||
import com.munjaon.server.server.queue.CollectUserQueue;
|
||||
import com.munjaon.server.server.service.HealthCheckServer;
|
||||
import com.munjaon.server.server.service.PropertyLoader;
|
||||
import com.munjaon.server.util.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
@ -131,8 +133,8 @@ public class CollectServerTask extends Thread {
|
||||
/* 2. Packet Timeout Check */
|
||||
if (checkTimeOut()) {
|
||||
saveSystemLog(printTaskLog() + "[checkTimeOut : Expired ... ... ... ... ... ... ...]");
|
||||
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]");
|
||||
expireConnectUser();
|
||||
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]");
|
||||
break;
|
||||
}
|
||||
/* 3. HeadBuffer 읽기 */
|
||||
@ -232,7 +234,7 @@ public class CollectServerTask extends Thread {
|
||||
return false;
|
||||
}
|
||||
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) {
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) throws UnsupportedEncodingException {
|
||||
if (deliverBuffer == null) {
|
||||
return null;
|
||||
}
|
||||
@ -557,8 +559,6 @@ public class CollectServerTask extends Thread {
|
||||
connectUserDto.setUserId(id);
|
||||
connectUserDto.setLogin(true);
|
||||
connectUserDto.setMemberDto(memberDto);
|
||||
/* 사용자 Pool에 저장 */
|
||||
collectUserQueue.putUser(this.serviceType, connectUserDto);
|
||||
/* 세션통신 시간 업데이트 */
|
||||
connectUserDto.updateLastTrafficTime();
|
||||
}
|
||||
@ -570,11 +570,17 @@ public class CollectServerTask extends Thread {
|
||||
try {
|
||||
saveSystemLog(printTaskLog() + "[BIND RESULT : " + resultCode + "]");
|
||||
channel.write(Bind.makeBindAckBuffer(resultCode));
|
||||
if ("00".equals(resultCode) == false) {
|
||||
if ("00".equals(resultCode)) {
|
||||
/* BIND 성공인 경우 사용자 Pool에 저장 */
|
||||
collectUserQueue.putUser(this.serviceType, connectUserDto);
|
||||
} else {
|
||||
expireConnectUser();
|
||||
}
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[COLLECT SERVER][SERVICE TYPE : " + this.serviceType + "][ID : " + connectUserDto.getUserId() + "][BIND RESULT : " + resultCode + "]");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
saveSystemLog(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -641,6 +647,8 @@ public class CollectServerTask extends Thread {
|
||||
if (connectUserDto != null) {
|
||||
if (connectUserDto.getUserId() != null) {
|
||||
collectUserQueue.removeUser(connectUserDto.getServiceType(), connectUserDto.getUserId());
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[COLLECT SERVER][SERVICE TYPE : " + this.serviceType + "][ID : " + connectUserDto.getUserId() + "][EXPIRE CONNECT USER]");
|
||||
}
|
||||
key.attach(null);
|
||||
}
|
||||
|
||||
143
src/main/java/com/munjaon/server/server/task/ReportBindTask.java
Normal file
143
src/main/java/com/munjaon/server/server/task/ReportBindTask.java
Normal file
@ -0,0 +1,143 @@
|
||||
package com.munjaon.server.server.task;
|
||||
|
||||
import com.munjaon.server.cache.dto.MemberDto;
|
||||
import com.munjaon.server.cache.enums.CacheService;
|
||||
import com.munjaon.server.cache.service.MemberService;
|
||||
import com.munjaon.server.queue.pool.ReportQueue;
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.packet.common.Bind;
|
||||
import com.munjaon.server.server.packet.common.Header;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.server.service.HealthCheckServer;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
public class ReportBindTask extends ReportTask {
|
||||
public ReportBindTask(SelectionKey key, String serviceName, LogUtil logger) {
|
||||
super(key, serviceName, "BIND_TASK", logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() throws Exception {
|
||||
SEND_CYCLE_CHECK_TIME = System.currentTimeMillis();
|
||||
while(true) {
|
||||
/* 1. Head 읽기 */
|
||||
int size = readHeader();
|
||||
/* 2. Body 읽기 */
|
||||
if (size > 0) {
|
||||
String command = Header.getCommand(this.headBuffer);
|
||||
if (Integer.parseInt(command) == 1) {
|
||||
recvBind(headBuffer);
|
||||
} else {
|
||||
expireConnectUser();
|
||||
}
|
||||
/* 패킷 수신한 경우 무조건 루프를 빠져나간다 */
|
||||
break;
|
||||
}
|
||||
/* 3초 이내에 로그인 실패시 종료 */
|
||||
if (System.currentTimeMillis() - SEND_CYCLE_CHECK_TIME > ServerConfig.LIMIT_BIND_TIMEOUT) {
|
||||
expireConnectUser();
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* 세션 만료 여부 */
|
||||
this.isExpiredYn = true;
|
||||
}
|
||||
|
||||
private void recvBind(ByteBuffer headBuffer) {
|
||||
String resultCode = "00";
|
||||
try {
|
||||
ByteBuffer bindBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Bind.BIND_BODY_LENGTH);
|
||||
ByteBuffer bodyBuffer = ByteBuffer.allocate(Bind.BIND_BODY_LENGTH);
|
||||
channel.read(bodyBuffer);
|
||||
Packet.mergeBuffers(bindBuffer, headBuffer, bodyBuffer);
|
||||
|
||||
String id = Bind.getBindId(bindBuffer);
|
||||
String pwd = Bind.getBindPwd(bindBuffer);
|
||||
|
||||
MemberService svc = (MemberService) CacheService.LOGIN_SERVICE.getService();
|
||||
MemberDto memberDto = null;
|
||||
if (svc != null) {
|
||||
memberDto = svc.get(id);
|
||||
}
|
||||
saveSystemLog("[" + this.taskName + "][BIND REQUEST] [ID : " + id + ", PWD : " + pwd + "]");
|
||||
/* Bind Check */
|
||||
resultCode = checkBind(memberDto, id, pwd);
|
||||
|
||||
/* 접속 IP 체크 */
|
||||
if ("00".equals(resultCode)) {
|
||||
boolean isPermit = false;
|
||||
if (memberDto.getIpLimitYn() == null || "Y".equals(memberDto.getIpLimitYn())) {
|
||||
saveSystemLog("[" + this.taskName + "][REMOTE IP : " + reportUserDto.getRemoteIP() + "]");
|
||||
saveSystemLog("[" + this.taskName + "][ALLOW IP BASIC : " + memberDto.getAllowIpBasic() + "]");
|
||||
saveSystemLog("[" + this.taskName + "][ALLOW IP EXTEND : " + memberDto.getAllowIpExtend() + "]");
|
||||
if (memberDto.getAllowIpBasic() != null && reportUserDto.getRemoteIP().equals(memberDto.getAllowIpBasic())) {
|
||||
isPermit = true;
|
||||
}
|
||||
if (memberDto.getAllowIpExtend() != null && reportUserDto.getRemoteIP().equals(memberDto.getAllowIpExtend())) {
|
||||
isPermit = true;
|
||||
}
|
||||
} else {
|
||||
isPermit = true;
|
||||
}
|
||||
if (isPermit) {
|
||||
resultCode = "00";
|
||||
} else {
|
||||
resultCode = "40";
|
||||
}
|
||||
}
|
||||
|
||||
/* BIND 성공인 경우 사용자 정보 저장 */
|
||||
if ("00".equals(resultCode)) {
|
||||
reportUserDto.setUserId(id);
|
||||
reportUserDto.setLogin(true);
|
||||
reportUserDto.setMemberDto(memberDto);
|
||||
/* 리포트 큐 생성 */
|
||||
ReportQueue reportQueue = new ReportQueue(reportUserDto.getQueuePath(), reportUserDto.getUserId());
|
||||
reportUserDto.setReportQueue(reportQueue);
|
||||
/* 세션통신 시간 업데이트 */
|
||||
reportUserDto.updateLastTrafficTime();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
resultCode = "10";
|
||||
saveSystemLog(e);
|
||||
}
|
||||
|
||||
try {
|
||||
saveSystemLog("[" + this.taskName + "][BIND RESULT : " + resultCode + "]");
|
||||
channel.write(Bind.makeBindAckBuffer(resultCode));
|
||||
if ("00".equals(resultCode)) {
|
||||
/* BIND 성공인 경우 사용자 Pool에 저장 */
|
||||
reportUserQueue.putUser(reportUserDto);
|
||||
} else {
|
||||
expireConnectUser();
|
||||
}
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[REPORT SERVER][ID : " + reportUserDto.getUserId() + "][BIND RESULT : " + resultCode + "]");
|
||||
} catch (IOException e) {
|
||||
saveSystemLog(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String checkBind(MemberDto memberDto, String id, String pwd) {
|
||||
if (id == null || pwd == null) {
|
||||
return "50";
|
||||
}
|
||||
if (reportUserQueue.isExist(id)) {
|
||||
return "60";
|
||||
}
|
||||
if (memberDto == null || !pwd.equals(memberDto.getAccessKey())) {
|
||||
return "20";
|
||||
}
|
||||
/* 회원 사용 상태 */
|
||||
if (memberDto.getMberSttus() == null || "N".equals(memberDto.getMberSttus())) {
|
||||
return "30";
|
||||
}
|
||||
|
||||
return "00";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
package com.munjaon.server.server.task;
|
||||
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.packet.common.Header;
|
||||
import com.munjaon.server.server.packet.common.LinkCheck;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
public class ReportLinkCheckTask extends ReportTask {
|
||||
/* Packet을 전송했는지 여부 */
|
||||
private boolean isPacketSendYn;
|
||||
|
||||
public ReportLinkCheckTask(SelectionKey key, String serviceName, LogUtil logger) {
|
||||
super(key, serviceName, "LINK_CHECK_TASK", logger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() throws Exception {
|
||||
sendInterest();
|
||||
recvInterest();
|
||||
/* 세션 만료 여부 */
|
||||
this.isExpiredYn = true;
|
||||
}
|
||||
|
||||
private void sendInterest() throws Exception {
|
||||
if (isPacketSendYn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reportUserDto.isAlive() == 2) {
|
||||
channel.write(LinkCheck.makeLinkCheckBuffer());
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][SEND LINK CHECK ... ... ... ... ... ... ...]");
|
||||
/* 패킷 전송 시간 체크위한 설정(3초간 유지) */
|
||||
SEND_CYCLE_CHECK_TIME = System.currentTimeMillis();
|
||||
/* Packet 전송했는지 여부 */
|
||||
isPacketSendYn = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void recvInterest() throws IOException, InterruptedException {
|
||||
while (isPacketSendYn) {
|
||||
/* 1. Head 읽기 */
|
||||
ByteBuffer headBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH);
|
||||
int size = channel.read(headBuffer);
|
||||
if (size > 0) {
|
||||
String command = Header.getCommand(headBuffer);
|
||||
switch (Integer.parseInt(command)) {
|
||||
case 8 : recvLinkCheck(); break;
|
||||
default: saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][INVALID REQUEST][command : " + command + "]");
|
||||
expireConnectUser(); break;
|
||||
}
|
||||
} else if (size == 0) {
|
||||
Thread.sleep(1);
|
||||
if (System.currentTimeMillis() - SEND_CYCLE_CHECK_TIME >= ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][SEND_CYCLE_CHECK_TIME IS OVER : 3000ms]");
|
||||
expireConnectUser();
|
||||
this.isExpiredYn = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][recvInterest : size is zero]");
|
||||
expireConnectUser();
|
||||
throw new IOException("[ID : " + this.reportUserDto.getUserId() + "][recvInterest : size is zero]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recvLinkCheck() throws IOException {
|
||||
ByteBuffer bodyBuffer = ByteBuffer.allocate(LinkCheck.LINK_CHECK_ACK_BODY_LENGTH);
|
||||
int size = channel.read(bodyBuffer);
|
||||
if (size > 0) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][RECEIVE LINK CHECK ACK ... ... ... ... ... ... ...]");
|
||||
reportUserDto.updateLastTrafficTime();
|
||||
this.isPacketSendYn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package com.munjaon.server.server.task;
|
||||
|
||||
import com.munjaon.server.queue.pool.ReportQueue;
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.dto.ReportDto;
|
||||
import com.munjaon.server.server.packet.common.Header;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.server.packet.common.Report;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
public class ReportResultTask extends ReportTask {
|
||||
/* Packet을 전송했는지 여부 */
|
||||
private boolean isPacketSendYn;
|
||||
private final ReportQueue reportQueue;
|
||||
private ReportDto reportDto; // 전송 리포트
|
||||
|
||||
public ReportResultTask(SelectionKey key, String serviceName, LogUtil logger) {
|
||||
super(key, serviceName, "RESULT_TASK", logger);
|
||||
|
||||
this.reportQueue = reportUserDto.getReportQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doService() throws Exception {
|
||||
sendInterest();
|
||||
recvInterest();
|
||||
/* 세션 만료 여부 */
|
||||
if (System.currentTimeMillis() - this.reportUserDto.getLastTrafficTime() >= ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
this.isExpiredYn = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void recvInterest() throws Exception {
|
||||
while (isPacketSendYn) {
|
||||
/* 1. Head 읽기 */
|
||||
ByteBuffer headBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH);
|
||||
int size = channel.read(headBuffer);
|
||||
if (size > 0) {
|
||||
String command = Header.getCommand(headBuffer);
|
||||
switch (Integer.parseInt(command)) {
|
||||
case 6 : recvReport(); break;
|
||||
default: saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][INVALID REQUEST][command : " + command + "]");
|
||||
expireConnectUser(); break;
|
||||
}
|
||||
} else if (size == 0) {
|
||||
Thread.sleep(1);
|
||||
if (System.currentTimeMillis() - SEND_CYCLE_CHECK_TIME >= ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][SEND_CYCLE_CHECK_TIME IS OVER : 3000ms]");
|
||||
expireConnectUser();
|
||||
this.isExpiredYn = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][recvInterest : size is zero]");
|
||||
expireConnectUser();
|
||||
throw new IOException("[ID : " + this.reportUserDto.getUserId() + "][recvInterest : size is zero]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recvReport() throws Exception {
|
||||
ByteBuffer bodyBuffer = ByteBuffer.allocate(Report.REPORT_ACK_BODY_LENGTH);
|
||||
int size = channel.read(bodyBuffer);
|
||||
if (size != Report.REPORT_ACK_BODY_LENGTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][RECEIVE REPORT ACK ... ... ... ... ... ... ...]");
|
||||
ReportQueue reportQueue = reportUserDto.getReportQueue();
|
||||
reportUserDto.updateLastTrafficTime();
|
||||
this.isPacketSendYn = false;
|
||||
if (reportQueue != null && this.reportDto != null) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][RECEIVE REPORT : " + this.reportDto.toString() + "]");
|
||||
reportQueue.addReadCounter();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendInterest() throws Exception {
|
||||
if (isPacketSendYn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.reportQueue != null && this.reportQueue.isRemainReport()) {
|
||||
this.reportDto = this.reportQueue.popReportFromQueue();
|
||||
if (reportDto == null) {
|
||||
return;
|
||||
}
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][REPORT SEND : " + reportDto.toString() + "]");
|
||||
ByteBuffer reportBuffer = ByteBuffer.allocate(Header.HEADER_LENGTH + Report.REPORT_BODY_LENGTH);
|
||||
Packet.setDefaultByte(reportBuffer);
|
||||
Header.putHeader(reportBuffer, Header.COMMAND_REPORT, Report.REPORT_BODY_LENGTH);
|
||||
Report.putReport(reportBuffer, reportDto);
|
||||
channel.write(reportBuffer);
|
||||
/* 패킷 전송 시간 체크위한 설정(3초간 유지) */
|
||||
SEND_CYCLE_CHECK_TIME = System.currentTimeMillis();
|
||||
/* Packet 전송했는지 여부 */
|
||||
isPacketSendYn = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,10 +9,12 @@ import com.munjaon.server.server.dto.ReportDto;
|
||||
import com.munjaon.server.server.dto.ReportUserDto;
|
||||
import com.munjaon.server.server.packet.common.*;
|
||||
import com.munjaon.server.server.queue.ReportUserQueue;
|
||||
import com.munjaon.server.server.service.HealthCheckServer;
|
||||
import com.munjaon.server.server.service.PropertyLoader;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
@ -38,6 +40,7 @@ public class ReportServerTask extends Thread {
|
||||
private boolean IS_RUN_YN;
|
||||
private long RUN_FLAG_CHECK_TIME;
|
||||
private long SEND_CYCLE_CHECK_TIME;
|
||||
private long LAST_PACKET_SEND_TIME = System.currentTimeMillis(); // 패킷 송수신 시간을 체크하기 위한 변수(최대 3초간 요청이 없는 경우 Thread 종료)
|
||||
private boolean IS_ERROR = false;
|
||||
|
||||
/* 세션이 만료되었는지 체크 */
|
||||
@ -114,8 +117,8 @@ public class ReportServerTask extends Thread {
|
||||
/* 2. Packet Timeout Check */
|
||||
if (checkTimeOut()) {
|
||||
saveSystemLog(printTaskLog() + "[checkTimeOut : Expired ... ... ... ... ... ... ...]");
|
||||
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]");
|
||||
expireConnectUser();
|
||||
saveSystemLog(printTaskLog() + "[### End ### ### ### ### ### ### ###]");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -124,7 +127,7 @@ public class ReportServerTask extends Thread {
|
||||
/* RUN Flag 체크 */
|
||||
reloadRunFlag();
|
||||
/* 쓰레드 완료 시점 체크 */
|
||||
if (System.currentTimeMillis() - SEND_CYCLE_CHECK_TIME > ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
if (System.currentTimeMillis() - LAST_PACKET_SEND_TIME > ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -171,7 +174,7 @@ public class ReportServerTask extends Thread {
|
||||
return size;
|
||||
}
|
||||
|
||||
private void bindInterest() {
|
||||
private void bindInterest() throws UnsupportedEncodingException {
|
||||
if (reportUserDto.isLogin()) {
|
||||
return;
|
||||
}
|
||||
@ -241,6 +244,7 @@ public class ReportServerTask extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
/* BIND 성공인 경우 사용자 정보 저장 */
|
||||
if ("00".equals(resultCode)) {
|
||||
reportUserDto.setUserId(id);
|
||||
reportUserDto.setLogin(true);
|
||||
@ -248,8 +252,6 @@ public class ReportServerTask extends Thread {
|
||||
/* 리포트 큐 생성 */
|
||||
ReportQueue reportQueue = new ReportQueue(reportUserDto.getQueuePath(), reportUserDto.getUserId());
|
||||
reportUserDto.setReportQueue(reportQueue);
|
||||
/* 사용자 Pool에 저장 */
|
||||
reportUserQueue.putUser(reportUserDto);
|
||||
/* 세션통신 시간 업데이트 */
|
||||
reportUserDto.updateLastTrafficTime();
|
||||
}
|
||||
@ -261,11 +263,17 @@ public class ReportServerTask extends Thread {
|
||||
try {
|
||||
saveSystemLog(printTaskLog() + "[BIND RESULT : " + resultCode + "]");
|
||||
channel.write(Bind.makeBindAckBuffer(resultCode));
|
||||
if (!"00".equals(resultCode)) {
|
||||
if ("00".equals(resultCode)) {
|
||||
/* BIND 성공인 경우 사용자 Pool에 저장 */
|
||||
reportUserQueue.putUser(reportUserDto);
|
||||
} else {
|
||||
expireConnectUser();
|
||||
}
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[REPORT SERVER][ID : " + reportUserDto.getUserId() + "][BIND RESULT : " + resultCode + "]");
|
||||
} catch (IOException e) {
|
||||
saveSystemLog(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,12 +305,16 @@ public class ReportServerTask extends Thread {
|
||||
switch (Integer.parseInt(command)) {
|
||||
case 6 : recvReport(channel); break;
|
||||
case 8 : recvLinkCheck(channel); break;
|
||||
default: saveSystemLog(printTaskLog() + "[INVALID REQUEST][command : " + command + ";");
|
||||
default: saveSystemLog(printTaskLog() + "[INVALID REQUEST][command : " + command + "]");
|
||||
expireConnectUser(); break;
|
||||
}
|
||||
/* 마지막 패킷 수신시간 체크 */
|
||||
LAST_PACKET_SEND_TIME = System.currentTimeMillis();
|
||||
} else if (size == 0) {
|
||||
Thread.sleep(1);
|
||||
if (System.currentTimeMillis() - SEND_CYCLE_CHECK_TIME >= ServerConfig.REPORT_EXEC_CYCLE_TIME) {
|
||||
saveSystemLog(printTaskLog() + "[SEND_CYCLE_CHECK_TIME IS OVER : 3000ms]");
|
||||
expireConnectUser();
|
||||
this.isExpiredYn = true;
|
||||
break;
|
||||
}
|
||||
@ -318,7 +330,7 @@ public class ReportServerTask extends Thread {
|
||||
ByteBuffer bodyBuffer = ByteBuffer.allocate(LinkCheck.LINK_CHECK_ACK_BODY_LENGTH);
|
||||
int size = channel.read(bodyBuffer);
|
||||
if (size > 0) {
|
||||
saveSystemLog(printTaskLog() + "[RECEIVER LINK CHECK ACK ... ... ... ... ... ... ...]");
|
||||
saveSystemLog(printTaskLog() + "[RECEIVE LINK CHECK ACK ... ... ... ... ... ... ...]");
|
||||
reportUserDto.updateLastTrafficTime();
|
||||
this.isPacketSendYn = false;
|
||||
}
|
||||
@ -347,6 +359,7 @@ public class ReportServerTask extends Thread {
|
||||
}
|
||||
if (reportUserDto.isAlive() == 2) {
|
||||
channel.write(LinkCheck.makeLinkCheckBuffer());
|
||||
saveSystemLog(printTaskLog() + "[SEND LINK CHECK ... ... ... ... ... ... ...]");
|
||||
SEND_CYCLE_CHECK_TIME = System.currentTimeMillis();
|
||||
/* Packet 전송했는지 여부 */
|
||||
isPacketSendYn = true;
|
||||
@ -381,6 +394,8 @@ public class ReportServerTask extends Thread {
|
||||
reportUserQueue.removeUser(reportUserDto.getUserId());
|
||||
}
|
||||
key.attach(null);
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[REPORT SERVER][ID : " + reportUserDto.getUserId() + "][EXPIRE CONNECT USER]");
|
||||
}
|
||||
/* 세션 만료 여부 */
|
||||
this.isExpiredYn = true;
|
||||
|
||||
173
src/main/java/com/munjaon/server/server/task/ReportTask.java
Normal file
173
src/main/java/com/munjaon/server/server/task/ReportTask.java
Normal file
@ -0,0 +1,173 @@
|
||||
package com.munjaon.server.server.task;
|
||||
|
||||
import com.munjaon.server.server.config.ServerConfig;
|
||||
import com.munjaon.server.server.dto.ReportUserDto;
|
||||
import com.munjaon.server.server.packet.common.Header;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
import com.munjaon.server.server.queue.ReportUserQueue;
|
||||
import com.munjaon.server.server.service.HealthCheckServer;
|
||||
import com.munjaon.server.server.service.PropertyLoader;
|
||||
import com.munjaon.server.util.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public abstract class ReportTask 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]";
|
||||
|
||||
protected final SelectionKey key;
|
||||
protected final SocketChannel channel;
|
||||
protected final ReportUserQueue reportUserQueue = ReportUserQueue.getInstance();
|
||||
protected final ReportUserDto reportUserDto;
|
||||
protected final String serviceName;
|
||||
protected final String taskName;
|
||||
protected final LogUtil logger;
|
||||
|
||||
protected boolean IS_ERROR = false;
|
||||
/* 세션이 만료되었는지 체크 */
|
||||
protected boolean isExpiredYn;
|
||||
/* 클라이언트 요청 데이터 수신 */
|
||||
protected final ByteBuffer headBuffer = ByteBuffer.allocateDirect(Header.HEADER_LENGTH);
|
||||
|
||||
private boolean IS_SERVER_RUN; // 서버가 구동중인지 여부
|
||||
private boolean IS_RUN_YN;
|
||||
private long RUN_FLAG_CHECK_TIME;
|
||||
protected long SEND_CYCLE_CHECK_TIME;
|
||||
|
||||
public ReportTask(SelectionKey key, String serviceName, String taskName, LogUtil logger) {
|
||||
this.key = key;
|
||||
this.channel = (SocketChannel) key.channel();
|
||||
this.reportUserDto = (ReportUserDto) key.attachment();
|
||||
this.reportUserDto.setRunningMode(true);
|
||||
this.serviceName = serviceName;
|
||||
this.taskName = taskName;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (this.reportUserDto.isLogin()) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][### Start ### ### ### ### ### ### ###]");
|
||||
} else {
|
||||
saveSystemLog("[" + this.taskName + "][### Start ### ### ### ### ### ### ###]");
|
||||
}
|
||||
|
||||
/* 최초 RUN Flag 체크 */
|
||||
reloadRunFlag();
|
||||
try {
|
||||
while (isRun()) {
|
||||
/* 만료 여부 체크 */
|
||||
if (isExpiredYn) {
|
||||
break;
|
||||
}
|
||||
|
||||
doService();
|
||||
/* RUN Flag 체크 */
|
||||
reloadRunFlag();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.IS_ERROR = true;
|
||||
saveSystemLog(e);
|
||||
}
|
||||
/* 중요 : 사용자 Thread 실행모드 Off */
|
||||
reportUserDto.setRunningMode(false);
|
||||
/* 에러가 발생한 경우 세션을 종료힌다. */
|
||||
if (IS_ERROR) {
|
||||
expireConnectUser();
|
||||
}
|
||||
|
||||
if (this.reportUserDto.isLogin()) {
|
||||
saveSystemLog("[" + this.taskName + "][ID : " + this.reportUserDto.getUserId() + "][### End ### ### ### ### ### ### ###]");
|
||||
} else {
|
||||
saveSystemLog("[" + this.taskName + "][### End ### ### ### ### ### ### ###]");
|
||||
}
|
||||
}
|
||||
|
||||
protected void reloadRunFlag() {
|
||||
if (System.currentTimeMillis() - RUN_FLAG_CHECK_TIME > ServerConfig.INTERVAL_PROPERTY_RELOAD_TIME) {
|
||||
this.IS_RUN_YN = getProp("RUN_FLAG") != null && "Y".equals(getProp("RUN_FLAG"));
|
||||
this.IS_SERVER_RUN = getProp("server", "run") != null && "Y".equals(getProp("server", "run"));
|
||||
RUN_FLAG_CHECK_TIME = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
protected void initHeaderBuffer() {
|
||||
this.headBuffer.clear();
|
||||
for (int loopCnt = 0; loopCnt < Header.HEADER_LENGTH; loopCnt++) {
|
||||
this.headBuffer.put(Packet.SET_DEFAULT_BYTE);
|
||||
}
|
||||
this.headBuffer.position(0);
|
||||
}
|
||||
|
||||
protected int readHeader() throws IOException {
|
||||
initHeaderBuffer();
|
||||
|
||||
return channel.read(headBuffer);
|
||||
}
|
||||
|
||||
protected void expireConnectUser() {
|
||||
if (key == null || !key.isValid()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
saveSystemLog("[" + this.taskName + "][Expire connect user: " + reportUserDto + "]");
|
||||
if (reportUserDto != null) {
|
||||
if (reportUserDto.getUserId() != null) {
|
||||
reportUserQueue.removeUser(reportUserDto.getUserId());
|
||||
}
|
||||
key.attach(null);
|
||||
/* 모니터링 로그 */
|
||||
HealthCheckServer.saveMonitorLog("[REPORT SERVER][ID : " + reportUserDto.getUserId() + "][EXPIRE CONNECT USER]");
|
||||
}
|
||||
/* 세션 만료 여부 */
|
||||
this.isExpiredYn = true;
|
||||
// 소켓 채널 닫기
|
||||
channel.close();
|
||||
// 키 닫기
|
||||
key.cancel();
|
||||
} catch (IOException e) {
|
||||
saveSystemLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isRun() {
|
||||
return IS_SERVER_RUN && IS_RUN_YN;
|
||||
}
|
||||
|
||||
protected String getProp(String name) {
|
||||
return getProp(this.serviceName, name);
|
||||
}
|
||||
|
||||
protected static String getProp(String svc, String name) {
|
||||
return PropertyLoader.getProp(svc, name);
|
||||
}
|
||||
|
||||
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)) + " {{" + this.serviceName + "}} " + obj);
|
||||
}
|
||||
|
||||
if (logger == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log(obj);
|
||||
}
|
||||
|
||||
/* 서비스 */
|
||||
public abstract void doService() throws Exception;
|
||||
}
|
||||
@ -12,6 +12,7 @@ import com.munjaon.server.util.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.Selector;
|
||||
@ -129,7 +130,7 @@ public class SendReadTask implements Runnable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) {
|
||||
public BasicMessageDto recvCommonMessage(ByteBuffer deliverBuffer) throws UnsupportedEncodingException {
|
||||
if (deliverBuffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
|
||||
package com.munjaon.server.util;
|
||||
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* bytes 관련 유틸리티 클래스
|
||||
* @author JDS
|
||||
@ -130,10 +134,10 @@ public final class ByteUtil {
|
||||
return src[offset];
|
||||
}
|
||||
|
||||
public static byte[] getBytes(String data) {
|
||||
public static byte[] getBytes(String data) throws UnsupportedEncodingException {
|
||||
byte[] b = null;
|
||||
|
||||
b = data.getBytes();
|
||||
b = data.getBytes(Packet.AGENT_CHARACTER_SET);
|
||||
|
||||
return (b);
|
||||
}
|
||||
@ -171,8 +175,8 @@ public final class ByteUtil {
|
||||
return dest;
|
||||
}
|
||||
|
||||
public static void setBytes(byte[] dest, int offset, String s) {
|
||||
setBytes(dest, offset, s.getBytes());
|
||||
public static void setBytes(byte[] dest, int offset, String s) throws UnsupportedEncodingException {
|
||||
setBytes(dest, offset, s.getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static byte[] setBytes(byte dest[], int offset, byte src[]) {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.munjaon.server.util;
|
||||
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
@ -69,12 +72,11 @@ public final class CommonUtil {
|
||||
return isValid;
|
||||
}
|
||||
// 해당 길이만큼 문자열을 자르는 함수
|
||||
public static String cutString(String str, int limit)
|
||||
{
|
||||
public static String cutString(String str, int limit) throws UnsupportedEncodingException {
|
||||
int len = str.length();
|
||||
int sumLength=0;
|
||||
String cutString = null;
|
||||
byte[] toByte = str.getBytes();
|
||||
byte[] toByte = str.getBytes(Packet.AGENT_CHARACTER_SET);
|
||||
|
||||
if(limit < 2)
|
||||
return "";
|
||||
|
||||
@ -4,7 +4,9 @@ import com.munjaon.server.config.ServiceCode;
|
||||
import com.munjaon.server.queue.config.*;
|
||||
import com.munjaon.server.queue.dto.BasicMessageDto;
|
||||
import com.munjaon.server.server.dto.ReportDto;
|
||||
import com.munjaon.server.server.packet.common.Packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -100,15 +102,15 @@ public final class MessageUtil {
|
||||
return isEmptyForMessage(obj, false);
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) {
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount, boolean trimFlag) throws UnsupportedEncodingException {
|
||||
if (isEmptyForMessage(obj, trimFlag)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return obj.getBytes().length > limitCount;
|
||||
return obj.getBytes(Packet.AGENT_CHARACTER_SET).length > limitCount;
|
||||
}
|
||||
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount) {
|
||||
public static boolean isOverByteForMessage(String obj, int limitCount) throws UnsupportedEncodingException {
|
||||
return isOverByteForMessage(obj, limitCount, false);
|
||||
}
|
||||
|
||||
@ -120,49 +122,49 @@ public final class MessageUtil {
|
||||
return popCounter < 0 ? QueueHeaderConfig.QUEUE_HEADER_LENGTH : (QueueHeaderConfig.QUEUE_HEADER_LENGTH + popCounter * dataByteLength);
|
||||
}
|
||||
|
||||
public static void setBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void setBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 1. 사용자 아이디 */
|
||||
buffer.position(BodyCommonConfig.USERID_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserId().getBytes());
|
||||
buffer.put(messageDto.getUserId().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 2. 요금제(선불 : P / 후불 : A) */
|
||||
buffer.position(BodyCommonConfig.FEETYPE_BYTE_POSITION);
|
||||
buffer.put(messageDto.getFeeType().getBytes());
|
||||
buffer.put(messageDto.getFeeType().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 3. 단가 */
|
||||
buffer.position(BodyCommonConfig.UNITCOST_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUnitCost().getBytes());
|
||||
buffer.put(messageDto.getUnitCost().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 4. MSG Group ID */
|
||||
buffer.position(BodyCommonConfig.MSGGROUPID_BYTE_POSITION);
|
||||
buffer.put(messageDto.getMsgGroupID().getBytes());
|
||||
buffer.put(messageDto.getMsgGroupID().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 5. MSG ID */
|
||||
buffer.position(BodyCommonConfig.MSGID_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserMsgID().getBytes());
|
||||
buffer.put(messageDto.getUserMsgID().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 6. Service Type */
|
||||
buffer.position(BodyCommonConfig.SERVICETYPE_BYTE_POSITION);
|
||||
buffer.put(messageDto.getServiceType().getBytes());
|
||||
buffer.put(messageDto.getServiceType().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 7. 메시지 전송 결과 >> 성공 : 0 / 필터링 : 기타값 */
|
||||
buffer.position(BodyCommonConfig.SENDSTATUS_BYTE_POSITION);
|
||||
buffer.put(messageDto.getSendStatus().getBytes());
|
||||
buffer.put(messageDto.getSendStatus().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 8. 회신번호 */
|
||||
buffer.position(BodyCommonConfig.SENDER_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserSender().getBytes());
|
||||
buffer.put(messageDto.getUserSender().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 9. 수신번호 */
|
||||
buffer.position(BodyCommonConfig.RECEIVER_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserReceiver().getBytes());
|
||||
buffer.put(messageDto.getUserReceiver().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 10. 예약시간 */
|
||||
buffer.position(BodyCommonConfig.RESERVEDT_BYTE_POSITION);
|
||||
buffer.put(messageDto.getReserveDt().getBytes());
|
||||
buffer.put(messageDto.getReserveDt().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 11. 요청시간 */
|
||||
buffer.position(BodyCommonConfig.REQUESTDT_BYTE_POSITION);
|
||||
buffer.put(messageDto.getRequestDt().getBytes());
|
||||
buffer.put(messageDto.getRequestDt().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 12. 원격 주소 */
|
||||
buffer.position(BodyCommonConfig.REMOTEIP_BYTE_POSITION);
|
||||
buffer.put(messageDto.getRemoteIP().getBytes());
|
||||
buffer.put(messageDto.getRemoteIP().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 13. 발송망 */
|
||||
buffer.position(BodyCommonConfig.AGENT_CODE_BYTE_POSITION);
|
||||
buffer.put(messageDto.getRouterSeq().getBytes());
|
||||
buffer.put(messageDto.getRouterSeq().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static void getBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void getBytesForCommonMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
byte[] destArray = null;
|
||||
if (buffer == null || messageDto == null) {
|
||||
return;
|
||||
@ -242,13 +244,13 @@ public final class MessageUtil {
|
||||
// messageDto.setRouterSeq(new String(destArray));
|
||||
}
|
||||
|
||||
public static void setBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void setBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 14. 메시지 */
|
||||
buffer.position(SmsBodyConfig.SMS_MSG_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserMessage().getBytes());
|
||||
buffer.put(messageDto.getUserMessage().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static void getBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void getBytesForSmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
byte[] destArray = null;
|
||||
if (buffer == null || messageDto == null) {
|
||||
return;
|
||||
@ -261,34 +263,34 @@ public final class MessageUtil {
|
||||
// messageDto.setUserMessage(new String(destArray));
|
||||
}
|
||||
|
||||
public static void setBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void setBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 14. 제목 */
|
||||
buffer.position(MediaBodyConfig.SUBJECT_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserSubject().getBytes());
|
||||
buffer.put(messageDto.getUserSubject().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 15. 메시지 */
|
||||
buffer.position(MediaBodyConfig.MEDIA_MSG_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserMessage().getBytes());
|
||||
buffer.put(messageDto.getUserMessage().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static void setBytesForKakaoMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void setBytesForKakaoMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 14. 제목 */
|
||||
buffer.position(KakaoBodyConfig.SUBJECT_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserSubject().getBytes());
|
||||
buffer.put(messageDto.getUserSubject().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 15. 메시지 */
|
||||
buffer.position(KakaoBodyConfig.MEDIA_MSG_BYTE_POSITION);
|
||||
buffer.put(messageDto.getUserMessage().getBytes());
|
||||
buffer.put(messageDto.getUserMessage().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 16. KAKAO_SENDER_KEY */
|
||||
buffer.position(KakaoBodyConfig.KAKAO_SENDER_KEY_BYTE_POSITION);
|
||||
buffer.put(messageDto.getKakaoSenderKey().getBytes());
|
||||
buffer.put(messageDto.getKakaoSenderKey().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 17. KAKAO_TEMPLATE_CODE */
|
||||
buffer.position(KakaoBodyConfig.KAKAO_TEMPLATE_CODE_BYTE_POSITION);
|
||||
buffer.put(messageDto.getKakaoTemplateCode().getBytes());
|
||||
buffer.put(messageDto.getKakaoTemplateCode().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 18. KAKAO_JSON_FILE */
|
||||
buffer.position(KakaoBodyConfig.FILENAME_JSON_BYTE_POSITION);
|
||||
buffer.put(messageDto.getKakaoJsonFile().getBytes());
|
||||
buffer.put(messageDto.getKakaoJsonFile().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static void getBytesForKakaoMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void getBytesForKakaoMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
byte[] destArray = null;
|
||||
if (buffer == null || messageDto == null) {
|
||||
return;
|
||||
@ -325,7 +327,7 @@ public final class MessageUtil {
|
||||
// messageDto.setUserSubject(new String(destArray));
|
||||
}
|
||||
|
||||
public static void getBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void getBytesForMediaMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
byte[] destArray = null;
|
||||
if (buffer == null || messageDto == null) {
|
||||
return;
|
||||
@ -344,28 +346,28 @@ public final class MessageUtil {
|
||||
// messageDto.setUserMessage(new String(destArray));
|
||||
}
|
||||
|
||||
public static void setBytesForMmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void setBytesForMmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
/* 16. 파일카운트 */
|
||||
buffer.position(MediaBodyConfig.FILECNT_BYTE_POSITION);
|
||||
buffer.put(Integer.toString(messageDto.getUserFileCnt()).getBytes());
|
||||
buffer.put(Integer.toString(messageDto.getUserFileCnt()).getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* 17. 파일명 #1 */
|
||||
buffer.position(MediaBodyConfig.FILENAME_ONE_BYTE_POSITION);
|
||||
if (messageDto.getUserFileName01() != null) {
|
||||
buffer.put(messageDto.getUserFileName01().getBytes());
|
||||
buffer.put(messageDto.getUserFileName01().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* 18. 파일명 #2 */
|
||||
buffer.position(MediaBodyConfig.FILENAME_TWO_BYTE_POSITION);
|
||||
if (messageDto.getUserFileName02() != null) {
|
||||
buffer.put(messageDto.getUserFileName02().getBytes());
|
||||
buffer.put(messageDto.getUserFileName02().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
/* 19. 파일명 #3 */
|
||||
buffer.position(MediaBodyConfig.FILENAME_THREE_BYTE_POSITION);
|
||||
if (messageDto.getUserFileName03() != null) {
|
||||
buffer.put(messageDto.getUserFileName03().getBytes());
|
||||
buffer.put(messageDto.getUserFileName03().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
}
|
||||
|
||||
public static void getBytesForMmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) {
|
||||
public static void getBytesForMmsMessage(ByteBuffer buffer, BasicMessageDto messageDto) throws UnsupportedEncodingException {
|
||||
byte[] destArray = null;
|
||||
if (buffer == null || messageDto == null) {
|
||||
return;
|
||||
@ -443,7 +445,7 @@ public final class MessageUtil {
|
||||
return pushCounter < 0 ? ReportConfig.HEAD_LENGTH : (ReportConfig.HEAD_LENGTH + pushCounter * dataByteLength);
|
||||
}
|
||||
|
||||
public static void setBytesForReport(ByteBuffer buffer, ReportDto reportDto) {
|
||||
public static void setBytesForReport(ByteBuffer buffer, ReportDto reportDto) throws UnsupportedEncodingException {
|
||||
if (buffer == null || reportDto == null) {
|
||||
return;
|
||||
}
|
||||
@ -451,22 +453,22 @@ public final class MessageUtil {
|
||||
byte[] destArray = null;
|
||||
/* MSG_ID (Length : 20 / Position : 0) */
|
||||
buffer.position(ReportConfig.MSG_ID_POSITION);
|
||||
buffer.put(reportDto.getAgentMsgId().getBytes());
|
||||
buffer.put(reportDto.getAgentMsgId().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* AGENT_CODE (Length : 2 / Position : 20) */
|
||||
buffer.position(ReportConfig.AGENT_CODE_POSITION);
|
||||
buffer.put(reportDto.getAgentCode().getBytes());
|
||||
buffer.put(reportDto.getAgentCode().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* SEND_TIME (Length : 14 / Position : 22) */
|
||||
buffer.position(ReportConfig.SEND_TIME_POSITION);
|
||||
buffer.put(reportDto.getRsltDate().getBytes());
|
||||
buffer.put(reportDto.getRsltDate().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* TELECOM (Length : 3 / Position : 36) */
|
||||
buffer.position(ReportConfig.TELECOM_POSITION);
|
||||
buffer.put(reportDto.getRsltNet().getBytes());
|
||||
buffer.put(reportDto.getRsltNet().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
/* RESULT (Length : 5 / Position : 39) */
|
||||
buffer.position(ReportConfig.RESULT_POSITION);
|
||||
buffer.put(reportDto.getRsltCode().getBytes());
|
||||
buffer.put(reportDto.getRsltCode().getBytes(Packet.AGENT_CHARACTER_SET));
|
||||
}
|
||||
|
||||
public static ReportDto getReportFromBuffer(ByteBuffer buffer) {
|
||||
public static ReportDto getReportFromBuffer(ByteBuffer buffer) throws UnsupportedEncodingException {
|
||||
if (buffer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
hikari:
|
||||
server:
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
url: jdbc:mariadb://192.168.0.125:3306/mjon_agent_back
|
||||
jdbc-url: jdbc:mariadb://192.168.0.125:3306/mjon_agent_back
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
hikari:
|
||||
server:
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
url: jdbc:mariadb://localhost:3306/mjon
|
||||
jdbc-url: jdbc:mariadb://localhost:3306/mjon
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
datasource:
|
||||
hikari:
|
||||
server:
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
url: jdbc:mariadb://119.193.215.98:3306/mjon_agent
|
||||
jdbc-url: jdbc:mariadb://119.193.215.98:3306/mjon_agent
|
||||
|
||||
Loading…
Reference in New Issue
Block a user