/** * 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; }
/* (non-Javadoc) * @see cn.com.rebirth.search.client.RegistrationRebirthService.BeanDefinitonCallbak#execute(java.lang.String) */ @Override public BeanDefinition execute(String beanName) { registrationRebirthService.clientBeanName = beanName; return BeanDefinitionBuilder.rootBeanDefinition(RebirthTransportClientFactoryBean.class) .addPropertyValue("addresses", getTransportAddresses()) .getBeanDefinition(); }