コード例 #1
0
  /**
   * Gets the transport addresses.
   *
   * @return the transport addresses
   */
  protected List<TransportAddress> getTransportAddresses() {
    List<TransportAddress> addresses = Lists.newArrayList();
    if (!registrationRebirthService.isZkJarLib()) {
      return addresses;
    }
    List<String> childNode =
        ZooKeeperExpand.getInstance().list(SearchConstants.getRebirthSearchBulidZKConfig());
    if (childNode != null) {
      regirtListener(childNode, addresses);
    }
    ZooKeeperExpand.getInstance()
        .getZkClient()
        .subscribeChildChanges(
            SearchConstants.getRebirthSearchBulidZKConfig(),
            new IZkChildListener() {

              @Override
              public void handleChildChange(String parentPath, List<String> currentChilds)
                  throws Exception {
                List<TransportAddress> addresses = Lists.newArrayList();
                regirtListener(currentChilds, addresses);
                if (!addresses.isEmpty()) {
                  TransportClient transportClient = beanFactory.getBean(TransportClient.class);
                  ImmutableList<TransportAddress> immutableList =
                      transportClient.transportAddresses();
                  for (TransportAddress transportAddress : addresses) {
                    if (!immutableList.contains(transportAddress))
                      transportClient.addTransportAddress(transportAddress);
                  }
                }
              }
            });
    return addresses;
  }
コード例 #2
0
 /**
  * Regirt listener.
  *
  * @param childNode the child node
  * @param addresses the addresses
  */
 private void regirtListener(List<String> childNode, List<TransportAddress> addresses) {
   for (String node : childNode) {
     Object object =
         ZooKeeperExpand.getInstance()
             .get(SearchConstants.getRebirthSearchBulidZKConfig() + "/" + node);
     if (object instanceof TransportAddress) {
       final TransportAddress address = (TransportAddress) object;
       if (addresses != null) addresses.add(address);
       ZooKeeperExpand.getInstance()
           .getZkClient()
           .subscribeDataChanges(
               SearchConstants.getRebirthSearchBulidZKConfig() + "/" + node,
               new NodeDataListener(beanFactory, address));
     }
   }
 }