提交 a254c1b0 编写于 作者: W whomhim

fix( #506 ): 修复只连上一个 TM 节点时,还负载均衡的问题

上级 faeebb5f
......@@ -31,10 +31,6 @@ public abstract class AbsMessage implements Message {
*/
protected Boolean isReadyCallBack = false;
protected Connection tcConnection;
protected String firstConnectionKey;
protected String messageId;
protected String firstMessageId;
......
......@@ -15,7 +15,7 @@ import org.springframework.context.ApplicationContext;
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class TransactionMessage extends AbsMessage {
public class TransactionMessage extends AbsMessage {
protected String groupId;
......
......@@ -17,7 +17,7 @@ import java.util.Map;
public class ConnectionService {
// server name -> connection
private final Map<String, Connection> connections = new HashMap<String, Connection>();
private final Map<String, Connection> connections = new HashMap<>();
public void addConnection(final Connection connection) {
final String uniqueKey = connection.getUniqueKey();
......
......@@ -36,4 +36,11 @@ public interface EventStatus {
* @param firstConnectionKeyTmp 暂时保存 ConnectionUniKey
*/
void onReadyCallBack(AbsMessage absMessage, Protocoler protocoler, String firstConnectionKeyTmp);
/**
* TM 节点只连接了一个 TC 时
*
* @param event EventService
*/
void onOneConnection(EventService event) throws Exception;
}
......@@ -58,6 +58,12 @@ public class EventStatusHandler implements EventStatus {
}
}
@Override
public void onOneConnection(EventService event) throws Exception {
log.debug("EventStatusHandler.onOneConnection");
event.execute();
}
/**
* 判断 AbsMessage 是来自哪个事件的,并 new 一个该事件
*
......
......@@ -43,9 +43,14 @@ public class LoadBalancerInterceptor implements EventInterceptor {
throws Exception {
String firstConnectionKeyTmp = connection.getUniqueKey();
String firstMessageIdTmp = absMessage.getMessageId();
eventStatus.onFirstNode(absMessage, firstMessageIdTmp, connection);
eventStatus.onBusinessExecuted(absMessage, event);
eventStatus.onReadyCallBack(absMessage, protocoler, firstConnectionKeyTmp);
if (protocoler.getConnections().size() == 1) {
eventStatus.onOneConnection(event);
} else {
eventStatus.onFirstNode(absMessage, firstMessageIdTmp, connection);
eventStatus.onBusinessExecuted(absMessage, event);
eventStatus.onReadyCallBack(absMessage, protocoler, firstConnectionKeyTmp);
}
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册