com.alibaba.otter.canal.common.zookeeper.ZkClientx Java Examples

The following examples show how to use com.alibaba.otter.canal.common.zookeeper.ZkClientx. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CanalTCPConsumer.java    From canal with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Properties properties, String destination, String groupId) {
    // load config
    String host = properties.getProperty(TCPConstants.CANAL_TCP_HOST);
    String username = properties.getProperty(TCPConstants.CANAL_TCP_USERNAME);
    String password = properties.getProperty(TCPConstants.CANAL_TCP_PASSWORD);
    String zkHosts = properties.getProperty(TCPConstants.CANAL_TCP_ZK_HOSTS);
    String batchSizePro = properties.getProperty(TCPConstants.CANAL_TCP_BATCH_SIZE);
    if (batchSizePro != null) {
        batchSize = Integer.parseInt(batchSizePro);
    }
    if (host != null) {
        String[] ipPort = host.split(":");
        SocketAddress sa = new InetSocketAddress(ipPort[0], Integer.parseInt(ipPort[1]));
        this.canalConnector = new SimpleCanalConnector(sa, username, password, destination);
    } else {
        this.canalConnector = new ClusterCanalConnector(username,
            password,
            destination,
            new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkHosts)));
    }
}
 
Example #2
Source File: CanalInstanceWithManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private synchronized ZkClientx getZkclientx() {
    // 做一下排序,保证相同的机器只使用同一个链接
    List<String> zkClusters = new ArrayList<String>(parameters.getZkClusters());
    Collections.sort(zkClusters);

    return ZkClientx.getZkClient(StringUtils.join(zkClusters, ";"));
}
 
Example #3
Source File: CanalConnectors.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
/**
 * 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描
 *
 * @param zkServers
 * @param destination
 * @param username
 * @param password
 * @return
 */
public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
                                                 String password) {
    ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
        password,
        destination,
        new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
    canalConnector.setSoTimeout(60 * 1000);
    canalConnector.setIdleTimeout(60 * 60 * 1000);
    return canalConnector;
}
 
Example #4
Source File: MixedLogPositionManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public MixedLogPositionManager(ZkClientx zkClient){
    if (zkClient == null) {
        throw new NullPointerException("null zkClient");
    }

    this.memoryLogPositionManager = new MemoryLogPositionManager();
    this.zooKeeperLogPositionManager = new ZooKeeperLogPositionManager(zkClient);

    this.executor = Executors.newFixedThreadPool(1);
}
 
Example #5
Source File: ZooKeeperLogPositionManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public ZooKeeperLogPositionManager(ZkClientx zkClient){
    if (zkClient == null) {
        throw new NullPointerException("null zkClient");
    }

    this.zkClientx = zkClient;
}
 
Example #6
Source File: ZooKeeperLogPositionManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public ZooKeeperLogPositionManager(ZkClientx zkClient){
    if (zkClient == null) {
        throw new NullPointerException("null zkClient");
    }

    this.zkClientx = zkClient;
}
 
Example #7
Source File: MixedLogPositionManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public MixedLogPositionManager(ZkClientx zkClient){
    if (zkClient == null) {
        throw new NullPointerException("null zkClient");
    }

    this.memoryLogPositionManager = new MemoryLogPositionManager();
    this.zooKeeperLogPositionManager = new ZooKeeperLogPositionManager(zkClient);

    this.executor = Executors.newFixedThreadPool(1);
}
 
Example #8
Source File: ClusterNodeConstructInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {

    String clusterPath = ZookeeperPathUtils.getDestinationClusterRoot(allArguments[0].toString());
    ZkClientx zkClientx = ((ClusterNodeAccessStrategy) objInst).getZkClient();
    ContextManager.getRuntimeContext().put("currentAddress", getCurrentAddress(zkClientx.getChildren(clusterPath)));

}
 
Example #9
Source File: CanalInstanceWithManager.java    From canal with Apache License 2.0 5 votes vote down vote up
private synchronized ZkClientx getZkclientx() {
    // 做一下排序,保证相同的机器只使用同一个链接
    List<String> zkClusters = new ArrayList<String>(parameters.getZkClusters());
    Collections.sort(zkClusters);

    return ZkClientx.getZkClient(StringUtils.join(zkClusters, ";"));
}
 
