23
23
import org .terasology .engine .core .subsystem .EngineSubsystem ;
24
24
import org .terasology .engine .monitoring .gui .AdvancedMonitor ;
25
25
import reactor .core .publisher .Flux ;
26
- import reactor .function .TupleUtils ;
27
- import reactor .util .function .Tuple2 ;
28
- import reactor .util .function .Tuples ;
29
26
30
27
import java .time .Duration ;
31
28
import java .util .List ;
@@ -45,6 +42,12 @@ public String getName() {
45
42
return "Monitoring" ;
46
43
}
47
44
45
+ @ Override
46
+ public void preInitialise (Context rootContext ) {
47
+ // FIXME: `@Share` is not implemented for EngineSubsystems?
48
+ rootContext .put (MonitoringSubsystem .class , this );
49
+ }
50
+
48
51
@ Override
49
52
public void initialise (GameEngine engine , Context rootContext ) {
50
53
if (rootContext .get (SystemConfig .class ).monitoringEnabled .get ()) {
@@ -54,11 +57,6 @@ public void initialise(GameEngine engine, Context rootContext) {
54
57
meterRegistry = initMeterRegistries ();
55
58
}
56
59
57
- @ Override
58
- public void postInitialise (Context context ) {
59
- initMeters (context );
60
- }
61
-
62
60
/**
63
61
* Initialize Micrometer metrics and publishers.
64
62
*
@@ -95,7 +93,7 @@ public Duration step() {
95
93
}
96
94
97
95
/** Initialize meters for all the things in this Context. */
98
- protected void initMeters (Context context ) {
96
+ public void initMeters (Context context ) {
99
97
// We can build meters individually like this:
100
98
var time = context .get (Time .class );
101
99
Gauge .builder ("terasology.fps" , time ::getFps )
@@ -117,15 +115,17 @@ protected void initMeters(Context context) {
117
115
}
118
116
119
117
protected void registerForContext (Context context , Iterable <GaugeMapEntry > gaugeMap ) {
120
- Flux .fromIterable (gaugeMap )
121
- .map (entry -> Tuples .of (context .get (entry .iface ), entry .gaugeSpecs ))
122
- .filter (TupleUtils .predicate ((subject , specs ) -> subject != null ))
123
- .doOnDiscard (Tuple2 .class , TupleUtils .consumer ((iface , gaugeSpecs ) ->
124
- logger .debug ("Not building gauges for {}, none was in {}" , iface , context )))
125
- .subscribe (TupleUtils .consumer (this ::registerAll ));
118
+ for (GaugeMapEntry entry : gaugeMap ) {
119
+ var subject = context .get (entry .iface );
120
+ if (subject != null ) {
121
+ registerAll (subject , entry .gaugeSpecs );
122
+ } else {
123
+ logger .warn ("Not building gauges for {}, none was in {}" , entry .iface , context );
124
+ }
125
+ }
126
126
}
127
127
128
- protected <T > void registerAll (T subject , Set <GaugeSpec <? extends T >> gaugeSpecs ) {
128
+ public <T > void registerAll (T subject , Set <GaugeSpec <? extends T >> gaugeSpecs ) {
129
129
Flux .fromIterable (gaugeSpecs )
130
130
.filter (spec -> spec .isInstanceOfType (subject ))
131
131
// Make sure the gauge is right for the specific type.
@@ -134,6 +134,7 @@ protected <T> void registerAll(T subject, Set<GaugeSpec<? extends T>> gaugeSpecs
134
134
}
135
135
136
136
public void registerMeter (MeterBinder meterBinder ) {
137
+ logger .debug ("Binding {} to {}" , meterBinder , meterRegistry );
137
138
meterBinder .bindTo (meterRegistry );
138
139
}
139
140
0 commit comments