Class AbstractQuotaService<T extends QuotaKey>

    • Constructor Detail

      • AbstractQuotaService

        public AbstractQuotaService()
    • Method Detail

      • initialize

        public Quota initialize​(T key,
                                long minCount,
                                long maxCount)
                         throws QuotaException
        Description copied from interface: QuotaService
        Initializes the quota of the resource for the given quota key.
        Specified by:
        initialize in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        minCount - the minimum count
        maxCount - the maximum count
        Returns:
        the quota
        Throws:
        QuotaException - on error
      • get

        public Quota get​(T key)
                  throws QuotaException
        Description copied from interface: QuotaService
        Gets the quota of the resource from a given quota key. A save operation is done if the current count has changed.
        Specified by:
        get in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        Returns:
        the quota mapped with the key
        Throws:
        QuotaException
      • verify

        public Quota verify​(T key)
                     throws QuotaException
        Description copied from interface: QuotaService
        Verifies if the quota is full or not enough from a given quota key.

        Be aware of that the quota count will be loaded and computed each time this signature is called.

        If full then a quota full exception is thrown If not enough then a quota not enough exception is thrown.
        Specified by:
        verify in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        Returns:
        the quota used by the verify treatment
        Throws:
        QuotaException - on error
      • verify

        public Quota verify​(T key,
                            AbstractQuotaCountingOffset countingOffset)
                     throws QuotaException
        Description copied from interface: QuotaService
        Verifies if the quota is full or not enough from a given quota key and adding a counting offset.

        Be aware of that the quota count will be loaded and computed each time this signature is called.

        If full then a quota full exception is throw. If not enough then a quota not enough exception is throw.
        Specified by:
        verify in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        countingOffset - a counting offset
        Returns:
        the quota used by the verify treatment
        Throws:
        QuotaException - on error
      • verify

        public Quota verify​(T key,
                            Quota quota)
                     throws QuotaException
        Description copied from interface: QuotaService
        Verifies if the given loaded and computed quota.

        Be aware of that the quota count is not again computed by this service. When this signature is called, it means that the Quota instance has been already loaded and there is no need to perform again the counting.

        If full then a quota full exception is thrown If not enough then a quota not enough exception is thrown.
        Specified by:
        verify in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        quota - a loaded quota
        Returns:
        the quota used by the verify treatment
        Throws:
        QuotaException - on error
      • verify

        public Quota verify​(T key,
                            Quota quota,
                            AbstractQuotaCountingOffset countingOffset)
                     throws QuotaException
        Description copied from interface: QuotaService
        Verifies if the given loaded and computed quota by adding a counting offset.

        Be aware of that the quota count is not again computed by this service. When this signature is called, it means that the Quota instance has been already loaded and there is no need to perform again the counting.

        If full then a quota full exception is thrown. If not enough then a quota not enough exception is thrown.
        Specified by:
        verify in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
        quota - a loaded quota
        countingOffset - a counting offset
        Returns:
        a copied quota from the given one containing the count with the offset used by the verify treatment
        Throws:
        QuotaException - on error
      • verifyQuota

        protected final Quota verifyQuota​(Quota quota,
                                          AbstractQuotaCountingOffset countingOffset)
                                   throws QuotaException
        This method ensures that no recursion can be done between service signatures.

        The count of given quota MUST have been computed before calling this method.

        Parameters:
        quota - the quota to verify.
        countingOffset - an offset to apply.
        Returns:
        a copied quota from the given one containing the count with the offset used by the verify treatment
        Throws:
        QuotaException - when the quota is reached.
      • remove

        public void remove​(T key)
        Description copied from interface: QuotaService
        Removes quietly the quota of the resource from a given quota key.
        Specified by:
        remove in interface QuotaService<T extends QuotaKey>
        Parameters:
        key - the key
      • isActivated

        protected abstract boolean isActivated()
        Indicates if the type of quota is activated
        Returns:
        true if activated, false otherwise