Class Feature

java.lang.Object
io.github.projectunified.faststats.core.Feature
Direct Known Subclasses:
ErrorTracker, FeatureFlagManager, PaperErrorTracker

public abstract class Feature extends Object
An abstract representation of a feature that can submit telemetry payloads on demand.
  • Constructor Details

    • Feature

      public Feature()
  • Method Details

    • onStart

      public void onStart()
      Called when the Metrics coordinator is started. Subclasses can override this to initialize scheduling or start listeners.
    • onShutdown

      public void onShutdown()
      Called when the Metrics coordinator is shutdown. Subclasses can override this to release resources or stop listeners.
    • getDefaultProperties

      public Map<String,String> getDefaultProperties()
      Gets the default properties to assign to the configuration.
      Returns:
      the default properties
    • onConfigMigrate

      public void onConfigMigrate(Config config, int oldConfigVersion, int newConfigVersion)
      Called when the configuration needs migration.
      Parameters:
      config - the configuration
      oldConfigVersion - the old configuration version
      newConfigVersion - the new configuration version
    • getDefaultContext

      protected final Map<String,Object> getDefaultContext()
      Gets the default context containing OS and platform information.
      Returns:
      the default context
    • submit

      protected final Submitter.Response submit(String path, Map<String,Object> dataMap, boolean compressed) throws Exception
      Submits the given data map payload and returns the response.
      Parameters:
      path - the target path or URL
      dataMap - a map of keys to their data maps
      compressed - whether to compress the payload using GZIP
      Returns:
      the response context
      Throws:
      Exception - if submission fails
    • deserialize

      protected final Map<String,Object> deserialize(String json) throws Exception
      Deserializes the given JSON string into a telemetry map.
      Parameters:
      json - the JSON string to deserialize
      Returns:
      the deserialized telemetry map
      Throws:
      Exception - if deserialization fails
    • getProperty

      public final String getProperty(String key, String defaultValue)
      Gets a configuration property.
      Parameters:
      key - the property key
      defaultValue - the default value to return if the property is missing
      Returns:
      the property value, or the default value if metrics is not initialized
    • getFeature

      public final <T extends Feature> Optional<T> getFeature(Class<T> featureClass)
      Finds a registered feature of the specified class.
      Type Parameters:
      T - the feature type
      Parameters:
      featureClass - the feature class
      Returns:
      an Optional containing the feature if found, or empty if not found or metrics is not set
    • getScheduler

      protected final TaskScheduler getScheduler()
      Gets the TaskScheduler instance.
      Returns:
      the TaskScheduler instance