@@ -21,9 +21,11 @@ public abstract class AbstractProcessSendDeviceState extends AbstractBalancerSta
21
21
private Long qtyMaxResendTansaction ;
22
22
private Device deviceToRemove ;
23
23
private BalancerState waitingLBDeviceRecivedReplyState ;
24
+ private final String overloadedGatewaySource ;
24
25
25
- public AbstractProcessSendDeviceState (Balancer balancer ) {
26
+ public AbstractProcessSendDeviceState (Balancer balancer , String gatewaySource ) {
26
27
super (balancer );
28
+ this .overloadedGatewaySource = gatewaySource ;
27
29
this .qtyMaxResendTansaction = this .balancer .qtyMaxTimeResendTransaction ();
28
30
}
29
31
@@ -35,20 +37,30 @@ public void onEnter() {
35
37
36
38
@ Override
37
39
protected void handleValidTransaction (Transaction transaction ) {
38
- if (transaction == null ){
40
+ if (transaction == null ) {
39
41
logger .warning ("VIXE" );
40
42
return ;
41
43
}
42
- if (!(transaction instanceof TargetedTransaction )){
44
+ if (!(transaction instanceof TargetedTransaction )) {
43
45
logger .log (Level .WARNING , "Transaction {0} recived but is not a targeted transaction" , transaction .getType ());
44
46
return ;
45
47
}
46
- String transTarget = ((TargetedTransaction ) transaction ).getTarget ();
47
- if (!this .source .equals (transTarget )){
48
+ TargetedTransaction targetedTransaction = ((TargetedTransaction ) transaction );
49
+
50
+ String transSource = targetedTransaction .getSource ();
51
+ if (!transSource .equals (this .overloadedGatewaySource )) {
48
52
return ;
49
53
}
50
- logger .info ("LB_*RESPONSE recebido com target correto. Iniciando envio de LB_*REQUEST." );
51
54
55
+ if (!targetedTransaction .isSameTarget (this .source )) {
56
+ logger .log (Level .INFO , "O gateway {1} escolheu outro alvo ({2}). Retornando ao estado Idle." ,
57
+ new Object []{this .overloadedGatewaySource , targetedTransaction .getTarget ()});
58
+
59
+ this .balancer .transitionTo (new IdleState (this .balancer ));
60
+ return ;
61
+ }
62
+ logger .info ("LB_*RESPONSE recebido com target correto. Iniciando envio de LB_*REQUEST." );
63
+
52
64
Transaction transactionRequest ;
53
65
String sender = transaction .getSource ();
54
66
try {
@@ -90,7 +102,7 @@ private void updateQtyResendTransaction() {
90
102
}
91
103
92
104
protected abstract Transaction buildTransaction (String deviceJson , String sender );
93
-
105
+
94
106
protected abstract void handlePostSendTransaction ();
95
107
96
108
}
0 commit comments