org.apache.ignite.internal.cluster

## Class ClusterGroupAdapter

- java.lang.Object
- - org.apache.ignite.internal.cluster.ClusterGroupAdapter

All Implemented Interfaces:
  Externalizable, Serializable, ClusterGroup, ClusterGroupEx

Direct Known Subclasses:
  IgniteClusterImpl

    public class ClusterGroupAdapter
    extends Object
    implements ClusterGroupEx, Externalizable

See Also:
  Serialized Form

### Field Summary

Fields
`protected GridKernalContext` `ctx` Kernal context.
`protected IgnitePredicate<ClusterNode>` `p` Cluster group predicate.
`protected UUID` `subjId` Subject ID.

### Constructor Summary

Constructors
`` `ClusterGroupAdapter()` Required by `Externalizable`.
`protected` `ClusterGroupAdapter(GridKernalContext ctx, UUID subjId, IgnitePredicate<ClusterNode> p)`
`protected` `ClusterGroupAdapter(GridKernalContext ctx, UUID subjId, Set<UUID> ids)`

### Method Summary

All Methods Instance Methods Concrete Methods
`IgniteCompute` `compute()`
`IgniteEvents` `events()`
`ExecutorService` `executorService()`
`ClusterGroup` `forAttribute(String name, Object val)` Creates a new cluster group for nodes containing given name and value specified in user attributes.
`ClusterGroup` `forCacheNodes(String cacheName)` Creates a cluster group for all nodes that have cache with specified name, either in client or server modes.
`ClusterGroup` `forCacheNodes(String cacheName, boolean affNodes, boolean nearNodes, boolean clientNodes)`
`ClusterGroup` `forClientNodes(String cacheName)` Creates a cluster group for all client nodes that access cache with the specified name.
`ClusterGroup` `forClients()` Creates a cluster group of nodes started in client mode.
`ClusterGroup` `forDaemons()` Gets a cluster group consisting from the daemon nodes.
`ClusterGroup` `forDataNodes(String cacheName)` Creates a cluster group for all data nodes that have the cache with the specified name running.
`ClusterGroup` `forHost(ClusterNode node)` Gets cluster group consisting from the nodes in this cluster group residing on the same host as the given node.
`ClusterGroup` `forHost(String host, String... hosts)` Gets cluster group consisting from the nodes running on the hosts specified.
`ClusterGroup` `forIgfsMetadataDataNodes(String igfsName, String metaCacheName)` Create projection for IGFS server nodes.
`ClusterGroup` `forNode(ClusterNode node, ClusterNode... nodes)` Creates a cluster group for the given node.
`ClusterGroup` `forNodeId(UUID id, UUID... ids)` Creates a cluster group for a node with the specified ID.
`ClusterGroup` `forNodeIds(Collection<UUID> ids)` Creates a cluster group over nodes with specified node IDs.
`ClusterGroup` `forNodes(Collection<? extends ClusterNode> nodes)` Creates a cluster group over a given set of nodes.
`ClusterGroup` `forOldest()` Creates a cluster group with one oldest node from the current cluster group.
`ClusterGroup` `forOthers(ClusterGroup grp)` Creates a cluster group for nodes not included into the given cluster group.
`ClusterGroup` `forOthers(ClusterNode node, ClusterNode... nodes)` Creates a cluster group for nodes other than the given nodes.
`ClusterGroup` `forPredicate(IgnitePredicate<ClusterNode> p)` Creates a new cluster group which includes all nodes that pass the given predicate filter.
`ClusterGroup` `forRandom()` Creates a cluster group with one random node from the current cluster group.
`ClusterGroup` `forRemotes()` Gets cluster group consisting from the nodes in this cluster group excluding the local node.
`ClusterGroup` `forServers()` Creates a cluster group of nodes started in server mode.
`ClusterGroupEx` `forSubjectId(UUID subjId)` Creates projection for specified subject ID.
`ClusterGroup` `forYoungest()` Creates a cluster group with one youngest node in the current cluster group.
`protected void` `guard()` `ctx.gateway().readLock()`
`Collection<String>` `hostNames()` Gets the read-only collection of hostnames in this cluster group.
`Ignite` `ignite()` Gets instance of grid.
`IgniteMessaging` `message()`
`ClusterMetrics` `metrics()` Gets a metrics snapshot for this cluster group.
`ClusterNode` `node()` Gets first node from the list of nodes in this cluster group.
`ClusterNode` `node(UUID id)` Gets a node for given ID from this cluster group.
`Collection<ClusterNode>` `nodes()` Gets the read-only collection of nodes in this cluster group.
`IgnitePredicate<ClusterNode>` `predicate()` Gets predicate that defines a subset of nodes for this cluster group.
`void` `readExternal(ObjectInput in)`
`protected Object` `readResolve()` Reconstructs object on unmarshalling.
`IgniteServices` `services()`
`void` `setKernalContext(GridKernalContext ctx)` Sets kernal context.
`protected void` `unguard()` `ctx.gateway().readUnlock()`
`void` `writeExternal(ObjectOutput out)`

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

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

