|
@@ -1,5 +1,6 @@
|
|
|
package com.its.common.cluster.service;
|
|
package com.its.common.cluster.service;
|
|
|
|
|
|
|
|
|
|
+import com.its.common.cluster.config.AbstractClusterConfig;
|
|
|
import com.its.common.cluster.vo.*;
|
|
import com.its.common.cluster.vo.*;
|
|
|
import com.its.common.cluster.utils.ClusterUtils;
|
|
import com.its.common.cluster.utils.ClusterUtils;
|
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.Channel;
|
|
@@ -47,6 +48,7 @@ public abstract class AbstractClusterSlaveService {
|
|
|
for (Map.Entry<Integer, ClusterNode> entry : this.clusterConfig.getClusterMap().entrySet()) {
|
|
for (Map.Entry<Integer, ClusterNode> entry : this.clusterConfig.getClusterMap().entrySet()) {
|
|
|
ClusterNode cluster = entry.getValue();
|
|
ClusterNode cluster = entry.getValue();
|
|
|
if (cluster.getId() == this.clusterConfig.getId()) {
|
|
if (cluster.getId() == this.clusterConfig.getId()) {
|
|
|
|
|
+ // 자기 자신은 접속하지 않도록 한다. 즉 타 클러스터 서버에 접속한다.
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
ClusterSlave slaveClient = new ClusterSlave(this, clusterConfig, cluster, this.bootstrapFactory);
|
|
ClusterSlave slaveClient = new ClusterSlave(this, clusterConfig, cluster, this.bootstrapFactory);
|
|
@@ -102,6 +104,7 @@ public abstract class AbstractClusterSlaveService {
|
|
|
log.error("ClusterSlaveService.channelClose");
|
|
log.error("ClusterSlaveService.channelClose");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
private String getSysTime() {
|
|
private String getSysTime() {
|
|
|
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
Date dtLog = new Date();
|
|
Date dtLog = new Date();
|
|
@@ -115,18 +118,18 @@ public abstract class AbstractClusterSlaveService {
|
|
|
return ClusterMessage.builder()
|
|
return ClusterMessage.builder()
|
|
|
.clusterId(this.clusterConfig.getId())
|
|
.clusterId(this.clusterConfig.getId())
|
|
|
.master(this.clusterConfig.isMaster())
|
|
.master(this.clusterConfig.isMaster())
|
|
|
- .serverTime(getSysTime())
|
|
|
|
|
|
|
+ .currentTimeMillis(System.currentTimeMillis())
|
|
|
.infos(details)
|
|
.infos(details)
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 스케쥴 주기 이외에 클러스터 메시지를 즉시 전송하기 위한 인터페이스 함수
|
|
// 스케쥴 주기 이외에 클러스터 메시지를 즉시 전송하기 위한 인터페이스 함수
|
|
|
- public void notifyClusterMessage() {
|
|
|
|
|
- if (this.clusterConfig.isLogging()) {
|
|
|
|
|
- log.info("ClusterSlaveService:notifyClusterMessage:---");
|
|
|
|
|
- }
|
|
|
|
|
- dataSyncSchedule();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// public void notifyClusterMessage() {
|
|
|
|
|
+// if (this.clusterConfig.isLogging()) {
|
|
|
|
|
+// log.info("ClusterSlaveService:notifyClusterMessage:---");
|
|
|
|
|
+// }
|
|
|
|
|
+// dataSyncSchedule();
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
private synchronized void dataSyncSchedule() {
|
|
private synchronized void dataSyncSchedule() {
|
|
|
if (this.clusterConfig.isLogging()) {
|
|
if (this.clusterConfig.isLogging()) {
|
|
@@ -136,15 +139,14 @@ public abstract class AbstractClusterSlaveService {
|
|
|
for (Map.Entry<Integer, ClusterNode> entry : this.clusterConfig.getClusterMap().entrySet()) {
|
|
for (Map.Entry<Integer, ClusterNode> entry : this.clusterConfig.getClusterMap().entrySet()) {
|
|
|
ClusterNode cluster = entry.getValue();
|
|
ClusterNode cluster = entry.getValue();
|
|
|
if (cluster.getId() == this.clusterConfig.getId()) {
|
|
if (cluster.getId() == this.clusterConfig.getId()) {
|
|
|
|
|
+ // 자기 자신은 전송하지 않음.
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if (cluster.getSyncState().getState() != ClusterNET.CLOSED) {
|
|
if (cluster.getSyncState().getState() != ClusterNET.CLOSED) {
|
|
|
sendSyncData(cluster, cluster.getSyncState().getChannel());
|
|
sendSyncData(cluster, cluster.getSyncState().getChannel());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}, this.clusterConfig.getSyncSeconds() * 1000L);
|
|
}, this.clusterConfig.getSyncSeconds() * 1000L);
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void sendSyncData(final ClusterNode cluster, final Channel channel) {
|
|
public void sendSyncData(final ClusterNode cluster, final Channel channel) {
|
|
@@ -158,17 +160,19 @@ public abstract class AbstractClusterSlaveService {
|
|
|
ChannelFuture f = channel.writeAndFlush(clusterMsg);
|
|
ChannelFuture f = channel.writeAndFlush(clusterMsg);
|
|
|
f.awaitUninterruptibly();
|
|
f.awaitUninterruptibly();
|
|
|
if (f.isDone() || f.isSuccess()) {
|
|
if (f.isDone() || f.isSuccess()) {
|
|
|
|
|
+ cluster.getSyncState().setLastSendTime(); // 데이터 정송 시각 설정
|
|
|
|
|
+
|
|
|
if (this.clusterConfig.isLogging()) {
|
|
if (this.clusterConfig.isLogging()) {
|
|
|
log.info("ClusterSlaveService.sendSyncData: [{}], {}, [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
|
|
log.info("ClusterSlaveService.sendSyncData: [{}], {}, [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
|
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
|
|
|
- cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getServerTime());
|
|
|
|
|
|
|
+ cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getCurrentTimeMillis());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
catch (Exception e) {
|
|
catch (Exception e) {
|
|
|
log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
|
|
log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: [--TO: clusterId: {}, (clusterId: {}, serverTime: {})]",
|
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel),
|
|
|
- cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getServerTime());
|
|
|
|
|
|
|
+ cluster.getId(), clusterMsg.getClusterId(), clusterMsg.getCurrentTimeMillis());
|
|
|
log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: {}",
|
|
log.error("ClusterSlaveService.sendSyncData: [{}], {}, Failed: {}",
|
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel), e.getMessage());
|
|
this.clusterConfig.getId(), ClusterUtils.getTcpAddress(channel), e.getMessage());
|
|
|
}
|
|
}
|