Package net.jodah.expiringmap
Class ExpiringMap.Builder<K,V>
- java.lang.Object
-
- net.jodah.expiringmap.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <K1 extends K,V1 extends V>
ExpiringMap.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.<K1 extends K,V1 extends V>
ExpiringMap.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.<K1 extends K,V1 extends V>
ExpiringMap<K1,V1>build()
Builds and returns an expiring map.<K1 extends K,V1 extends V>
ExpiringMap.Builder<K1,V1>entryLoader(EntryLoader<? super K1,? super V1> loader)
Sets the EntryLoader to use when loading entries.ExpiringMap.Builder<K,V>
expiration(long duration, TimeUnit timeUnit)
Sets the default map entry expiration.<K1 extends K,V1 extends V>
ExpiringMap.Builder<K1,V1>expirationListener(ExpirationListener<? super K1,? super V1> listener)
Configures the expiration listener that will receive notifications upon each map entry's expiration.<K1 extends K,V1 extends V>
ExpiringMap.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.ExpiringMap.Builder<K,V>
expirationPolicy(ExpirationPolicy expirationPolicy)
Configures the map entry expiration policy.<K1 extends K,V1 extends V>
ExpiringMap.Builder<K1,V1>expiringEntryLoader(ExpiringEntryLoader<? super K1,? super V1> loader)
Sets the ExpiringEntryLoader to use when loading entries and configuresvariable expiration
.ExpiringMap.Builder<K,V>
maxSize(int maxSize)
Sets the maximum size of the map.ExpiringMap.Builder<K,V>
variableExpiration()
Allows for map entries to have individual expirations and for expirations to be changed.
-
-
-
Method Detail
-
build
public <K1 extends K,V1 extends V> ExpiringMap<K1,V1> build()
Builds and returns an expiring map.- Type Parameters:
K1
- Key typeV1
- 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 removedtimeUnit
- the unit thatduration
is expressed in- Throws:
NullPointerException
- iftimeUnit
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.
-
entryLoader
public <K1 extends K,V1 extends V> ExpiringMap.Builder<K1,V1> entryLoader(EntryLoader<? super K1,? super V1> loader)
Sets the EntryLoader to use when loading entries. Either an EntryLoader or ExpiringEntryLoader may be set, not both.- Parameters:
loader
- to set- Throws:
NullPointerException
- ifloader
is nullIllegalStateException
- if anExpiringEntryLoader
is set
-
expiringEntryLoader
public <K1 extends K,V1 extends V> ExpiringMap.Builder<K1,V1> expiringEntryLoader(ExpiringEntryLoader<? super K1,? super V1> loader)
Sets the ExpiringEntryLoader to use when loading entries and configuresvariable expiration
. Either an EntryLoader or ExpiringEntryLoader may be set, not both.- Parameters:
loader
- to set- Throws:
NullPointerException
- ifloader
is nullIllegalStateException
- if anEntryLoader
is set
-
expirationListener
public <K1 extends K,V1 extends V> ExpiringMap.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
- iflistener
is null
-
expirationListeners
public <K1 extends K,V1 extends V> ExpiringMap.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
- iflistener
is null
-
asyncExpirationListener
public <K1 extends K,V1 extends V> ExpiringMap.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
- iflistener
is null
-
asyncExpirationListeners
public <K1 extends K,V1 extends V> ExpiringMap.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
- iflistener
is null
-
expirationPolicy
public ExpiringMap.Builder<K,V> expirationPolicy(ExpirationPolicy expirationPolicy)
Configures the map entry expiration policy.- Parameters:
expirationPolicy
-- Throws:
NullPointerException
- ifexpirationPolicy
is null
-
variableExpiration
public ExpiringMap.Builder<K,V> variableExpiration()
Allows for map entries to have individual expirations and for expirations to be changed.
-
-