Class BlockingHashMap<TKey,TValue>

java.lang.Object
com.comphenix.protocol.concurrency.BlockingHashMap<TKey,TValue>
Type Parameters:
TKey - - type of the key.
TValue - - type of the value.

public class BlockingHashMap<TKey,TValue> extends Object
A map that supports blocking on read operations. Null keys are not supported.

Values are stored as weak references, and will be automatically removed once they've all been dereferenced.

  • Constructor Details

    • BlockingHashMap

      public BlockingHashMap()
      Initialize a new map.
  • Method Details

    • newInvalidCacheLoader

      public static <TKey, TValue> com.google.common.cache.CacheLoader<TKey,TValue> newInvalidCacheLoader()
      Retrieve a cache loader that will always throw an exception.
      Type Parameters:
      TKey - Type of the key
      TValue - Type of the value
      Returns:
      An invalid cache loader.
    • create

      public static <TKey, TValue> BlockingHashMap<TKey,TValue> create()
      Initialize a new map.
      Type Parameters:
      TKey - Type of the key
      TValue - Type of the value
      Returns:
      The created map.
    • get

      public TValue get(TKey key) throws InterruptedException
      Waits until a value has been associated with the given key, and then retrieves that value.
      Parameters:
      key - - the key whose associated value is to be returned
      Returns:
      The value to which the specified key is mapped.
      Throws:
      InterruptedException - If the current thread got interrupted while waiting.
    • get

      public TValue get(TKey key, long timeout, TimeUnit unit) throws InterruptedException
      Waits until a value has been associated with the given key, and then retrieves that value.
      Parameters:
      key - - the key whose associated value is to be returned
      timeout - - the amount of time to wait until an association has been made.
      unit - - unit of timeout.
      Returns:
      The value to which the specified key is mapped, or NULL if the timeout elapsed.
      Throws:
      InterruptedException - If the current thread got interrupted while waiting.
    • get

      public TValue get(TKey key, long timeout, TimeUnit unit, boolean ignoreInterrupted) throws InterruptedException
      Waits until a value has been associated with the given key, and then retrieves that value.

      If timeout is zero, this method will return immediately if it can't find an socket injector.

      Parameters:
      key - - the key whose associated value is to be returned
      timeout - - the amount of time to wait until an association has been made.
      unit - - unit of timeout.
      ignoreInterrupted - - TRUE if we should ignore the thread being interrupted, FALSE otherwise.
      Returns:
      The value to which the specified key is mapped, or NULL if the timeout elapsed.
      Throws:
      InterruptedException - If the current thread got interrupted while waiting.
    • put

      public TValue put(TKey key, TValue value)
      Associate a given key with the given value.

      Wakes up any blocking getters on this specific key.

      Parameters:
      key - - the key to associate.
      value - - the value.
      Returns:
      The previously associated value.
    • putIfAbsent

      public TValue putIfAbsent(TKey key, TValue value)
      If and only if a key is not present in the map will it be associated with the given value.
      Parameters:
      key - - the key to associate.
      value - - the value to associate.
      Returns:
      The previous value this key has been associated with.
    • size

      public int size()
    • values

      public Collection<TValue> values()
    • keys

      public Set<TKey> keys()