public interface GridMetadataAware extends Serializable
Note that unlike other types of attributes the metadata is explicitly local to VM. Local metadata does not have any distribution semantic and is not specifically distributed in any way. Note, however, that if object that implements this interface gets serialized and deserialized on the remote node the attachments may or may not be carried over (depending on the implementation). All classes that come with GridGain and implement this interface support proper serialization and deserialization.
For example, this may become useful for cache entries or cache transactions. Cache entry attachment can be used whenever entry needs to carry additional context and it is too expensive to keep looking that context up from a separate map by a key. For example, an expiration policy used by caches may add some expiration context to cache entries to properly expire them.
| Modifier and Type | Method and Description |
|---|---|
<V> V |
addMeta(String name,
V val)
Adds a new metadata.
|
<V> V |
addMetaIfAbsent(String name,
Callable<V> c)
Adds given metadata value only if it was absent.
|
<V> V |
addMetaIfAbsent(String name,
V val)
Adds given metadata value only if it was absent.
|
<V> Map<String,V> |
allMeta()
Gets all metadata in this entry.
|
void |
copyMeta(GridMetadataAware from)
Copies all metadata from another instance.
|
void |
copyMeta(Map<String,?> data)
Copies all metadata from given map.
|
boolean |
hasMeta(String name)
Tests whether or not given metadata is set.
|
<V> boolean |
hasMeta(String name,
V val)
Tests whether or not metadata with given name and value is set.
|
<V> V |
meta(String name)
Gets metadata by name.
|
<V> V |
putMetaIfAbsent(String name,
Callable<V> c)
Adds given metadata value only if it was absent.
|
<V> V |
putMetaIfAbsent(String name,
V val)
Adds given metadata value only if it was absent.
|
<V> V |
removeMeta(String name)
Removes metadata by name.
|
<V> boolean |
removeMeta(String name,
V val)
Removes metadata only if its current value is equal to
val passed in. |
<V> boolean |
replaceMeta(String name,
V curVal,
V newVal)
Replaces given metadata with new
newVal value only if its current value
is equal to curVal. |
void copyMeta(GridMetadataAware from)
from - Metadata aware instance to copy metadata from.void copyMeta(Map<String,?> data)
data - Map to copy metadata from.@Nullable <V> V addMeta(String name, V val)
V - Type of the value.name - Metadata name.val - Metadata value.null if there was none.@Nullable <V> V putMetaIfAbsent(String name, V val)
V - Type of the value.name - Metadata name.val - Value to add if it's not attached already.null if new value was put, or current value if put didn't happen.@Nullable <V> V putMetaIfAbsent(String name, Callable<V> c)
V - Type of the value.name - Metadata name.c - Factory closure to produce value to add if it's not attached already.
Not that unlike addMeta(String, 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.null if new value was put, or current value if put didn't happen.<V> V addMetaIfAbsent(String name, V val)
putMetaIfAbsent(String, Callable), this method always returns
the latest value and never previous one.V - Type of the value.name - Metadata name.val - Value to add if it's not attached already.@Nullable <V> V addMetaIfAbsent(String name, @Nullable Callable<V> c)
V - Type of the value.name - Metadata name.c - Factory closure to produce value to add if it's not attached already.
Not that unlike addMeta(String, 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. If null and metadata value is missing - null
will be returned from this method.<V> V meta(String name)
V - Type of the value.name - Metadata name.null.<V> V removeMeta(String name)
V - Type of the value.name - Name of the metadata to remove.null.<V> boolean removeMeta(String name, V val)
val passed in.V - Value type.name - Name of metadata attribute.val - Value to compare.True if value was removed, false otherwise.<V> Map<String,V> allMeta()
V - Type of the value.boolean hasMeta(String name)
name - Name of the metadata to test.<V> boolean hasMeta(String name, V val)
true if
attachment with given name it set and its value is equals to provided value. Otherwise returns
false.V - Type of the value.name - Name of the metadata.val - Value to compare. Cannot be null.true if metadata with given name is set and its value is equals to provided value -
otherwise returns false.<V> boolean replaceMeta(String name, V curVal, V newVal)
newVal value only if its current value
is equal to curVal. Otherwise, it is no-op.name - Name of the metadata.curVal - Current value to check.newVal - New value.true if replacement occurred, false otherwise.Copyright © 2014. All rights reserved.