org.apache.ignite.cluster

## Interface ClusterNode

All Known Implementing Classes:
  TcpDiscoveryNode

    public interface ClusterNode

Interface representing a single grid node. Use `attribute(String)` or `metrics()` to get static and dynamic information about remote nodes. `GridNode` list, which includes all nodes within task topology, is provided to `ComputeTask.map(List, Object)` method. You can also get a handle on discovered nodes by calling any of the following methods:

- `IgniteCluster.localNode()`

# Grid Node Attributes

You can use grid node attributes to provide static information about a node. This information is initialized once within grid, during node startup, and remains the same throughout the lifetime of a node. Use `IgniteConfiguration.getUserAttributes()` method to initialize your custom node attributes at startup. Here is an example of how to assign an attribute to a node at startup:

     <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
         ...
         <property name="userAttributes">
             <map>
                 <entry key="worker" value="true"/>
             </map>
         </property>
         ...
     </bean>

The system adds the following attributes automatically:

- `{@link System#getProperties()}` - All system properties.
- `{@link System#getenv(String)}` - All environment properties.
- `org.ignite.build.ver` - Ignite build version.
- `org.apache.ignite.jit.name` - Name of JIT compiler used.
- `org.apache.ignite.net.itf.name` - Name of network interface.
- `org.apache.ignite.user.name` - Operating system user name.
- `org.apache.ignite.ignite.name` - Grid name (see `Ignite.name()`).
- `spiName.org.apache.ignite.spi.class` - SPI implementation class for every SPI, where `spiName` is the name of the SPI (see `IgniteSpi.getName()`.
- `spiName.org.apache.ignite.spi.ver` - SPI version for every SPI, where `spiName` is the name of the SPI (see `IgniteSpi.getName()`.

Note that all System and Environment properties for all nodes are automatically included into node attributes. This gives you an ability to get any information specified in `System.getProperties()` about any node. So for example, in order to print out information about Operating System for all nodes you would do the following:

     for (GridNode node : G.grid().nodes()) {
         System.out.println("Operating system name: " + node.getAttribute("os.name"));
         System.out.println("Operating system architecture: " + node.getAttribute("os.arch"));
         System.out.println("Operating system version: " + node.getAttribute("os.version"));
     }

This interface provide a system view on the node instance. All user-level APIs work with `ClusterNode` interface that provides much more functionality and extends this interface. Consult `ClusterNode` for more information.

# Grid Node Metrics

Grid node metrics (see `metrics()`) are updated frequently for all nodes and can be used to get dynamic information about a node. The frequency of update is often directly related to the heartbeat exchange between nodes. So if, for example, default `TcpDiscoverySpi` is used, the metrics data will be updated every `2` seconds by default.

Grid node metrics provide information about other nodes that can frequently change, such as Heap and Non-Heap memory utilization, CPU load, number of active and waiting grid jobs, etc... This information can become useful during job collision resolution or `ComputeTask.map(List, Object)` operation when jobs are assigned to remote nodes for execution. For example, you can only pick nodes that don't have any jobs waiting to be executed.

Local node metrics are registered as `MBean` and can be accessed from any JMX management console. The simplest way is to use standard `jconsole` that comes with JDK as it also provides ability to view any node parameter as a graph.

### Method Summary

Methods
`Collection<String>` `addresses()` Gets collection of addresses this node is known by.
`<T> T` `attribute(String name)` Gets a node attribute.
`Map<String,Object>` `attributes()` Gets all node attributes.
`Object` `consistentId()` Gets consistent globally unique node ID.
`Collection<String>` `hostNames()` Gets collection of host names this node is known by.
`UUID` `id()` Gets globally unique node ID.
`boolean` `isClient()` Tests whether or not this node is a client node.
`boolean` `isDaemon()` Tests whether or not this node is a daemon.
`boolean` `isLocal()` Tests whether or not this node is a local node.
`ClusterMetrics` `metrics()` Gets metrics snapshot for this node.
`long` `order()` Node order within grid topology.
`IgniteProductVersion` `version()` Gets node version.

### Method Detail

#### id

    UUID id()

Gets globally unique node ID. A new ID is generated every time a node restarts.

Returns:
  Globally unique node ID.

#### consistentId

    Object consistentId()

Gets consistent globally unique node ID. Unlike `id()` method, this method returns consistent node ID which survives node restarts.

Returns:
  Consistent globally unique node ID.

#### attribute

    @Nullable
    <T> T attribute(String name)

Gets a node attribute. Attributes are assigned to nodes at startup via `IgniteConfiguration.getUserAttributes()` method.

The system adds the following attributes automatically:

- `{@link System#getProperties()}` - All system properties.
- `{@link System#getenv(String)}` - All environment properties.
- All attributes defined in `IgniteNodeAttributes`

Note that attributes cannot be changed at runtime.

Type Parameters:
  `T` - Attribute Type.
Parameters:
  `name` - Attribute name. Note that attribute names starting with `org.apache.ignite` are reserved for internal use.
Returns:
  Attribute value or `null`.

#### metrics

    ClusterMetrics metrics()

Gets metrics snapshot for this node. Note that node metrics are constantly updated and provide up to date information about nodes. For example, you can get an idea about CPU load on remote node via `ClusterMetrics.getCurrentCpuLoad()` method and use it during `ComputeTask.map(List, Object)` or during collision resolution.

Node metrics are updated with some delay which is directly related to heartbeat frequency. For example, when used with default `TcpDiscoverySpi` the update will happen every `2` seconds.

Returns:
  Runtime metrics snapshot for this node.

#### attributes

    Map<String,Object> attributes()

Gets all node attributes. Attributes are assigned to nodes at startup via `IgniteConfiguration.getUserAttributes()` method.

The system adds the following attributes automatically:

- `{@link System#getProperties()}` - All system properties.
- `{@link System#getenv(String)}` - All environment properties.
- All attributes defined in `IgniteNodeAttributes`

Note that attributes cannot be changed at runtime.

Returns:
  All node attributes.

#### addresses

    Collection<String> addresses()

Gets collection of addresses this node is known by.

If `IgniteConfiguration.getLocalHost()` value isn't `null` node will try to use that address for all communications and returned collection will contain only that address. If it is `null` then local wildcard address will be used, and Ignite will make the best effort to supply all addresses of that node in returned collection.

Returns:
  Collection of addresses.

#### hostNames

    Collection<String> hostNames()

Gets collection of host names this node is known by.

If `IgniteConfiguration.getLocalHost()` value isn't `null` node will try to use the host name of that resolved address for all communications and returned collection will contain only that host name. If that host name can not be resolved then ip address returned by method `addresses()` is used.

If `IgniteConfiguration.getLocalHost()` value is `null` then local wildcard address will be used, and this method returns host names of all addresses of that node.

Returns:
  Collection of host names.

#### order

    long order()

Node order within grid topology. Discovery SPIs that support node ordering will assign a proper order to each node and will guarantee that discovery event notifications for new nodes will come in proper order. All other SPIs not supporting ordering may choose to return node startup time here.

NOTE: in cases when discovery SPI doesn't support ordering Ignite cannot guarantee that orders on all nodes will be unique or chronologically correct. If such guarantee is required - make sure use discovery SPI that provides ordering.

Returns:
  Node startup order.

#### version

    IgniteProductVersion version()

Gets node version.

Returns:
  Node version.

#### isLocal

    boolean isLocal()

Tests whether or not this node is a local node.

Returns:
  `True` if this node is a local node, `false` otherwise.

#### isDaemon

    boolean isDaemon()

Tests whether or not this node is a daemon.

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 `ClusterGroup.forDaemons()` method.

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

Application code should never use daemon nodes.

Returns:
  `True` if this node is a daemon, `false` otherwise.

#### isClient

    boolean isClient()

Tests whether or not this node is a client node.

Returns:
  `True` if this node is a client node, `false` otherwise.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

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