### Field Detail

#### ctx

    protected transient GridKernalContext ctx

Kernal context.

#### subjId

    protected UUID subjId

Subject ID.

#### p

    protected IgnitePredicate<ClusterNode> p

Cluster group predicate.

### Constructor Detail

#### ClusterGroupAdapter

    public ClusterGroupAdapter()

Required by `Externalizable`.

#### ClusterGroupAdapter

    protected ClusterGroupAdapter(@Nullable
                                  GridKernalContext ctx,
                                  @Nullable
                                  UUID subjId,
                                  @Nullable
                                  IgnitePredicate<ClusterNode> p)

Parameters:
  `subjId` - Subject ID.
  `ctx` - Kernal context.
  `p` - Predicate.

#### ClusterGroupAdapter

    protected ClusterGroupAdapter(@Nullable
                                  GridKernalContext ctx,
                                  @Nullable
                                  UUID subjId,
                                  Set<UUID> ids)

Parameters:
  `ctx` - Kernal context.
  `subjId` - Subject ID.
  `ids` - Node IDs.

### Method Detail

#### guard

    protected void guard()

`ctx.gateway().readLock()`

#### unguard

    protected void unguard()

`ctx.gateway().readUnlock()`

#### setKernalContext

    public void setKernalContext(GridKernalContext ctx)

Sets kernal context.

Parameters:
  `ctx` - Kernal context to set.

#### ignite

    public final Ignite ignite()

Gets instance of grid.

Specified by:
  `ignite` in interface `ClusterGroup`
Returns:
  Grid instance.

#### compute

    public final IgniteCompute compute()

Returns:
  `IgniteCompute` for this cluster group.

#### message

    public final IgniteMessaging message()

Returns:
  `IgniteMessaging` for this cluster group.

#### events

    public final IgniteEvents events()

Returns:
  `IgniteEvents` for this cluster group.

#### services

    public IgniteServices services()

Returns:
  `IgniteServices` for this cluster group.

#### executorService

    public ExecutorService executorService()

Returns:
  `ExecutorService` for this cluster group.

#### metrics

    public final ClusterMetrics metrics()

Gets a metrics snapshot for this cluster group.

Specified by:
  `metrics` in interface `ClusterGroup`
Returns:
  Metrics snapshot.

#### nodes

    public Collection<ClusterNode> nodes()

Gets the read-only collection of nodes in this cluster group.

Specified by:
  `nodes` in interface `ClusterGroup`
Returns:
  All nodes in this cluster group.

#### hostNames

    public Collection<String> hostNames()

Gets the read-only collection of hostnames in this cluster group.

Specified by:
  `hostNames` in interface `ClusterGroup`
Returns:
  All hostnames in this cluster group.

#### node

    public final ClusterNode node(UUID id)

Gets a node for given ID from this cluster group.

Specified by:
  `node` in interface `ClusterGroup`
Parameters:
  `id` - Node ID.
Returns:
  Node with given ID from this cluster group or `null`, if such node does not exist.

#### node

    public ClusterNode node()

Gets first node from the list of nodes in this cluster group. This method is specifically useful for cluster groups with one node only.

Specified by:
  `node` in interface `ClusterGroup`
Returns:
  First node from the list of nodes in this cluster group or `null` if the cluster group is empty.

#### predicate

    public IgnitePredicate<ClusterNode> predicate()

Gets predicate that defines a subset of nodes for this cluster group.

Specified by:
  `predicate` in interface `ClusterGroup`
Returns:
  Predicate that defines a subset of nodes for this cluster group.

#### forPredicate

    public ClusterGroup forPredicate(IgnitePredicate<ClusterNode> p)

Creates a new cluster group which includes all nodes that pass the given predicate filter.

