-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b676253
commit 3f4576f
Showing
7 changed files
with
275 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
src/main/java/com/device/fot/virtual/controller/DataController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/device/fot/virtual/controller/LatencyLogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.device.fot.virtual.controller; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
|
||
public class LatencyLogController extends PersistenceController<Long> { | ||
|
||
private static LatencyLogController latencyLogController = new LatencyLogController(); | ||
|
||
private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss.SSS"); | ||
|
||
private LatencyLogController() { | ||
super("latency_log.csv"); | ||
} | ||
|
||
public synchronized static LatencyLogController getInstance() { | ||
return latencyLogController; | ||
} | ||
|
||
public void putLatency(Long latency) throws InterruptedException { | ||
if (canSaveData) { | ||
buffer.put(latency); | ||
} | ||
} | ||
|
||
private String buildLogLatencyLine(Long latency) { | ||
LocalDateTime currentTime = LocalDateTime.now(); | ||
String formattedTime = currentTime.format(formatter); | ||
return String.format("%s,%d", formattedTime, latency); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
running = true; | ||
var latencyLines = new ArrayList<String>(bufferSize); | ||
while (running) { | ||
try { | ||
if (!buffer.isEmpty()) { | ||
latencyLines.add(this.buildLogLatencyLine(buffer.take())); | ||
if (latencyLines.size() >= bufferSize) { | ||
this.write(latencyLines); | ||
latencyLines.clear(); | ||
} | ||
} | ||
} catch (InterruptedException ex) { | ||
this.write(latencyLines); | ||
this.running = false; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String getThreadName() { | ||
return "LATENCY_LOG_WRITER"; | ||
} | ||
} |
Oops, something went wrong.