org.apache.ignite.internal

## Class ClusterGroupAdapter

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

All Implemented Interfaces:
  Externalizable, Serializable, ClusterGroup, ClusterGroupEx

Direct Known Subclasses:
  IgniteKernal

    public class ClusterGroupAdapter
    extends Object
    implements ClusterGroupEx, Externalizable

See Also:
  Serialized Form

### Field Summary

Fields
`protected GridKernalContext` `ctx` Kernal context.
`protected IgnitePredicate<ClusterNode>` `p` Projection predicate.

### Constructor Summary

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

### Method Summary

Methods
`IgniteCompute` `compute()`
`IgniteEvents` `events()`
`ExecutorService` `executorService()`
`ClusterGroup` `forAttribute(String name, String val)` Creates projection for nodes containing given name and value specified in user attributes.
`ClusterGroup` `forCacheNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running.
`ClusterGroup` `forCacheNodes(String cacheName, Set<CacheDistributionMode> distributionModes)`
`ClusterGroup` `forClientNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.CLIENT_ONLY` or `CacheDistributionMode.NEAR_ONLY`.
`ClusterGroup` `forDaemons()` Gets projection consisting from the daemon nodes in this projection.
`ClusterGroup` `forDataNodes(String cacheName)` Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.PARTITIONED_ONLY` or `CacheDistributionMode.NEAR_PARTITIONED`.
`ClusterGroup` `forHost(ClusterNode node)` Gets grid projection consisting from the nodes in this projection residing on the same host as given node.
`ClusterGroup` `forNode(ClusterNode node, ClusterNode... nodes)` Creates a grid projection for the given node.
`ClusterGroup` `forNodeId(UUID id, UUID... ids)` Creates a grid projection for a node with specified ID.
`ClusterGroup` `forNodeIds(Collection<UUID> ids)` Creates a grid projection over nodes with specified node IDs.
`ClusterGroup` `forNodes(Collection<? extends ClusterNode> nodes)` Creates a grid projection over a given set of nodes.
`ClusterGroup` `forOldest()` Creates grid projection with one oldest node in the current projection.
`ClusterGroup` `forOthers(ClusterGroup prj)` Creates a grid projection for nodes not included into given projection.
`ClusterGroup` `forOthers(ClusterNode node, ClusterNode... nodes)` Creates a grid projection for nodes other than given nodes.
`ClusterGroup` `forPredicate(IgnitePredicate<ClusterNode> p)` Creates a grid projection which includes all nodes that pass the given predicate filter.
`ClusterGroup` `forRandom()` Creates grid projection with one random node from current projection.
`ClusterGroup` `forRemotes()` Gets grid projection consisting from the nodes in this projection excluding the local node.
`ClusterGroup` `forStreamer(String streamerName, String... streamerNames)` Creates projection for all nodes that have streamer with specified name running.
`ClusterGroupEx` `forSubjectId(UUID subjId)` Creates projection for specified subject ID.
`ClusterGroup` `forYoungest()` Creates grid projection with one youngest node in the current projection.
`protected void` `guard()` `ctx.gateway().readLock()`
`Ignite` `ignite()` Gets instance of grid.
`protected void` `lightCheck()` `ctx.gateway().lightCheck()`
`IgniteMessaging` `message()`
`ClusterMetrics` `metrics()` Gets a metrics snapshot for this projection.
`ClusterNode` `node()` Gets first node from the list of nodes in this projection.
`ClusterNode` `node(UUID id)` Gets a node for given ID from this grid projection.
`Collection<ClusterNode>` `nodes()` Gets read-only collections of nodes in this projection.
`IgnitePredicate<ClusterNode>` `predicate()` Gets predicate that defines a subset of nodes for this projection.
`void` `readExternal(ObjectInput in)`
`protected Object` `readResolve()` Reconstructs object on unmarshalling.
`IgniteServices` `services()`
`protected 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.

#### p

    protected IgnitePredicate<ClusterNode> p

Projection predicate.

### Constructor Detail

#### ClusterGroupAdapter

    public ClusterGroupAdapter()

Required by `Externalizable`.

#### ClusterGroupAdapter

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

Parameters:
  `parent` - Parent of this projection.
  `ctx` - Grid kernal context.
  `p` - Predicate.

#### ClusterGroupAdapter

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

Parameters:
  `parent` - Parent of this projection.
  `ctx` - Grid kernal context.
  `ids` - Node IDs.

### Method Detail

#### guard

    protected void guard()

`ctx.gateway().readLock()`

#### unguard

    protected void unguard()

`ctx.gateway().readUnlock()`

#### lightCheck

    protected void lightCheck()

`ctx.gateway().lightCheck()`

#### setKernalContext

    protected 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 projection.

#### message

    public final IgniteMessaging message()

Returns:
  `IgniteMessaging` for this projection.

#### events

    public final IgniteEvents events()

Returns:
  `IgniteEvents` for this projection.

#### services

    public IgniteServices services()

Returns:
  `IgniteServices` for this projection.

#### executorService

    public ExecutorService executorService()

Returns:
  `ExecutorService` for this projection.

#### metrics

    public final ClusterMetrics metrics()

Gets a metrics snapshot for this projection.

Specified by:
  `metrics` in interface `ClusterGroup`
Returns:
  Grid projection metrics snapshot.

#### nodes

    public Collection<ClusterNode> nodes()

Gets read-only collections of nodes in this projection.

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

#### node

    public final ClusterNode node(UUID id)

Gets a node for given ID from this grid projection.

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

#### node

    public ClusterNode node()

Gets first node from the list of nodes in this projection. This method is specifically useful for projection over one node only.

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

#### predicate

    public final IgnitePredicate<ClusterNode> predicate()

Gets predicate that defines a subset of nodes for this projection.

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

#### forPredicate

    public final ClusterGroup forPredicate(IgnitePredicate<ClusterNode> p)

Creates a grid projection 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 this projection.
Returns:
  Grid projection for nodes that passed the predicate filter.

#### forAttribute

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

Creates projection 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:
  Grid projection for nodes containing specified attribute.

#### forNode

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

Creates a grid projection for the given node.

Specified by:
  `forNode` in interface `ClusterGroup`
Parameters:
  `node` - Node to get projection for.
  `nodes` - Optional additional nodes to include into projection.
Returns:
  Grid projection for the given node.

#### forNodes

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

Creates a grid projection over a given set of nodes.

Specified by:
  `forNodes` in interface `ClusterGroup`
Parameters:
  `nodes` - Collection of nodes to create a projection from.
Returns:
  Projection over provided grid nodes.

#### forNodeId

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

Creates a grid projection for a node with specified ID.

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

#### forNodeIds

    public final ClusterGroup forNodeIds(Collection<UUID> ids)

Creates a grid projection over nodes with specified node IDs.

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

#### forOthers

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

Creates a grid projection for nodes other than given nodes.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `node` - Node to exclude from new grid projection.
  `nodes` - Optional additional nodes to exclude from projection.
Returns:
  Projection that will contain all nodes that original projection contained excluding given nodes.

#### forOthers

    public ClusterGroup forOthers(ClusterGroup prj)

Creates a grid projection for nodes not included into given projection.

Specified by:
  `forOthers` in interface `ClusterGroup`
Parameters:
  `prj` - Projection to exclude from new grid projection.
Returns:
  Projection for nodes not included into given projection.

#### forRemotes

    public final ClusterGroup forRemotes()

Gets grid projection consisting from the nodes in this projection excluding the local node.

Specified by:
  `forRemotes` in interface `ClusterGroup`
Returns:
  Grid projection consisting from the nodes in this projection excluding the local node, if any.

#### forCacheNodes

    public final ClusterGroup forCacheNodes(@Nullable
                             String cacheName)

Creates projection for all nodes that have cache with specified name running.

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

#### forDataNodes

    public final ClusterGroup forDataNodes(@Nullable
                            String cacheName)

Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.PARTITIONED_ONLY` or `CacheDistributionMode.NEAR_PARTITIONED`.