Specified by:
  `forPredicate` in interface `ClusterGroup`
Parameters:
  `p` - Predicate filter for nodes to include into the cluster group.
Returns:
  Cluster group for nodes that passed the predicate filter.

#### forAttribute

    public final ClusterGroup forAttribute(String name,
                                           @Nullable
                                           Object val)

Creates a new cluster group for nodes containing given name and value specified in user attributes.

User attributes for every node are optional and can be specified in grid node configuration. See `IgniteConfiguration.getUserAttributes()` for more information.

Specified by:
  `forAttribute` in interface `ClusterGroup`
Parameters:
  `name` - Name of the attribute.
  `val` - Optional attribute value to match.
Returns:
  Cluster group for nodes containing specified attribute.

#### forServers

    public ClusterGroup forServers()

Creates a cluster group of nodes started in server mode.

Specified by:
  `forServers` in interface `ClusterGroup`
Returns:
  Cluster group of nodes started in server mode.
See Also:
  `Ignition.setClientMode(boolean)`, `IgniteConfiguration.setClientMode(boolean)`

#### forClients

    public ClusterGroup forClients()

Creates a cluster group of nodes started in client mode.

Specified by:
  `forClients` in interface `ClusterGroup`
Returns:
  Cluster group of nodes started in client mode.
See Also:
  `Ignition.setClientMode(boolean)`, `IgniteConfiguration.setClientMode(boolean)`

#### forNode

    public final ClusterGroup forNode(ClusterNode node,
                                      ClusterNode... nodes)

Creates a cluster group for the given node.

Specified by:
  `forNode` in interface `ClusterGroup`
Parameters:
  `node` - Node to create cluster group for.
  `nodes` - Optional additional nodes to include into the cluster group.
Returns:
  Cluster group for the given nodes.

#### forNodes

    public final ClusterGroup forNodes(Collection<? extends ClusterNode> nodes)

Creates a cluster group over a given set of nodes.

Specified by:
  `forNodes` in interface `ClusterGroup`
Parameters:
  `nodes` - Collection of nodes to create the cluster group from.
Returns:
  Cluster group for the provided grid nodes.

#### forNodeId

    public final ClusterGroup forNodeId(UUID id,
                                        UUID... ids)

Creates a cluster group for a node with the specified ID.

Specified by:
  `forNodeId` in interface `ClusterGroup`
Parameters:
  `id` - Node ID to get the cluster group for.
  `ids` - Optional additional node IDs to include into the cluster group.
Returns:
  Cluster group over the node with the specified node IDs.

#### forNodeIds

    public final ClusterGroup forNodeIds(Collection<UUID> ids)

Creates a cluster group over nodes with specified node IDs.

Specified by:
  `forNodeIds` in interface `ClusterGroup`
Parameters:
  `ids` - Collection of node IDs.
Returns:
  Cluster group over nodes with the specified node IDs.

#### forOthers

    public final ClusterGroup forOthers(ClusterNode node,
                                        ClusterNode... nodes)

Creates a cluster group for nodes other than the given nodes.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `node` - Node to exclude from the new cluster group.
  `nodes` - Optional additional nodes to exclude from the cluster group.
Returns:
  Cluster group that will contain all nodes from the original cluster group excluding the given nodes.

#### forOthers

    public ClusterGroup forOthers(ClusterGroup grp)

Creates a cluster group for nodes not included into the given cluster group.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `grp` - Cluster group to exclude from the new cluster group.
Returns:
  Cluster group for nodes not included into the given cluster group.

#### forRemotes

    public final ClusterGroup forRemotes()

Gets cluster group consisting from the nodes in this cluster group excluding the local node.

Specified by:
  `forRemotes` in interface `ClusterGroup`
Returns:
  Cluster group consisting from the nodes in this cluster group excluding the local node.

#### forCacheNodes

    public final ClusterGroup forCacheNodes(String cacheName)

Creates a cluster group for all nodes that have cache with specified name, either in client or server modes.

Specified by:
  `forCacheNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Cluster group over nodes that have specified cache running.

#### forDataNodes

    public final ClusterGroup forDataNodes(String cacheName)

Creates a cluster group for all data nodes that have the cache with the specified name running.

Specified by:
  `forDataNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Cluster group over nodes that have the cache with the specified name running.

#### forClientNodes

    public final ClusterGroup forClientNodes(String cacheName)

Creates a cluster group for all client nodes that access cache with the specified name.

