Class MappedThrottlingPolicy

  • All Implemented Interfaces:
    ThrottlingPolicy

    public class MappedThrottlingPolicy
    extends Object
    implements ThrottlingPolicy
    Implementation of ThrottlingPolicy backed by a Map.
    • if the key is null, then the defaultRate is returned
    • if the key can be looked up as key in the throttlingRatesMapping, then the matching rate is returned
    • if the key can't be looked up in the throttlingRatesMapping, then the defaultRate is returned
    • Constructor Detail

      • MappedThrottlingPolicy

        public MappedThrottlingPolicy​(org.forgerock.util.AsyncFunction<ContextAndRequest,​String,​Exception> throttlingRateMapper,
                                      Map<String,​ThrottlingRate> throttlingRatesMapping,
                                      ThrottlingRate defaultRate)
        Constructs a new MappedThrottlingPolicy.
        Parameters:
        throttlingRateMapper - the key to lookup the throttling rate
        throttlingRatesMapping - the Map to look into to find the matching throttling rate.
        defaultRate - the default throttling definition.
    • Method Detail

      • lookup

        public org.forgerock.util.promise.Promise<ThrottlingRate,​Exception> lookup​(org.forgerock.services.context.Context context,
                                                                                         org.forgerock.http.protocol.Request request)
        Description copied from interface: ThrottlingPolicy
        Returns the ThrottlingRate that should be used for the provided request.
        Specified by:
        lookup in interface ThrottlingPolicy
        Parameters:
        context - The current context which might be used to retrieve the throttling rate.
        request - The current request which might be used to retrieve the throttling rate.
        Returns:
        A Promise representing the ThrottlingRate that should be used for the request.