Class UsageReporter

  • All Implemented Interfaces:

    
    public class UsageReporter
    
                        

    Each Usage Reporter is assigned a Target ID, and reports usage by persisting the UsageRecords into the UsageStore.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public String targetId
    • Constructor Summary

      Constructors 
      Constructor Description
      UsageReporter(String targetId, UsageStore recordStore) Constructs a usage reporter by assigning a target ID and a persistence store.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      String getTargetId() Returns the targetId assigned to the reporter.
      boolean isEnabled() Checks if the UsageReporter is enabled.
      void report(@NonNull() UsageRecord record) Persists a UsageRecord if the reporter is enabled.
      <T extends Enum<T>> void report(@NonNull() T event, @NonNull() Date date, @NonNull() UsageInfo info) Creates a UsageRecord with the user-defined event type, date, and UsageInfo, then persists the record.
      void setEnabled(boolean enabled) Enables the usage reporter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UsageReporter

        UsageReporter(String targetId, UsageStore recordStore)
        Constructs a usage reporter by assigning a target ID and a persistence store.
        Parameters:
        targetId - an ID to group all records reported by this reporter
        recordStore - a store to persists the usage records
    • Method Detail

      • getTargetId

        @NonNull() String getTargetId()

        Returns the targetId assigned to the reporter.

      • isEnabled

         boolean isEnabled()

        Checks if the UsageReporter is enabled. If it is not enabled all the call to reporter methods will be ignored.

      • report

         void report(@NonNull() UsageRecord record)

        Persists a UsageRecord if the reporter is enabled. The record will be discarded if the reporter is disabled.

        Parameters:
        record - a usage record
      • report

         <T extends Enum<T>> void report(@NonNull() T event, @NonNull() Date date, @NonNull() UsageInfo info)

        Creates a UsageRecord with the user-defined event type, date, and UsageInfo, then persists the record.

        Parameters:
        event - an instance of user defined Enum event type
        date - a date
        info - an instance of UsageInfo
      • setEnabled

         void setEnabled(boolean enabled)

        Enables the usage reporter.

        Parameters:
        enabled - True to enable the reporter, false to disable it.