Class GridMetadataAwareAdapter
- java.lang.Object
-
- org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter
-
- Direct Known Subclasses:
GridCacheMapEntry,GridDeployment,IgniteTxAdapter,TcpDiscoveryNode
public class GridMetadataAwareAdapter extends Object
Convenient adapter for working with metadata.Thread Safety
This class provides necessary synchronization for thread-safe access.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGridMetadataAwareAdapter.EntryKeyEnum stored predefined keys.
-
Constructor Summary
Constructors Constructor Description GridMetadataAwareAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> VaddMeta(int key, V val)Adds a new metadata.<V> VaddMetaIfAbsent(int key, @NotNull Callable<V> c)Adds given metadata value only if it was absent.<V> VaddMetaIfAbsent(int key, V val)Adds given metadata value only if it was absent.<V> Object[]allMeta()Gets all metadata in this entry.Objectclone()voidcopyMeta(Object[] data)Copies all metadata from given map.voidcopyMeta(GridMetadataAwareAdapter from)Copies all metadata from another instance.booleanhasMeta(int key)Tests whether or not given metadata is set.<V> booleanhasMeta(int key, V val)Tests whether or not given metadata is set.<V> Vmeta(int key)Gets metadata by name.<V> VputMetaIfAbsent(int key, V val)Adds given metadata value only if it was absent.voidremoveAllMeta()Removes all meta.<V> VremoveMeta(int key)Removes metadata by key.<V> booleanremoveMeta(int key, V val)Removes metadata only if its current value is equal tovalpassed in.<V> booleanreplaceMeta(int key, V curVal, V newVal)Replaces given metadata with newnewValvalue only if its current value is equal tocurVal.
-
-
-
Method Detail
-
copyMeta
public void copyMeta(GridMetadataAwareAdapter from)
Copies all metadata from another instance.- Parameters:
from- Metadata aware instance to copy metadata from.
-
copyMeta
public void copyMeta(Object[] data)
Copies all metadata from given map.- Parameters:
data- Map to copy metadata from.
-
addMeta
@Nullable public <V> V addMeta(int key, V val)Adds a new metadata.- Type Parameters:
V- Type of the value.- Parameters:
key- Metadata key.val- Metadata value.- Returns:
- Metadata previously associated with given name, or
nullif there was none.
-
meta
@Nullable public <V> V meta(int key)
Gets metadata by name.- Type Parameters:
V- Type of the value.- Parameters:
key- Metadata key.- Returns:
- Metadata value or
null.
-
removeMeta
@Nullable public <V> V removeMeta(int key)
Removes metadata by key.- Type Parameters:
V- Type of the value.- Parameters:
key- Name of the metadata to remove.- Returns:
- Value of removed metadata or
null.
-
removeMeta
public <V> boolean removeMeta(int key, V val)Removes metadata only if its current value is equal tovalpassed in.- Type Parameters:
V- Value type.- Parameters:
key- Name of metadata attribute.val- Value to compare.- Returns:
Trueif value was removed,falseotherwise.
-
allMeta
public <V> Object[] allMeta()
Gets all metadata in this entry.- Type Parameters:
V- Type of the value.- Returns:
- All metadata in this entry.
-
removeAllMeta
public void removeAllMeta()
Removes all meta.
-
hasMeta
public boolean hasMeta(int key)
Tests whether or not given metadata is set.- Parameters:
key- key of the metadata to test.- Returns:
- Whether or not given metadata is set.
-
hasMeta
public <V> boolean hasMeta(int key, V val)Tests whether or not given metadata is set.- Parameters:
key- Key of the metadata to test.- Returns:
- Whether or not given metadata is set.
-
putMetaIfAbsent
@Nullable public <V> V putMetaIfAbsent(int key, V val)Adds given metadata value only if it was absent.- Type Parameters:
V- Type of the value.- Parameters:
key- Metadata key.val- Value to add if it's not attached already.- Returns:
nullif new value was put, or current value if put didn't happen.
-
addMetaIfAbsent
public <V> V addMetaIfAbsent(int key, V val)Adds given metadata value only if it was absent. This method always returns the latest value and never previous one.- Type Parameters:
V- Type of the value.- Parameters:
key- Metadata key.val- Value to add if it's not attached already.- Returns:
- The value of the metadata after execution of this method.
-
addMetaIfAbsent
@Nullable public <V> V addMetaIfAbsent(int key, @NotNull @NotNull Callable<V> c)Adds given metadata value only if it was absent.- Type Parameters:
V- Type of the value.- Parameters:
key- Metadata key.c- Factory closure to produce value to add if it's not attached already. Not that unlikeaddMeta(int, Object)method the factory closure will not be called unless the value is required and therefore value will only be created when it is actually needed. Ifnulland metadata value is missing -nullwill be returned from this method.- Returns:
- The value of the metadata after execution of this method.
-
replaceMeta
public <V> boolean replaceMeta(int key, V curVal, V newVal)Replaces given metadata with newnewValvalue only if its current value is equal tocurVal. Otherwise, it is no-op.- Parameters:
key- Key of the metadata.curVal- Current value to check.newVal- New value.- Returns:
trueif replacement occurred,falseotherwise.
-
-