Class ExpiringMap.Builder<K,​V>

  • Enclosing class:
    ExpiringMap<K,​V>

    public static final class ExpiringMap.Builder<K,​V>
    extends Object
    Builds ExpiringMap instances. Defaults to ExpirationPolicy.CREATED, expiration of 60 TimeUnit.SECONDS and a maxSize of Integer.MAX_VALUE.
    • Method Detail

      • build

        public <K1 extends K,​V1 extends VExpiringMap<K1,​V1> build()
        Builds and returns an expiring map.
        Type Parameters:
        K1 - Key type
        V1 - Value type
      • expiration

        public ExpiringMap.Builder<K,​V> expiration​(long duration,
                                                         TimeUnit timeUnit)
        Sets the default map entry expiration.
        Parameters:
        duration - the length of time after an entry is created that it should be removed
        timeUnit - the unit that duration is expressed in
        Throws:
        NullPointerException - if timeUnit is null
      • maxSize

        public ExpiringMap.Builder<K,​V> maxSize​(int maxSize)
        Sets the maximum size of the map. Once this size has been reached, adding an additional entry will expire the first entry in line for expiration based on the expiration policy.
        Parameters:
        maxSize - The maximum size of the map.
      • expirationListener

        public <K1 extends K,​V1 extends VExpiringMap.Builder<K1,​V1> expirationListener​(ExpirationListener<? super K1,​? super V1> listener)
        Configures the expiration listener that will receive notifications upon each map entry's expiration. Notifications are delivered synchronously and block map write operations.
        Parameters:
        listener - to set
        Throws:
        NullPointerException - if listener is null
      • expirationListeners

        public <K1 extends K,​V1 extends VExpiringMap.Builder<K1,​V1> expirationListeners​(List<ExpirationListener<? super K1,​? super V1>> listeners)
        Configures the expiration listeners which will receive notifications upon each map entry's expiration. Notifications are delivered synchronously and block map write operations.
        Parameters:
        listeners - to set
        Throws:
        NullPointerException - if listener is null
      • asyncExpirationListener

        public <K1 extends K,​V1 extends VExpiringMap.Builder<K1,​V1> asyncExpirationListener​(ExpirationListener<? super K1,​? super V1> listener)
        Configures the expiration listener which will receive asynchronous notifications upon each map entry's expiration.
        Parameters:
        listener - to set
        Throws:
        NullPointerException - if listener is null
      • asyncExpirationListeners

        public <K1 extends K,​V1 extends VExpiringMap.Builder<K1,​V1> asyncExpirationListeners​(List<ExpirationListener<? super K1,​? super V1>> listeners)
        Configures the expiration listeners which will receive asynchronous notifications upon each map entry's expiration.
        Parameters:
        listeners - to set
        Throws:
        NullPointerException - if listener is null
      • variableExpiration

        public ExpiringMap.Builder<K,​V> variableExpiration()
        Allows for map entries to have individual expirations and for expirations to be changed.