Specified by:
  `forDataNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Projection over nodes that have specified cache running.
See Also:
  `CacheConfiguration.getDistributionMode()`

#### forClientNodes

    public final ClusterGroup forClientNodes(@Nullable
                              String cacheName)

Creates projection for all nodes that have cache with specified name running and cache distribution mode is `CacheDistributionMode.CLIENT_ONLY` or `CacheDistributionMode.NEAR_ONLY`.

Specified by:
  `forClientNodes` in interface `ClusterGroup`
Parameters:
  `cacheName` - Cache name.
Returns:
  Projection over nodes that have specified cache running.
See Also:
  `CacheConfiguration.getDistributionMode()`

#### forStreamer

    public final ClusterGroup forStreamer(@Nullable
                           String streamerName,
                           @Nullable
                           String... streamerNames)

Creates projection for all nodes that have streamer with specified name running.

Specified by:
  `forStreamer` in interface `ClusterGroup`
Parameters:
  `streamerName` - Streamer name.
  `streamerNames` - Optional additional streamer names to include into projection.
Returns:
  Projection over nodes that have specified streamer running.

#### forCacheNodes

    public ClusterGroup forCacheNodes(@Nullable
                             String cacheName,
                             Set<CacheDistributionMode> distributionModes)

Specified by:
  `forCacheNodes` in interface `ClusterGroupEx`
Parameters:
  `cacheName` - Cache name.
  `distributionModes` - Cache distribution modes.
Returns:
  Cluster group.

#### forHost

    public final ClusterGroup forHost(ClusterNode node)

Gets grid projection consisting from the nodes in this projection residing on the same host as given node.

Specified by:
  `forHost` in interface `ClusterGroup`
Parameters:
  `node` - Node residing on the host for which projection is created.
Returns:
  Projection for nodes residing on the same host as passed in node.

#### forDaemons

    public final ClusterGroup forDaemons()

Gets projection consisting from the daemon nodes in this projection.

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 projections. 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 "normal" topology so that it won't participate in task execution or in-memory data grid storage.

Specified by:
  `forDaemons` in interface `ClusterGroup`
Returns:
  Grid projection consisting from the daemon nodes in this projection.

#### forRandom

    public final ClusterGroup forRandom()

Creates grid projection with one random node from current projection.

Specified by:
  `forRandom` in interface `ClusterGroup`
Returns:
  Grid projection with one random node from current projection.

#### forOldest

    public ClusterGroup forOldest()

Creates grid projection with one oldest node in the current projection. The resulting projection is dynamic and will always pick the next oldest node if the previous one leaves topology even after the projection has been created.

Specified by:
  `forOldest` in interface `ClusterGroup`
Returns:
  Grid projection with one oldest node from the current projection.

#### forYoungest

    public ClusterGroup forYoungest()

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

Specified by:
  `forYoungest` in interface `ClusterGroup`
Returns:
  Grid projection with one youngest node from the current projection.

#### forSubjectId

    public ClusterGroupEx forSubjectId(UUID subjId)

Creates projection for specified subject ID.

Specified by:
  `forSubjectId` in interface `ClusterGroupEx`
Parameters:
  `subjId` - Subject ID.
Returns:
  Internal projection.

#### 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.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015