ConcurrentMap on demand, based on a key value. Works the same as
concurrentMap.computeIfAbsent(key, key -> newInstance(key)), except that it also works on JDK 7.
| Modifier and Type | Class and Description |
|---|---|
| public static class | SingletonMap.
Thrown when |
| public static interface | |
| public static class | SingletonMap.
Thrown when |
| private static class | SingletonMap.
the singleton type V>Wrapper to allow an object instance to be put into a ConcurrentHashMap using putIfAbsent() without requiring the instance to be initialized first, so that putIfAbsent can be performed without wrapping it with a synchronized lock, and so that initialization work is not wasted if an object is already in the map for the key. |
| Modifier and Type | Field and Description |
|---|---|
| private final ConcurrentMap | map
The map. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public List | |
| public V | Returns: The non-null singleton instance, ifnewInstance(Object, LogNode) returned a non-null
instance on this call or a previous call, otherwise throws NullPointerException if this call
or a previous call to newInstance(Object, LogNode) returned null.The key for the singleton. key, final LogNode The log. log, final SingletonMap.if non-null, a factory for creating new instances, otherwise if null, then
newInstanceFactorynewInstance(Object, LogNode) is called instead (this allows new instance creation to be
overridden on a per-instance basis).Check if the given key is in the map, and if so, return the value of |
| public V | Returns: The non-null singleton instance, ifnewInstance(Object, LogNode) returned a non-null
instance on this call or a previous call, otherwise throws NullPointerException if this call
or a previous call to newInstance(Object, LogNode) returned null.The key for the singleton. key, final LogNode The log. log)Check if the given key is in the map, and if so, return the value of |
| public boolean | |
| public abstract V | Returns: The singleton instance. This method must either return a non-null value, or throw an exception of type E.The key for the singleton. key, LogNode The log. log)Construct a new singleton instance. |
| public V | Returns: the old singleton from the map, if one was present, otherwise null.the key key)Remove the singleton for a given key. |
| public List | Returns: the singleton values in the map, skipping over any value for which newInstance() threw an exception or returned null.Get all valid singleton values in the map. |
| map | back to summary |
|---|---|
| private final ConcurrentMap<K, SingletonMap. The map. | |
| SingletonMap | back to summary |
|---|---|
| public SingletonMap() | |
| clear | back to summary |
|---|---|
| public void clear() Clear the map. | |
| entries | back to summary |
|---|---|
| public List Get the map entries.
| |
| get | back to summary |
|---|---|
| public V get(final K key, final LogNode log, final SingletonMap. Check if the given key is in the map, and if so, return the value of
| |
| get | back to summary |
|---|---|
| public V get(final K key, final LogNode log) throws SingletonMap:E, InterruptedException, NullSingletonException, NewInstanceException Check if the given key is in the map, and if so, return the value of
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns true if the map is empty.
| |
| newInstance | back to summary |
|---|---|
| public abstract V newInstance(K key, LogNode log) throws SingletonMap:E, InterruptedException Construct a new singleton instance.
| |
| remove | back to summary |
|---|---|
| public V remove(final K key) throws InterruptedException Remove the singleton for a given key.
| |
| values | back to summary |
|---|---|
| public List Get all valid singleton values in the map.
| |
SingletonMap#newInstance(Object, LogNode) throws an exception.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final long | serialVersionUID
serialVersionUID.
|
| Access | Constructor and Description |
|---|---|
| public < the key type K> | NewInstanceException(final K
the key key, final Throwable the Throwable that was thrown t)Constructor. |
| serialVersionUID | back to summary |
|---|---|
| pack-priv static final long serialVersionUID Hides java. serialVersionUID. | |
| NewInstanceException | back to summary |
|---|---|
| public <K> NewInstanceException(final K key, final Throwable t) Constructor.
| |
| Modifier and Type | Method and Description |
|---|---|
| public V |
| newInstance | back to summary |
|---|---|
| public V newInstance() throws SingletonMap:E, InterruptedException Create a new instance.
| |
SingletonMap#newInstance(Object, LogNode) returns null.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final long | serialVersionUID
serialVersionUID.
|
| Access | Constructor and Description |
|---|---|
| public < the key type K> |
| serialVersionUID | back to summary |
|---|---|
| pack-priv static final long serialVersionUID Hides java. serialVersionUID. | |
| NullSingletonException | back to summary |
|---|---|
| public <K> NullSingletonException(final K key) Constructor.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final CountDownLatch | initialized
Whether or not the singleton has been initialized (the count will have reached 0 if so). |
| private volatile V | singleton
The singleton. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv V | |
| pack-priv void |
| initialized | back to summary |
|---|---|
| private final CountDownLatch initialized Whether or not the singleton has been initialized (the count will have reached 0 if so). | |
| singleton | back to summary |
|---|---|
| private volatile V singleton The singleton.
| |
| SingletonHolder | back to summary |
|---|---|
| private SingletonHolder() | |
| get | back to summary |
|---|---|
| pack-priv V get() throws InterruptedException Get the singleton value.
| |
| set | back to summary |
|---|---|
| pack-priv void set(final V singleton) throws IllegalArgumentException Set the singleton value, and decreases the countdown latch to 0.
| |