Skip to content

Commit ea62cdf

Browse files
committed
refactor: make Persistence an injectable bean
1 parent 380be82 commit ea62cdf

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

server/src/main/java/net/laprun/sustainability/power/PowerMeasurer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class PowerMeasurer {
2121
@Inject
2222
PowerSensor sensor;
2323

24+
@Inject
25+
Persistence persistence;
26+
2427
@ConfigProperty(name = "net.laprun.sustainability.power.sampling-period", defaultValue = DEFAULT_SAMPLING_PERIOD)
2528
Duration samplingPeriod;
2629

@@ -32,7 +35,7 @@ public Multi<SensorMeasure> stream(String pid) throws Exception {
3235
}
3336

3437
public void startTrackingApp(String appName, String pid) throws Exception {
35-
stream(pid).subscribe().with(m -> Persistence.save(m, appName));
38+
stream(pid).subscribe().with(m -> persistence.save(m, appName));
3639
}
3740

3841
private RegisteredPID track(String pid) throws Exception {

server/src/main/java/net/laprun/sustainability/power/persistence/Persistence.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package net.laprun.sustainability.power.persistence;
22

3+
import jakarta.enterprise.context.ApplicationScoped;
34
import jakarta.transaction.Transactional;
45

56
import net.laprun.sustainability.power.SensorMeasure;
67

7-
public enum Persistence {
8-
;
8+
@ApplicationScoped
9+
public class Persistence {
910

1011
@Transactional
11-
public static Measure save(SensorMeasure measure, String appName) {
12+
public Measure save(SensorMeasure measure, String appName) {
1213
final var persisted = new Measure();
1314
persisted.components = measure.components();
1415
persisted.appName = appName;

0 commit comments

Comments
 (0)