Example #10
Source File: CanalConnectors.java    From canal with Apache License 2.0 5 votes vote down vote up
/**
 * 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描
 *
 * @param zkServers
 * @param destination
 * @param username
 * @param password
 * @return
 */
public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
                                                 String password) {
    ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
        password,
        destination,
        new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
    canalConnector.setSoTimeout(60 * 1000);
    canalConnector.setIdleTimeout(60 * 60 * 1000);
    return canalConnector;
}
 
Example #11
Source File: CanalController.java    From canal with Apache License 2.0 4 votes vote down vote up
public void stop() throws Throwable {

        if (canalServer != null) {
            canalServer.stop();
        }

        if (autoScan) {
            for (InstanceConfigMonitor monitor : instanceConfigMonitors.values()) {
                if (monitor.isStart()) {
                    monitor.stop();
                }
            }
        }

        for (ServerRunningMonitor runningMonitor : ServerRunningMonitors.getRunningMonitors().values()) {
            if (runningMonitor.isStart()) {
                runningMonitor.stop();
            }
        }

        // 释放canal的工作节点
        releaseCid(ZookeeperPathUtils.getCanalClusterNode(registerIp + ":" + port));
        logger.info("## stop the canal server[{}({}):{}]", ip, registerIp, port);

        if (zkclientx != null) {
            zkclientx.close();
        }

        // 关闭时清理缓存
        if (instanceConfigs != null) {
            instanceConfigs.clear();
        }
        if (managerClients != null) {
            managerClients.clear();
        }
        if (instanceConfigMonitors != null) {
            instanceConfigMonitors.clear();
        }

        ZkClientx.clearClients();
    }
 
Example #12
Source File: ZooKeeperMetaManager.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setZkClientx(ZkClientx zkClientx) {
    this.zkClientx = zkClientx;
}
 
Example #13
Source File: ServerRunningMonitor.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #14
Source File: ClusterNodeAccessStrategy.java    From canal with Apache License 2.0 4 votes vote down vote up
public ZkClientx getZkClient() {
    return zkClient;
}
 
Example #15
Source File: ClusterNodeAccessStrategy.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #16
Source File: ClientRunningMonitor.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #17
Source File: SimpleCanalConnector.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setZkClientx(ZkClientx zkClientx) {
    this.zkClientx = zkClientx;
    initClientRunningMonitor(this.clientIdentity);
}
 
Example #18
Source File: ZooKeeperMetaManager.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setZkClientx(ZkClientx zkClientx) {
    this.zkClientx = zkClientx;
}
 
Example #19
Source File: CanalController.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void stop() throws Throwable {

        if (canalServer != null) {
            canalServer.stop();
        }

        if (autoScan) {
            for (InstanceConfigMonitor monitor : instanceConfigMonitors.values()) {
                if (monitor.isStart()) {
                    monitor.stop();
                }
            }
        }

        for (ServerRunningMonitor runningMonitor : ServerRunningMonitors.getRunningMonitors().values()) {
            if (runningMonitor.isStart()) {
                runningMonitor.stop();
            }
        }

        // 释放canal的工作节点
        releaseCid(ZookeeperPathUtils.getCanalClusterNode(ip + ":" + port));
        logger.info("## stop the canal server[{}:{}]", ip, port);

        if (zkclientx != null) {
            zkclientx.close();
        }

        //关闭时清理缓存
        if (instanceConfigs != null) {
            instanceConfigs.clear();
        }
        if (managerClients != null) {
            managerClients.clear();
        }
        if (instanceConfigMonitors != null) {
            instanceConfigMonitors.clear();
        }

        ZkClientx.clearClients();
    }
 
Example #20
Source File: ServerRunningMonitor.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #21
Source File: ClusterNodeAccessStrategy.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public ZkClientx getZkClient() {
    return zkClient;
}
 
Example #22
Source File: ClusterNodeAccessStrategy.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #23
Source File: ClientRunningMonitor.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setZkClient(ZkClientx zkClient) {
    this.zkClient = zkClient;
}
 
Example #24
Source File: SimpleCanalConnector.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setZkClientx(ZkClientx zkClientx) {
    this.zkClientx = zkClientx;
    initClientRunningMonitor(this.clientIdentity);
}