Skip to content

Commit

Permalink
If applied, this commit will update hornet reachable verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
UellingtonDamasceno committed Nov 22, 2024
1 parent e97555f commit 3bd1156
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/java/dlt/load/balancer/model/Balancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;

import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Timer;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class Balancer implements ILedgerSubscriber, Runnable {
private boolean flagSubscribe;
private static final Logger logger = Logger.getLogger(Balancer.class.getName());
private boolean balanceable, multiLayerBalancing;
private String realMqttPort;

ExecutorService executorTimeout = Executors.newSingleThreadExecutor();

Expand Down Expand Up @@ -148,7 +150,9 @@ public void setSubscribedTopics(String topicsJSON) {
.stream()
.filter(String.class::isInstance)
.map(String.class::cast)
.collect(toList());
.peek(s -> {
logger.log(Level.INFO, "Load balancer - Subscribe at {0}", s);
}).collect(toList());
}

public void start() {
Expand All @@ -157,6 +161,8 @@ public void start() {
logger.log(Level.INFO, "IS BALANCEABLE: {0}", this.balanceable);
this.multiLayerBalancing = this.isMultiLayerBalancing();
logger.log(Level.INFO, "IS MULTI LAYER BALANCING: {0}", this.multiLayerBalancing);
this.realMqttPort = this.currentMqttPort();
logger.log(Level.INFO, "Real MQTT PORT: {0}", this.realMqttPort);
}

public void stop() {
Expand Down Expand Up @@ -547,6 +553,7 @@ public void stopTimeout() {
public void update(Object trans, Object messageId) {

if(!this.balanceable){
logger.log(Level.INFO, "Load balancer - New message but will not processed because is not balanceable.");
return;
}

Expand Down Expand Up @@ -579,11 +586,11 @@ public void update(Object trans, Object messageId) {
@Override
public void run() {
try {
InetAddress inet = InetAddress.getByName(
this.connector.getLedgerWriter().getUrl()
);

if (inet.isReachable(3000)) {
URL urlObj = new URL(this.connector.getLedgerWriter().getUrl());
String host = urlObj.getHost();
InetAddress inet = InetAddress.getByName(host);
if (inet.isReachable(5000)) {
if (this.flagSubscribe) {
this.subscribedTopics.forEach(topic ->
this.connector.subscribe(topic, this)
Expand Down

0 comments on commit 3bd1156

Please sign in to comment.