Specified by:
  `forClientNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Cluster group over nodes that have the specified cache running.

#### forCacheNodes

    public ClusterGroup forCacheNodes(String cacheName,
                                      boolean affNodes,
                                      boolean nearNodes,
                                      boolean clientNodes)

Specified by:
  `forCacheNodes` in interface `ClusterGroupEx`
Parameters:
  `cacheName` - Cache name.
  `affNodes` - Flag to include affinity nodes.
  `nearNodes` - Flag to include near nodes.
  `clientNodes` - Flag to include client nodes.
Returns:
  Cluster group.

#### forIgfsMetadataDataNodes

    public ClusterGroup forIgfsMetadataDataNodes(String igfsName,
                                                 String metaCacheName)

Create projection for IGFS server nodes.

Specified by:
  `forIgfsMetadataDataNodes` in interface `ClusterGroupEx`
Parameters:
  `igfsName` - IGFS name.
  `metaCacheName` - Metadata cache name.
Returns:
  Cluster group.

#### forHost

    public final ClusterGroup forHost(ClusterNode node)

Gets cluster group consisting from the nodes in this cluster group residing on the same host as the given node.

Specified by:
  `forHost` in interface `ClusterGroup`
Parameters:
  `node` - Node to select the host for.
Returns:
  Cluster group for nodes residing on the same host as the specified node.

#### forHost

    public final ClusterGroup forHost(String host,
                                      String... hosts)

Gets cluster group consisting from the nodes running on the hosts specified.

Specified by:
  `forHost` in interface `ClusterGroup`
Parameters:
  `host` - Host name to get nodes to put in cluster
  `hosts` - Host names to get nodes to put in cluster.
Returns:
  Cluster group for nodes residing on the hosts specified.

#### forDaemons

    public final ClusterGroup forDaemons()

Gets a cluster group consisting from the daemon nodes.

Daemon nodes are the usual grid nodes that participate in topology but not visible on the main APIs, i.e. they are not part of any cluster group. The only way to see daemon nodes is to use this method.

Daemon nodes are used primarily for management and monitoring functionality that is build on Ignite and needs to participate in the topology, but also needs to be excluded from the "normal" topology, so that it won't participate in the task execution or in-memory data grid storage.

Specified by:
  `forDaemons` in interface `ClusterGroup`
Returns:
  Cluster group consisting from the daemon nodes.

#### forRandom

    public final ClusterGroup forRandom()

Creates a cluster group with one random node from the current cluster group.

Specified by:
  `forRandom` in interface `ClusterGroup`
Returns:
  Cluster group containing one random node from the current cluster group.

#### forOldest

    public ClusterGroup forOldest()

Creates a cluster group with one oldest node from the current cluster group. The resulting cluster group is dynamic and will always pick the next oldest node if the previous one leaves topology even after the cluster group has been created.

Use `ClusterGroup.node()` method to get the oldest node.

Specified by:
  `forOldest` in interface `ClusterGroup`
Returns:
  Cluster group containing one oldest node from the current cluster group.

#### forYoungest

    public ClusterGroup forYoungest()

Creates a cluster group with one youngest node in the current cluster group. The resulting cluster group is dynamic and will always pick the newest node in the topology, even if more nodes entered after the cluster group has been created.

Specified by:
  `forYoungest` in interface `ClusterGroup`
Returns:
  Cluster group containing one youngest node from the current cluster group.

#### forSubjectId

    public ClusterGroupEx forSubjectId(UUID subjId)

Creates projection for specified subject ID.

Specified by:
  `forSubjectId` in interface `ClusterGroupEx`
Parameters:
  `subjId` - Subject ID.
Returns:
  Cluster group.

#### writeExternal

    public void writeExternal(ObjectOutput out)
                       throws IOException

Specified by:
  `writeExternal` in interface `Externalizable`
Throws:
  `IOException`

#### readExternal

    public void readExternal(ObjectInput in)
                      throws IOException,
                             ClassNotFoundException

Specified by:
  `readExternal` in interface `Externalizable`
Throws:
  `IOException`
  `ClassNotFoundException`

#### readResolve

    protected Object readResolve()
                          throws ObjectStreamException

Reconstructs object on unmarshalling.

Returns:
  Reconstructed object.
Throws:
  `ObjectStreamException` - Thrown in case of unmarshalling error.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.4.0
Release Date | : March 5 2018