Skip to content

Commit

Permalink
Orwell (#198)
Browse files Browse the repository at this point in the history
* Break cycle
  • Loading branch information
RetGal authored Dec 26, 2024
1 parent cb4ab5f commit 42a47aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/mpo/dayon/common/monitoring/BigBrother.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import mpo.dayon.common.monitoring.counter.Counter;

public final class BigBrother {
public final class BigBrother implements CounterRegistry {

private BigBrother() {
}
Expand All @@ -22,7 +22,8 @@ public static BigBrother get() {
/**
* @param instantRatePeriod millis
*/
public void registerCounter(final Counter<?> counter, final long instantRatePeriod) {
@Override
public void registerCounter(Counter<?> counter, long instantRatePeriod) {
scheduler.scheduleAtFixedRate(counter::computeAndResetInstantValue, 0, instantRatePeriod, TimeUnit.MILLISECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mpo.dayon.common.monitoring;

import mpo.dayon.common.monitoring.counter.Counter;

public interface CounterRegistry {
void registerCounter(Counter<?> counter, long instantPeriod);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.atomic.AtomicLong;

import mpo.dayon.common.monitoring.BigBrother;
import mpo.dayon.common.monitoring.CounterRegistry;

public abstract class Counter<T> {
private final List<CounterListener<T>> listeners = new CopyOnWriteArrayList<>();
Expand All @@ -13,14 +14,14 @@ public abstract class Counter<T> {

private final String shortDescription;

private final BigBrother bigBrother;
private final CounterRegistry counterRegistry;

AtomicLong instantStart;

Counter(String uid, String shortDescription, BigBrother bigBrother) {
Counter(String uid, String shortDescription, CounterRegistry counterRegistry) {
this.uid = uid;
this.shortDescription = shortDescription;
this.bigBrother = bigBrother;
this.counterRegistry = counterRegistry;
}

public void addListener(CounterListener<T> listener) {
Expand Down Expand Up @@ -51,7 +52,7 @@ private void initialize() {
*/
public void start(long instantPeriod) {
initialize();
bigBrother.registerCounter(this, instantPeriod);
counterRegistry.registerCounter(this, instantPeriod);
}

public abstract void computeAndResetInstantValue();
Expand Down

0 comments on commit 42a47aa

Please sign in to comment.