org.apache.ignite.internal.util.lang

## 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
`static class` `GridMetadataAwareAdapter.EntryKey` Enum stored predefined keys.

### Constructor Summary

Constructors
Constructor and Description
`GridMetadataAwareAdapter()`

### Method Summary

All Methods Instance Methods Concrete Methods
`<V> V` `addMeta(int key, V val)` Adds a new metadata.
`<V> V` `addMetaIfAbsent(int key, @Nullable Callable<V> c)` Adds given metadata value only if it was absent.
`<V> V` `addMetaIfAbsent(int key, V val)` Adds given metadata value only if it was absent.
`<V> Object[]` `allMeta()` Gets all metadata in this entry.
`Object` `clone()`
`void` `copyMeta(GridMetadataAwareAdapter from)` Copies all metadata from another instance.
`void` `copyMeta(Object[] data)` Copies all metadata from given map.
`boolean` `hasMeta(int key)` Tests whether or not given metadata is set.
`<V> boolean` `hasMeta(int key, V val)` Tests whether or not given metadata is set.
`<V> V` `meta(int key)` Gets metadata by name.
`<V> V` `putMetaIfAbsent(int key, V val)` Adds given metadata value only if it was absent.
`void` `removeAllMeta()` Removes all meta.
`<V> V` `removeMeta(int key)` Removes metadata by key.
`<V> boolean` `removeMeta(int key, V val)` Removes metadata only if its current value is equal to `val` passed in.
`<V> boolean` `replaceMeta(int key, V curVal, V newVal)` Replaces given metadata with new `newVal` value only if its current value is equal to `curVal`.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### GridMetadataAwareAdapter

    public GridMetadataAwareAdapter()

### 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 `null` if 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 to `val` passed in.

Type Parameters:
  `V` - Value type.
Parameters:
  `key` - Name of metadata attribute.
  `val` - Value to compare.
Returns:
  `True` if value was removed, `false` otherwise.

#### 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:
  `null` if 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,
                                           @Nullable
                                           @Nullable 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 unlike `addMeta(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. If `null` and metadata value is missing - `null` will 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 new `newVal` value only if its current value is equal to `curVal`. Otherwise, it is no-op.

Parameters:
  `key` - Key of the metadata.
  `curVal` - Current value to check.
  `newVal` - New value.
Returns:
  `true` if replacement occurred, `false` otherwise.

#### clone

    public Object clone()

Overrides:
  `clone` in class `Object`

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.13.0
Release Date | : April 20 2022