Class Metrics.Builder

java.lang.Object
io.github.projectunified.faststats.core.Metrics.Builder
Enclosing class:
Metrics

public static final class Metrics.Builder extends Object
Builder class for Metrics.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • platform

      public Metrics.Builder platform(Platform platform)
      Sets the platform implementation.
      Parameters:
      platform - the platform
      Returns:
      this builder instance
    • serializer

      public Metrics.Builder serializer(Serializer serializer)
      Sets the JSON serializer.
      Parameters:
      serializer - the serializer
      Returns:
      this builder instance
    • submitter

      public Metrics.Builder submitter(Submitter submitter)
      Sets the submitter.
      Parameters:
      submitter - the submitter
      Returns:
      this builder instance
    • scheduler

      public Metrics.Builder scheduler(TaskScheduler scheduler)
      Sets the task scheduler.
      Parameters:
      scheduler - the task scheduler
      Returns:
      this builder instance
    • addMetric

      public Metrics.Builder addMetric(Metric<?> metric)
      Adds a metric to be collected and submitted.
      Parameters:
      metric - the metric to add
      Returns:
      this builder instance
      Throws:
      IllegalArgumentException - if the metric name is invalid or already added
    • addMetrics

      public Metrics.Builder addMetrics(Collection<Metric<?>> metrics)
      Adds a collection of metrics to be collected and submitted.
      Parameters:
      metrics - the metrics to add
      Returns:
      this builder instance
      Throws:
      IllegalArgumentException - if a metric name is invalid or already added
    • onFlush

      public Metrics.Builder onFlush(Runnable flush)
      Adds a flush callback to this metrics instance.

      The callback is invoked after the metrics payload has been accepted by the metrics server, which makes it suitable for resetting counters that accumulate between submissions.

      Parameters:
      flush - the flush callback
      Returns:
      this builder instance
    • addFeature

      public Metrics.Builder addFeature(Feature feature)
      Adds a feature to be configured with the submit executor.
      Parameters:
      feature - the feature to add
      Returns:
      this builder instance
    • addFeatures

      public Metrics.Builder addFeatures(Collection<Feature> features)
      Adds a collection of features to be configured with the submit executor.
      Parameters:
      features - the features to add
      Returns:
      this builder instance
    • build

      public Metrics build()
      Builds the Metrics instance.
      Returns:
      a new Metrics instance
      Throws:
      IllegalStateException - if any required fields are missing