Class CustomMeteringAgent


  • public class CustomMeteringAgent
    extends Object
    CustomMeteringAgent is used to get recorded duration, to check whether usage entry exists, to persist and retrieve usage.
    • Constructor Detail

      • CustomMeteringAgent

        public CustomMeteringAgent​(org.wso2.carbon.registry.core.Registry registry)
        Constructor for the custom metering agent
        Parameters:
        registry - governance registry of super tenant
    • Method Detail

      • getRecordedDurations

        public String[] getRecordedDurations​(String measurement)
                                      throws UsageException
        Get recorded durations
        Parameters:
        measurement - the measurement to get the duration
        Returns:
        the durations array
        Throws:
        UsageException
      • isUsageEntryExists

        public boolean isUsageEntryExists​(String duration,
                                          String measurement)
                                   throws UsageException
        Check whether the usage entry exist or not
        Parameters:
        duration - the duration (e.g. year month), null for any duration
        measurement - measurement key
        Returns:
        true if usage entry exists
        Throws:
        UsageException
      • persistUsage

        public void persistUsage​(String duration,
                                 String measurement,
                                 String value)
                          throws UsageException
        Persist usage of a user
        Parameters:
        duration - the duration (e.g. year month), null for any duration
        measurement - measurement key
        value - measurement value
        Throws:
        UsageException
      • retrieveUsage

        public String retrieveUsage​(String duration,
                                    String measurement)
                             throws UsageException
        Retrieve usage of a user
        Parameters:
        duration - the duration (e.g. year month), null for any duration
        measurement - measurement key
        Returns:
        measurement value
        Throws:
        UsageException
      • addUsage

        public long addUsage​(String duration,
                             String measurement,
                             long value)
                      throws UsageException
        Add a long value to the usage, if there were no previous entry, this will start with value 0
        Parameters:
        duration - the duration (e.g. year month), null for any duration
        measurement - measurement key
        value - measurement value
        Returns:
        the added measurement value
        Throws:
        UsageException