コード例 #1
0
  public void connect() throws CanalClientException {
    while (currentConnector == null) {
      SocketAddress nextAddress = this.accessStrategy.nextNode();

      int times = 0;
      /** retry for #retryTimes for each node when trying to connect to it. */
      while (times < retryTimes) {
        try {
          currentConnector = new SimpleCanalConnector(nextAddress, username, password, destination);
          currentConnector.setSoTimeout(soTimeout);
          if (accessStrategy instanceof ClusterNodeAccessStrategy) {
            currentConnector.setZkClientx(
                ((ClusterNodeAccessStrategy) accessStrategy).getZkClient());
          }

          currentConnector.connect();
          break;
        } catch (Exception e) {
          logger.warn("failed to connect to:{} after retry {} times", nextAddress, times);
          currentConnector.disconnect();
          currentConnector = null;
          times = times + 1;
        }
      }
    }
  }
コード例 #2
0
 public void unsubscribe() throws CanalClientException {
   int times = 0;
   while (times < retryTimes) {
     try {
       currentConnector.unsubscribe();
       return;
     } catch (Throwable t) {
       logger.warn(
           "something goes wrong when unsubscribing from server:{}\n{}",
           currentConnector.getAddress(),
           t);
       times++;
       restart();
       logger.info("restart the connector for next round retry.");
     }
   }
   throw new CanalClientException("failed to unsubscribe after " + times + " times retry.");
 }
コード例 #3
0
 public void rollback(long batchId) throws CanalClientException {
   int times = 0;
   while (times < retryTimes) {
     try {
       currentConnector.rollback(batchId);
       return;
     } catch (Throwable t) {
       logger.warn(
           "something goes wrong when rollbacking data from server:{}\n{}",
           currentConnector.getAddress(),
           t);
       times++;
       restart();
       logger.info("restart the connector for next round retry.");
     }
   }
   throw new CanalClientException("failed to fetch the data after " + times + " times retry");
 }
コード例 #4
0
 public Message getWithoutAck(int batchSize) throws CanalClientException {
   int times = 0;
   while (times < retryTimes) {
     try {
       Message msg = currentConnector.getWithoutAck(batchSize);
       return msg;
     } catch (Throwable t) {
       logger.warn(
           "something goes wrong when getWithoutAck data from server:{}\n{}",
           currentConnector.getAddress(),
           t);
       times++;
       restart();
       logger.info("restart the connector for next round retry.");
     }
   }
   throw new CanalClientException("failed to fetch the data after " + times + " times retry");
 }
コード例 #5
0
 public void disconnect() throws CanalClientException {
   if (currentConnector != null) {
     currentConnector.disconnect();
     currentConnector = null;
   }
 }
コード例 #6
0
 public boolean checkValid() {
   return currentConnector != null && currentConnector.checkValid();
 }