2323import org .terasology .engine .core .subsystem .EngineSubsystem ;
2424import org .terasology .engine .monitoring .gui .AdvancedMonitor ;
2525import reactor .core .publisher .Flux ;
26- import reactor .function .TupleUtils ;
27- import reactor .util .function .Tuple2 ;
28- import reactor .util .function .Tuples ;
2926
3027import java .time .Duration ;
3128import java .util .List ;
@@ -45,6 +42,12 @@ public String getName() {
4542 return "Monitoring" ;
4643 }
4744
45+ @ Override
46+ public void preInitialise (Context rootContext ) {
47+ // FIXME: `@Share` is not implemented for EngineSubsystems?
48+ rootContext .put (MonitoringSubsystem .class , this );
49+ }
50+
4851 @ Override
4952 public void initialise (GameEngine engine , Context rootContext ) {
5053 if (rootContext .get (SystemConfig .class ).monitoringEnabled .get ()) {
@@ -54,11 +57,6 @@ public void initialise(GameEngine engine, Context rootContext) {
5457 meterRegistry = initMeterRegistries ();
5558 }
5659
57- @ Override
58- public void postInitialise (Context context ) {
59- initMeters (context );
60- }
61-
6260 /**
6361 * Initialize Micrometer metrics and publishers.
6462 *
@@ -95,7 +93,7 @@ public Duration step() {
9593 }
9694
9795 /** Initialize meters for all the things in this Context. */
98- protected void initMeters (Context context ) {
96+ public void initMeters (Context context ) {
9997 // We can build meters individually like this:
10098 var time = context .get (Time .class );
10199 Gauge .builder ("terasology.fps" , time ::getFps )
@@ -117,15 +115,17 @@ protected void initMeters(Context context) {
117115 }
118116
119117 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+ }
126126 }
127127
128- protected <T > void registerAll (T subject , Set <GaugeSpec <? extends T >> gaugeSpecs ) {
128+ public <T > void registerAll (T subject , Set <GaugeSpec <? extends T >> gaugeSpecs ) {
129129 Flux .fromIterable (gaugeSpecs )
130130 .filter (spec -> spec .isInstanceOfType (subject ))
131131 // 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
134134 }
135135
136136 public void registerMeter (MeterBinder meterBinder ) {
137+ logger .debug ("Binding {} to {}" , meterBinder , meterRegistry );
137138 meterBinder .bindTo (meterRegistry );
138139 }
139140
0 commit comments