11package dev .faststats .core ;
22
33import com .google .gson .JsonObject ;
4- import dev .faststats .core .chart . Chart ;
4+ import dev .faststats .core .data . Metric ;
55import org .jetbrains .annotations .Async ;
66import org .jetbrains .annotations .Contract ;
77import org .jetbrains .annotations .MustBeInvokedByOverriders ;
@@ -41,7 +41,7 @@ public abstract class SimpleMetrics implements Metrics {
4141 .build ();
4242 private @ Nullable ScheduledExecutorService executor = null ;
4343
44- private final Set <Chart <?>> charts ;
44+ private final Set <Metric <?>> metrics ;
4545 private final Config config ;
4646 private final @ Token String token ;
4747 private final @ Nullable ErrorTracker tracker ;
@@ -55,7 +55,7 @@ protected SimpleMetrics(final Factory<?, ?> factory, final Config config) throws
5555 if (factory .token == null ) throw new IllegalStateException ("Token must be specified" );
5656
5757 this .config = config ;
58- this .charts = config .additionalMetrics ? Set .copyOf (factory .charts ) : Set .of ();
58+ this .metrics = config .additionalMetrics ? Set .copyOf (factory .metrics ) : Set .of ();
5959 this .debug = factory .debug || Boolean .getBoolean ("faststats.debug" ) || config .debug ();
6060 this .token = factory .token ;
6161 this .tracker = config .errorTracking ? factory .tracker : null ;
@@ -71,7 +71,7 @@ protected SimpleMetrics(final Factory<?, ?> factory, final Path config) throws I
7171 @ VisibleForTesting
7272 protected SimpleMetrics (
7373 final Config config ,
74- final Set <Chart <?>> charts ,
74+ final Set <Metric <?>> metrics ,
7575 @ Token final String token ,
7676 @ Nullable final ErrorTracker tracker ,
7777 @ Nullable final Runnable flush ,
@@ -82,7 +82,7 @@ protected SimpleMetrics(
8282 throw new IllegalArgumentException ("Invalid token '" + token + "', must match '" + Token .PATTERN + "'" );
8383 }
8484
85- this .charts = config .additionalMetrics ? Set .copyOf (charts ) : Set .of ();
85+ this .metrics = config .additionalMetrics ? Set .copyOf (metrics ) : Set .of ();
8686 this .config = config ;
8787 this .debug = debug ;
8888 this .token = token ;
@@ -235,32 +235,32 @@ private boolean submitNow() throws IOException {
235235
236236 protected JsonObject createData () {
237237 final var data = new JsonObject ();
238- final var charts = new JsonObject ();
238+ final var metrics = new JsonObject ();
239239
240- charts .addProperty ("java_version" , javaVersion );
241- charts .addProperty ("os_arch" , osArch );
242- charts .addProperty ("os_name" , osName );
243- charts .addProperty ("os_version" , osVersion );
244- charts .addProperty ("core_count" , coreCount );
240+ metrics .addProperty ("java_version" , javaVersion );
241+ metrics .addProperty ("os_arch" , osArch );
242+ metrics .addProperty ("os_name" , osName );
243+ metrics .addProperty ("os_version" , osVersion );
244+ metrics .addProperty ("core_count" , coreCount );
245245
246- this .charts .forEach (chart -> {
246+ this .metrics .forEach (metric -> {
247247 try {
248- chart .getData ().ifPresent (chartData -> charts .add (chart .getId (), chartData ));
248+ metric .getData ().ifPresent (element -> metrics .add (metric .getId (), element ));
249249 } catch (final Throwable t ) {
250- error ("Failed to build chart data: " + chart .getId (), t );
250+ error ("Failed to build metric data: " + metric .getId (), t );
251251 getErrorTracker ().ifPresent (tracker -> tracker .trackError (t ));
252252 }
253253 });
254254
255255 try {
256- appendDefaultData (charts );
256+ appendDefaultData (metrics );
257257 } catch (final Throwable t ) {
258258 error ("Failed to append default data" , t );
259259 getErrorTracker ().ifPresent (tracker -> tracker .trackError (t ));
260260 }
261261
262262 data .addProperty ("identifier" , config .serverId ().toString ());
263- data .add ("data" , charts );
263+ data .add ("data" , metrics );
264264
265265 getErrorTracker ().map (SimpleErrorTracker .class ::cast )
266266 .map (SimpleErrorTracker ::getData )
@@ -285,7 +285,7 @@ public Metrics.Config getConfig() {
285285 }
286286
287287 @ Contract (mutates = "param1" )
288- protected abstract void appendDefaultData (JsonObject charts );
288+ protected abstract void appendDefaultData (JsonObject metrics );
289289
290290 protected void error (final String message , @ Nullable final Throwable throwable ) {
291291 if (debug ) printError ("[" + getClass ().getName () + "]: " + message , throwable );
@@ -322,7 +322,7 @@ public void shutdown() {
322322 }
323323
324324 public abstract static class Factory <T , F extends Metrics .Factory <T , F >> implements Metrics .Factory <T , F > {
325- private final Set <Chart <?>> charts = new HashSet <>(0 );
325+ private final Set <Metric <?>> metrics = new HashSet <>(0 );
326326 private URI url = URI .create ("https://metrics.faststats.dev/v1/collect" );
327327 private @ Nullable ErrorTracker tracker ;
328328 private @ Nullable Runnable flush ;
@@ -331,8 +331,8 @@ public abstract static class Factory<T, F extends Metrics.Factory<T, F>> impleme
331331
332332 @ Override
333333 @ SuppressWarnings ("unchecked" )
334- public F addChart (final Chart <?> chart ) throws IllegalArgumentException {
335- if (!charts .add (chart )) throw new IllegalArgumentException ("Chart already added: " + chart .getId ());
334+ public F addMetric (final Metric <?> metric ) throws IllegalArgumentException {
335+ if (!metrics .add (metric )) throw new IllegalArgumentException ("Metric already added: " + metric .getId ());
336336 return (F ) this ;
337337 }
338338
0 commit comments