Skip to content

Commit

Permalink
Merge pull request #2 from larsid/refactor/log
Browse files Browse the repository at this point in the history
Refactor/log
  • Loading branch information
AllanCapistrano authored Jul 17, 2023
2 parents b5ee212 + f7c142d commit b859276
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/dlt/load/monitor/model/LoadMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class LoadMonitor implements Runnable {
private Processor processor;
private int samplingInterval;
private IDevicePropertiesManager deviceManager;
private static final Logger logger = Logger.getLogger(LoadMonitor.class.getName());

public LoadMonitor(int samplingInterval) {
this.samplingInterval = samplingInterval;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void run() {
qtdDevices = this.deviceManager.getAllDevices().size();
this.processor.updateBrokerStatus(qtdDevices);
} catch (IOException | InterruptedException ex) {
Logger.getLogger(LoadMonitor.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
this.stop();
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/dlt/load/monitor/model/Processor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dlt.load.monitor.model;

import java.util.logging.Logger;

/**
*
* @author Allan Capistrano, Antonio Crispim, Uellington Damasceno
Expand All @@ -12,6 +14,9 @@ public class Processor {
private long lastSentLbEntry;
private boolean flag;
private long lbEntryTimeout;
private static final Logger logger = Logger.getLogger(
Processor.class.getName()
);

public Processor(int loadLimit) {
this.loadLimit = loadLimit;
Expand All @@ -22,16 +27,14 @@ protected void updateBrokerStatus(Integer qtdDevices)
boolean lbEntry = (qtdDevices >= loadLimit);
boolean available = ((qtdDevices + 1) < loadLimit);

System.out.println(
logger.info(
"Amount of devices: " + qtdDevices + " | Need balancing? " + lbEntry
);

if (lbEntry) { //Se o gateway está sobrecarregado.
if (
flag ||
System.currentTimeMillis() >
this.lastSentLbEntry +
lbEntryTimeout
System.currentTimeMillis() > this.lastSentLbEntry + lbEntryTimeout
) {
// Salva o tempo da última vez que enviou uma transação do tipo LB_ENTRY.
this.lastSentLbEntry = System.currentTimeMillis();
Expand Down

0 comments on commit b859276

Please sign in to comment.