com.googlecode.concurrentlinkedhashmap
Class ConcurrentLinkedHashMap.Builder<K,V>

java.lang.Object
  extended by com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder<K,V>
Enclosing class:
ConcurrentLinkedHashMap<K,V>

public static final class ConcurrentLinkedHashMap.Builder<K,V>
extends Object

A builder that creates ConcurrentLinkedHashMap instances. It provides a flexible approach for constructing customized instances with a named parameter syntax. It can be used in the following manner:

ConcurrentMap<Vertices, Set<Edge>> graph = new Builder<Vertices, Set<Edge>>()
     .maximumWeightedCapacity(5000)
     .weigher(Weighers.<Edge>set())
     .build();
 


Constructor Summary
ConcurrentLinkedHashMap.Builder()
           
 
Method Summary
 ConcurrentLinkedHashMap<K,V> build()
          Creates a new ConcurrentLinkedHashMap instance.
 ConcurrentLinkedHashMap.Builder<K,V> catchup(ScheduledExecutorService executor, long delay, TimeUnit unit)
          Specifies an executor for use in catching up the page replacement policy.
 ConcurrentLinkedHashMap.Builder<K,V> concurrencyLevel(int concurrencyLevel)
          Specifies the estimated number of concurrently updating threads.
 ConcurrentLinkedHashMap.Builder<K,V> initialCapacity(int initialCapacity)
          Specifies the initial capacity of the hash table (default 16).
 ConcurrentLinkedHashMap.Builder<K,V> listener(EvictionListener<K,V> listener)
          Specifies an optional listener that is registered for notification when an entry is evicted.
 ConcurrentLinkedHashMap.Builder<K,V> maximumWeightedCapacity(int capacity)
          Specifies the maximum weighted capacity to coerce the map to and may exceed it temporarily.
 ConcurrentLinkedHashMap.Builder<K,V> weigher(Weigher<? super V> weigher)
          Specifies an algorithm to determine how many the units of capacity a value consumes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConcurrentLinkedHashMap.Builder

public ConcurrentLinkedHashMap.Builder()
Method Detail

initialCapacity

public ConcurrentLinkedHashMap.Builder<K,V> initialCapacity(int initialCapacity)
Specifies the initial capacity of the hash table (default 16). This is the number of key-value pairs that the hash table can hold before a resize operation is required.

Parameters:
initialCapacity - the initial capacity used to size the hash table to accommodate this many entries.
Throws:
IllegalArgumentException - if the initialCapacity is negative

maximumWeightedCapacity

public ConcurrentLinkedHashMap.Builder<K,V> maximumWeightedCapacity(int capacity)
Specifies the maximum weighted capacity to coerce the map to and may exceed it temporarily.

Parameters:
capacity - the weighted threshold to bound the map by
Throws:
IllegalArgumentException - if the maximumWeightedCapacity is negative

concurrencyLevel

public ConcurrentLinkedHashMap.Builder<K,V> concurrencyLevel(int concurrencyLevel)
Specifies the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads (default 16).

Parameters:
concurrencyLevel - the estimated number of concurrently updating threads
Throws:
IllegalArgumentException - if the concurrencyLevel is less than or equal to zero

listener

public ConcurrentLinkedHashMap.Builder<K,V> listener(EvictionListener<K,V> listener)
Specifies an optional listener that is registered for notification when an entry is evicted.

Parameters:
listener - the object to forward evicted entries to
Throws:
NullPointerException - if the listener is null

weigher

public ConcurrentLinkedHashMap.Builder<K,V> weigher(Weigher<? super V> weigher)
Specifies an algorithm to determine how many the units of capacity a value consumes. The default algorithm bounds the map by the number of key-value pairs by giving each entry a weight of 1.

Parameters:
weigher - the algorithm to determine a value's weight
Throws:
NullPointerException - if the weigher is null

catchup

public ConcurrentLinkedHashMap.Builder<K,V> catchup(ScheduledExecutorService executor,
                                                    long delay,
                                                    TimeUnit unit)
Specifies an executor for use in catching up the page replacement policy. The catch-up phase processes both updates to the retention ordering and writes that may trigger an eviction. The delay should be chosen carefully as the map will not automatically evict between executions.

If unspecified or the executor is shutdown, the catching up will be amortized on user threads during write operations (or during read operations, in the absence of writes).

A single-threaded ScheduledExecutorService should be sufficient for catching up the page replacement policy in many maps.

Parameters:
executor - the executor to schedule on
delay - the delay between executions
unit - the time unit of the delay parameter
Throws:
NullPointerException - if the executor or time unit is null
IllegalArgumentException - if the delay is less than or equal to zero

build

public ConcurrentLinkedHashMap<K,V> build()
Creates a new ConcurrentLinkedHashMap instance.

Throws:
IllegalStateException - if the maximum weighted capacity was not set
RejectedExecutionException - if an executor was specified and the catch-up task cannot be scheduled for execution


Copyright © 2012. All Rights Reserved.