|
@@ -15,7 +15,6 @@ import com.alibaba.otter.canal.common.utils.JsonUtils;
|
|
|
import com.alibaba.otter.canal.common.zookeeper.ZkClientx;
|
|
|
import com.alibaba.otter.canal.common.zookeeper.ZookeeperPathUtils;
|
|
|
import com.alibaba.otter.canal.common.zookeeper.running.ServerRunningData;
|
|
|
-import com.alibaba.otter.canal.protocol.exception.CanalClientException;
|
|
|
|
|
|
/**
|
|
|
* 集群模式的调度策略
|
|
@@ -25,6 +24,7 @@ import com.alibaba.otter.canal.protocol.exception.CanalClientException;
|
|
|
*/
|
|
|
public class ClusterNodeAccessStrategy implements CanalNodeAccessStrategy {
|
|
|
|
|
|
+ private String destination;
|
|
|
private IZkChildListener childListener; // 监听所有的服务器列表
|
|
|
private IZkDataListener dataListener; // 监听当前的工作节点
|
|
|
private ZkClientx zkClient;
|
|
@@ -32,6 +32,7 @@ public class ClusterNodeAccessStrategy implements CanalNodeAccessStrategy {
|
|
|
private volatile InetSocketAddress runningAddress = null;
|
|
|
|
|
|
public ClusterNodeAccessStrategy(String destination, ZkClientx zkClient){
|
|
|
+ this.destination = destination;
|
|
|
this.zkClient = zkClient;
|
|
|
childListener = new IZkChildListener() {
|
|
|
|
|
@@ -73,7 +74,7 @@ public class ClusterNodeAccessStrategy implements CanalNodeAccessStrategy {
|
|
|
} else if (!currentAddress.isEmpty()) { // 如果不存在已经启动的服务,可能服务是一种lazy启动,随机选择一台触发服务器进行启动
|
|
|
return currentAddress.get(0);// 默认返回第一个节点,之前已经做过shuffle
|
|
|
} else {
|
|
|
- throw new CanalClientException("no alive canal server");
|
|
|
+ throw new ServerNotFoundException("no alive canal server for " + destination);
|
|
|
}
|
|
|
}
|
|
|
|