주석추가, config loader trim 추가
This commit is contained in:
parent
4be1ae4130
commit
7fa49f3f29
@ -11,7 +11,6 @@ import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -27,7 +26,6 @@ import javax.sql.DataSource;
|
||||
@EnableTransactionManagement
|
||||
@MapperScan(basePackages= "com.munjaon.client.**.mapper")
|
||||
public class DataSourceConfig {
|
||||
//public class DataSourceConfig implements BeanDefinitionRegistryPostProcessor {
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private final ServerConfig serverConfig;
|
||||
@ -56,22 +54,6 @@ public class DataSourceConfig {
|
||||
return new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
// @Primary
|
||||
// @Bean(name = "datasource")
|
||||
// public DataSource dataSource() throws ConfigurationException {
|
||||
// String dbms = serverConfig.getString("DB.DBMS");
|
||||
// System.out.println("MARIADB.DRIVER : " + serverConfig.getString(dbms + ".DRIVER"));
|
||||
// System.out.println("MARIADB.URL : " + serverConfig.getString(dbms + ".URL"));
|
||||
// System.out.println("MARIADB.USER : " + serverConfig.getString(dbms + ".USER"));
|
||||
// System.out.println("MARIADB.PASSWORD : " + serverConfig.getString(dbms + ".PASSWORD"));
|
||||
// return DataSourceBuilder.create().type(HikariDataSource.class)
|
||||
// .driverClassName(serverConfig.getString(dbms + ".DRIVER"))
|
||||
// .url(serverConfig.getString(dbms + ".URL"))
|
||||
// .username(serverConfig.getString(dbms + ".USER"))
|
||||
// .password(serverConfig.getString(dbms + ".PASSWORD"))
|
||||
// .build();
|
||||
// }
|
||||
|
||||
@Primary
|
||||
@Bean(name = "factory")
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
||||
@ -83,7 +65,6 @@ public class DataSourceConfig {
|
||||
sqlSessionFactory.setTypeAliasesPackage("com.munjaon.client.**.dto");
|
||||
sqlSessionFactory.setConfigLocation(applicationContext.getResource("classpath:mybatis-config.xml"));
|
||||
sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/sqlmap/**/*.xml"));
|
||||
// sqlSessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/sqlmap/" + dbms.toLowerCase() + "/*.xml"));
|
||||
return sqlSessionFactory.getObject();
|
||||
}
|
||||
|
||||
@ -92,22 +73,4 @@ public class DataSourceConfig {
|
||||
public SqlSessionTemplate sqlSession(SqlSessionFactory sqlSessionFactory) {
|
||||
return new SqlSessionTemplate(sqlSessionFactory);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
// String dbms = null;
|
||||
// try {
|
||||
// dbms = serverConfig.getString("DB.DBMS");
|
||||
// } catch (ConfigurationException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// AbstractBeanDefinition mapperScannerConfigurer = BeanDefinitionBuilder
|
||||
// .genericBeanDefinition(MapperScannerConfigurer.class)
|
||||
// .addPropertyValue("sqlSessionFactoryBeanName", "factory")
|
||||
// .addPropertyValue("basePackage", "com.munjaon.client.**.dto")
|
||||
// .addPropertyValue("annotationClass", MapperType.value(dbms).getClass())
|
||||
// .getBeanDefinition();
|
||||
//
|
||||
// registry.registerBeanDefinition("MapperScanner", mapperScannerConfigurer);
|
||||
// }
|
||||
}
|
||||
|
||||
@ -12,12 +12,21 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* RunnerConfiguration
|
||||
* Agent Service 실행
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class RunnerConfiguration {
|
||||
private final ServerConfig serverConfig;
|
||||
|
||||
/**
|
||||
* 설정파일 로드
|
||||
* @return
|
||||
* @throws ConfigurationException
|
||||
*/
|
||||
@Bean
|
||||
@Order(1)
|
||||
public CommandLineRunner getRunnerBeanForProperty() throws ConfigurationException {
|
||||
@ -26,9 +35,13 @@ public class RunnerConfiguration {
|
||||
System.setProperty("DBMS", serverConfig.getString("DB.DBMS"));
|
||||
PropertyLoader.load();
|
||||
|
||||
return args -> System.out.println("Runner Bean #1 : " + serverConfig.getServerProperyFile());
|
||||
return args -> System.out.println("MunjaonAgent Config Property : " + serverConfig.getServerProperyFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* SMS 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForSms() {
|
||||
@ -41,9 +54,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("SMS Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* LMS 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForLms() {
|
||||
@ -56,9 +73,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("LMS Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* MMS 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForMms() {
|
||||
@ -71,9 +92,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("MMS Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* 카카오 알림톡 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForKat() {
|
||||
@ -86,9 +111,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("KAT Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* 카카오 친구톡 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForKft() {
|
||||
@ -101,9 +130,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("KFT Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* 리포트 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(2)
|
||||
public CommandLineRunner getRunnerBeanForReport() {
|
||||
@ -115,9 +148,13 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("REPORT Service Started");
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그이동 서비스 실행
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(3)
|
||||
public CommandLineRunner getRunnerBeanForMove() {
|
||||
@ -129,6 +166,6 @@ public class RunnerConfiguration {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return args -> System.out.println("Runner Bean #2");
|
||||
return args -> System.out.println("LOG MOVE Service Started");
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit;
|
||||
@Component
|
||||
public class ServerConfig {
|
||||
@Getter
|
||||
// @Value("${agent.server-property-file}")
|
||||
private String serverProperyFile;
|
||||
|
||||
@Getter
|
||||
@ -32,7 +31,6 @@ public class ServerConfig {
|
||||
|
||||
@PostConstruct
|
||||
void init() throws ConfigurationException {
|
||||
// this.serverRootPath = System.getProperty("SERVICE_HOME");
|
||||
this.serverProperyFile = serverRootPath + File.separator + "config" + File.separator + "munjaonAgent.conf";
|
||||
builder = new ReloadingFileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(new Parameters().fileBased().setFile(new File(serverProperyFile)));
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package com.munjaon.client.server.packet;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Bind {
|
||||
public static final int BIND_BODY_LENGTH = 41;
|
||||
|
||||
@ -17,16 +17,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CollectClientService extends Service {
|
||||
/* 서비스 타입
|
||||
* RunnerConfiguration에서 서비스 타입 지정
|
||||
* SMS, LMS, MMS, KAT, KFT
|
||||
* */
|
||||
private final String serviceType;
|
||||
private DatabaseTypeWorker worker;
|
||||
private SocketChannel socketChannel;
|
||||
private long lastPacketSendTime = 0;
|
||||
private String address;
|
||||
private int port;
|
||||
private String id;
|
||||
private String pwd;
|
||||
private DatabaseTypeWorker worker; // 서비스 타입별 DAO 호출
|
||||
private SocketChannel socketChannel; // 클라이언트 SocketChannel
|
||||
private long lastPacketSendTime = 0; // 마지막 패킷을 전송 및 응답 시간
|
||||
private String address; // 서비스별 서버 주소
|
||||
private int port; // 서비스별 포트 정보
|
||||
private String id; // 접속 아이디
|
||||
private String pwd; // 접속 비밀번호
|
||||
|
||||
private StringBuilder deliverBuilder;
|
||||
private List<String> deliverList = null;
|
||||
|
||||
public CollectClientService(String serviceName, String serviceType) {
|
||||
@ -187,7 +190,6 @@ public class CollectClientService extends Service {
|
||||
|
||||
private void messageService() {
|
||||
List<MunjaonMsg> list = selectToDeliver();
|
||||
this.deliverBuilder = new StringBuilder();
|
||||
if (list == null || list.isEmpty()) {
|
||||
try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}
|
||||
return;
|
||||
|
||||
@ -33,7 +33,7 @@ public class PropertyLoader extends Thread {
|
||||
value = value.replaceAll("\\$SERVICE_HOME", System.getProperty("SERVICE_HOME"));
|
||||
}
|
||||
|
||||
return value;
|
||||
return value == null ? null : value.trim();
|
||||
}
|
||||
|
||||
public synchronized static Properties load() {
|
||||
|
||||
@ -4,12 +4,10 @@ import com.munjaon.client.server.config.ServerConfig;
|
||||
import com.munjaon.client.util.LogUtil;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public abstract class Service extends Thread {
|
||||
public static final SimpleDateFormat sdf = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||
public static final String LOG_DATE_FORMAT = "[MM-dd HH:mm:ss]";
|
||||
|
||||
private String LOG_FILE;
|
||||
@ -17,9 +15,9 @@ public abstract class Service extends Thread {
|
||||
private Long LAST_PROPERTY_LOAD_TIME = 0L;
|
||||
|
||||
protected boolean IS_SERVER_RUN; // 서버가 구동중인지 여부
|
||||
protected boolean IS_READY_YN; // 서비스 구동준비가 완료되었는지 체크
|
||||
protected boolean IS_RUN_YN;
|
||||
protected boolean IS_STOP_YN;
|
||||
protected boolean IS_READY_YN; // 서비스 구동준비가 완료되었는지 체크
|
||||
protected boolean IS_RUN_YN; // 서비스 실행여부
|
||||
protected boolean IS_STOP_YN; // 서비스 Stop여부
|
||||
|
||||
public Service() {}
|
||||
public Service(String serviceName) {
|
||||
@ -27,22 +25,42 @@ public abstract class Service extends Thread {
|
||||
LOG_FILE = System.getProperty("ROOTPATH") + getProp("LOG_FILE");
|
||||
}
|
||||
|
||||
/**
|
||||
* config property load
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
protected String getProp(String name) {
|
||||
return getProp(getName(), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* config property load
|
||||
* @param svc
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static String getProp(String svc, String name) {
|
||||
return PropertyLoader.getProp(svc, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스 실행 여부 config property 조회
|
||||
*/
|
||||
protected void checkRun() {
|
||||
this.IS_RUN_YN = getProp("RUN_FLAG") != null && "Y".equals(getProp("RUN_FLAG"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 클라이언트 실행여부 config property 조회
|
||||
*/
|
||||
protected void checkClientRun() {
|
||||
this.IS_SERVER_RUN = getProp("client", "run") != null && "Y".equals(getProp("client", "run"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스 및 클라이언트 실행여부 조회
|
||||
*/
|
||||
public void reloadCheckRun() {
|
||||
if ((System.currentTimeMillis() - this.LAST_PROPERTY_LOAD_TIME) > ServerConfig.INTERVAL_PROPERTY_RELOAD_TIME) {
|
||||
checkRun();
|
||||
@ -51,14 +69,26 @@ public abstract class Service extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스 실행 조건 조회
|
||||
* @return
|
||||
*/
|
||||
public boolean isRun() {
|
||||
return IS_SERVER_RUN && IS_RUN_YN && !IS_STOP_YN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스가 실행준비가 되었는지 조회
|
||||
* @return
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return IS_READY_YN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스별 로그파일 초기화
|
||||
* @param sLogFile
|
||||
*/
|
||||
protected void setLogFile(String sLogFile) {
|
||||
if ( logger != null ) {
|
||||
logger.close();
|
||||
@ -68,14 +98,27 @@ public abstract class Service extends Thread {
|
||||
logger = new LogUtil( sLogFile );
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행로그 화면 출력 및 저장
|
||||
* @param obj
|
||||
*/
|
||||
protected void saveSystemLog(Object obj) {
|
||||
saveLog(obj, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행로그 저장
|
||||
* @param obj
|
||||
*/
|
||||
protected void saveLog(Object obj) {
|
||||
saveLog(obj, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실행로그 저장
|
||||
* @param obj
|
||||
* @param isConsoleOutput
|
||||
*/
|
||||
protected void saveLog(Object obj, boolean isConsoleOutput) {
|
||||
if(isConsoleOutput) {
|
||||
System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern(LOG_DATE_FORMAT)) + " {{"+ getName() +"}} "+obj);
|
||||
@ -91,6 +134,9 @@ public abstract class Service extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그파일 초기화
|
||||
*/
|
||||
protected void initLogFile() {
|
||||
LOG_FILE = System.getProperty("ROOTPATH") + getProp("LOG_FILE");
|
||||
System.out.println("LOG_FILE: " + LOG_FILE);
|
||||
@ -98,6 +144,9 @@ public abstract class Service extends Thread {
|
||||
saveSystemLog("Service Log Initializing ... ...");
|
||||
}
|
||||
|
||||
/**
|
||||
* 서비스 실행
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user