com.codingapi.tx.netty.service.impl.NettyDistributeServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tx-client Show documentation
Show all versions of tx-client Show documentation
tx-client project for Spring Boot
package com.codingapi.tx.netty.service.impl;
import com.codingapi.tx.Constants;
import com.codingapi.tx.model.TxServer;
import com.codingapi.tx.netty.service.MQTxManagerService;
import com.codingapi.tx.netty.service.NettyDistributeService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by lorne on 2017/6/30.
*/
@Service
public class NettyDistributeServiceImpl implements NettyDistributeService {
private int connectCont = 0;
private Logger logger = LoggerFactory.getLogger(NettyDistributeServiceImpl.class);
@Autowired
private MQTxManagerService txManagerService;
@Override
public synchronized void loadTxServer() {
if (Constants.txServer == null) {
getTxServer();
return;
}
connectCont++;
if (connectCont == 3) {
getTxServer();
}
}
private void getTxServer() {
//获取负载均衡服务地址
String json = null;
while (StringUtils.isEmpty(json)) {
json = txManagerService.httpGetServer();
logger.info("获取manager服务信息->" + json);
if (StringUtils.isEmpty(json)) {
logger.info("TxManager服务器无法访问.");
try {
Thread.sleep(1000 * 2);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
TxServer txServer = TxServer.parser(json);
if (txServer != null) {
logger.info("txServer -> " + txServer);
logger.info(txServer.toString());
Constants.txServer = txServer;
logger.info(Constants.txServer.toString());
connectCont = 0;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy