org.apache.ignite.spi

## Interface IgniteSpiContext

-     public interface IgniteSpiContext

  SPI context provides common functionality for all SPI implementations.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener lsnr, int... types)` Adds an event listener for local events.
    `void` | `addLocalMessageListener(@Nullable Object topic, IgniteBiPredicate<UUID,?> p)` Register an local message listener to receive messages sent by remote nodes.
    `void` | `addMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener lsnr, String topic)` Deprecated. Use `addLocalMessageListener(Object, IgniteBiPredicate)` instead.
    `void` | `addMetricRegistryCreationListener(Consumer<ReadOnlyMetricRegistry> lsnr)` Register listener which will be notified on metric registry creation.
    `void` | `addTimeoutObject(IgniteSpiTimeoutObject c)`
    `SecuritySubject` | `authenticatedSubject(UUID subjId)` Gets security subject based on subject ID.
    `Collection<SecuritySubject>` | `authenticatedSubjects()` Gets collection of authenticated subjects together with their permissions.
    `boolean` | `communicationFailureResolveSupported()`
    `<K> boolean` | `containsKey(String cacheName, K key)` Returns `true` if this cache contains a mapping for the specified key.
    `void` | `deregisterPort(int port, IgnitePortProtocol proto)` Deregisters closed port.
    `void` | `deregisterPorts()` Deregisters all closed ports.
    `void` | `failNode(UUID nodeId, @Nullable String warning)`
    `<K,V> V` | `get(String cacheName, K key)` Gets object from cache.
    `ReadOnlyMetricRegistry` | `getOrCreateMetricRegistry(String name)` Returns existing or newly created instance of metric registry with given name.
    `boolean` | `isEventRecordable(int... types)` Checks whether all provided event types are recordable.
    `boolean` | `isStopping()`
    `ClusterNode` | `localNode()` Gets local grid node.
    `MessageFactory` | `messageFactory()` Gets message factory.
    `MessageFormatter` | `messageFormatter()` Gets message formatter.
    `Iterable<ReadOnlyMetricRegistry>` | `metricRegistries()` Returns all registered metric registries.
    `@Nullable ClusterNode` | `node(UUID nodeId)` Gets a node instance based on its ID.
    `Map<String,Object>` | `nodeAttributes()`
    `Collection<ClusterNode>` | `nodes()` Gets a collection of all grid nodes.
    `int` | `partition(String cacheName, Object key)` Calculates partition number for given key.
    `boolean` | `pingNode(UUID nodeId)` Pings a remote node.
    `<K,V> V` | `put(String cacheName, K key, V val, long ttl)` Puts object in cache.
    `<K,V> V` | `putIfAbsent(String cacheName, K key, V val, long ttl)` Puts object into cache if there was no previous object associated with given key.
    `void` | `recordEvent(Event evt)` Records local event.
    `void` | `registerPort(int port, IgnitePortProtocol proto)` Registers open port.
    `Collection<ClusterNode>` | `remoteNodes()` Gets a collection of remote grid nodes.
    `<K,V> V` | `remove(String cacheName, K key)` Removes object from cache.
    `boolean` | `removeLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener lsnr)` Removes local event listener.
    `void` | `removeLocalMessageListener(@Nullable Object topic, IgniteBiPredicate<UUID,?> p)` Removes a previously registered local message listener.
    `boolean` | `removeMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener lsnr, String topic)` Deprecated. Use `removeLocalMessageListener(Object, IgniteBiPredicate)` instead.
    `void` | `removeMetricRegistry(String name)` Removes metric registry with given name.
    `void` | `removeTimeoutObject(IgniteSpiTimeoutObject c)`
    `void` | `resolveCommunicationFailure(ClusterNode node, Exception err)`
    `void` | `send(ClusterNode node, Serializable msg, String topic)` Sends a message to a remote node.
    `boolean` | `tryFailNode(UUID nodeId, @Nullable String warning)`
    `@Nullable IgniteNodeValidationResult` | `validateNode(ClusterNode node)` Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.
    `@Nullable IgniteNodeValidationResult` | `validateNode(ClusterNode node, DiscoveryDataBag discoData)`

- - ### Method Detail

    - #### remoteNodes

          Collection<ClusterNode> remoteNodes()

      Gets a collection of remote grid nodes. Remote nodes are discovered via underlying `DiscoverySpi` implementation used. Unlike `nodes()`, this method does not include local grid node.
      Returns:
        Collection of remote grid nodes.
      See Also:
        `localNode()`, `nodes()`, `DiscoverySpi`

    - #### nodes

          Collection<ClusterNode> nodes()

      Gets a collection of all grid nodes. Remote nodes are discovered via underlying `DiscoverySpi` implementation used. Unlike `remoteNodes()`, this method does include local grid node.
      Returns:
        Collection of remote grid nodes.
      See Also:
        `localNode()`, `remoteNodes()`, `DiscoverySpi`

    - #### localNode

          ClusterNode localNode()

      Gets local grid node. Instance of local node is provided by underlying `DiscoverySpi` implementation used.
      Returns:
        Local grid node.
      See Also:
        `DiscoverySpi`

    - #### node

          @Nullable
          @Nullable ClusterNode node(UUID nodeId)

      Gets a node instance based on its ID.
      Parameters:
        `nodeId` - ID of a node to get.
      Returns:
        Node for a given ID or `null` is such not has not been discovered.
      See Also:
        `DiscoverySpi`

    - #### pingNode

          boolean pingNode(UUID nodeId)

      Pings a remote node. The underlying communication is provided via `DiscoverySpi.pingNode(UUID)` implementation.

      Discovery SPIs usually have some latency in discovering failed nodes. Hence, communication to remote nodes may fail at times if an attempt was made to establish communication with a failed node. This method can be used to check if communication has failed due to node failure or due to some other reason.

      Parameters:
        `nodeId` - ID of a node to ping.
      Returns:
        `true` if node for a given ID is alive, `false` otherwise.
      See Also:
        `DiscoverySpi`

    - #### send

          void send(ClusterNode node,
                    Serializable msg,
                    String topic)
             throws IgniteSpiException

      Sends a message to a remote node. The underlying communication mechanism is defined by `CommunicationSpi` implementation used.
      Parameters:
        `node` - Node to send a message to.
        `msg` - Message to send.
        `topic` - Topic to send message to.
      Throws:
        `IgniteSpiException` - If failed to send a message to remote node.

    - #### addLocalMessageListener

          void addLocalMessageListener(@Nullable
                                       @Nullable Object topic,
                                       IgniteBiPredicate<UUID,?> p)

      Register an local message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined by `CommunicationSpi` implementation used.
      Parameters:
        `topic` - Topic to subscribe to.
        `p` - Message predicate.

    - #### removeLocalMessageListener

          void removeLocalMessageListener(@Nullable
                                          @Nullable Object topic,
                                          IgniteBiPredicate<UUID,?> p)

      Removes a previously registered local message listener.
      Parameters:
        `topic` - Topic to unsubscribe from.
        `p` - Message predicate.

    - #### addMessageListener

          @Deprecated
          void addMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener lsnr,
                                              String topic)

      Deprecated. Use `addLocalMessageListener(Object, IgniteBiPredicate)` instead.
      Register a message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined by `CommunicationSpi` implementation used.

      This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can send messages by calling `send(org.apache.ignite.cluster.ClusterNode, Serializable, String)` method.

      Parameters:
        `lsnr` - Message listener to register.
        `topic` - Topic to register listener for.

    - #### removeMessageListener

          @Deprecated
          boolean removeMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener lsnr,
                                                    String topic)

      Deprecated. Use `removeLocalMessageListener(Object, IgniteBiPredicate)` instead.
      Removes a previously registered message listener.
      Parameters:
        `lsnr` - Message listener to remove.
        `topic` - Topic to unregister listener for.
      Returns:
        `true` of message listener was removed, `false` if it was not previously registered.

    - #### addLocalEventListener

          void addLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener lsnr,
                                     int... types)

      Adds an event listener for local events.
      Parameters:
        `lsnr` - Event listener for local events.
        `types` - Optional types for which this listener will be notified. If no types are provided this listener will be notified for all local events.
      See Also:
        `Event`

    - #### removeLocalEventListener

          boolean removeLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener lsnr)

      Removes local event listener.
      Parameters:
        `lsnr` - Local event listener to remove.
      Returns:
        `true` if listener was removed, `false` otherwise.

    - #### isEventRecordable

          boolean isEventRecordable(int... types)

      Checks whether all provided event types are recordable.
      Parameters:
        `types` - Event types to check.
      Returns:
        Whether or not all provided event types are recordable..

    - #### recordEvent

          void recordEvent(Event evt)

      Records local event.
      Parameters:
        `evt` - Local grid event to record.

    - #### registerPort

          void registerPort(int port,
                            IgnitePortProtocol proto)

      Registers open port.
      Parameters:
        `port` - Port.
        `proto` - Protocol.

    - #### deregisterPort

          void deregisterPort(int port,
                              IgnitePortProtocol proto)

      Deregisters closed port.
      Parameters:
        `port` - Port.
        `proto` - Protocol.

    - #### deregisterPorts

          void deregisterPorts()

      Deregisters all closed ports.

    - #### get

          @Nullable
          <K,V> V get(String cacheName,
                                K key)
                         throws javax.cache.CacheException

      Gets object from cache.
      Type Parameters:
        `K` - Key type.
        `V` - Value type.
      Parameters:
        `cacheName` - Cache name.
        `key` - Object key.
      Returns:
        Cached object.
      Throws:
        `javax.cache.CacheException` - Thrown if any exception occurs.

    - #### put

          @Nullable
          <K,V> V put(String cacheName,
                                K key,
                                V val,
                                long ttl)
                         throws javax.cache.CacheException

      Puts object in cache.
      Type Parameters:
        `K` - Key type.
        `V` - Value type.
      Parameters:
        `cacheName` - Cache name.
        `key` - Object key.
        `val` - Cached object.
        `ttl` - Time to live, `0` means the entry will never expire.
      Returns:
        Previous value associated with specified key, possibly `null`.
      Throws:
        `javax.cache.CacheException` - Thrown if any exception occurs.

    - #### putIfAbsent

          @Nullable
          <K,V> V putIfAbsent(String cacheName,
                                        K key,
                                        V val,
                                        long ttl)
                                 throws javax.cache.CacheException

      Puts object into cache if there was no previous object associated with given key.
      Type Parameters:
        `K` - Cache key type.
        `V` - Cache value type.
      Parameters:
        `cacheName` - Cache name.
        `key` - Cache key.
        `val` - Cache value.
        `ttl` - Time to live.
      Returns:
        Either existing value or `null` if there was no value for given key.
      Throws:
        `javax.cache.CacheException` - If put failed.

    - #### remove

          @Nullable
          <K,V> V remove(String cacheName,
                                   K key)
                            throws javax.cache.CacheException

      Removes object from cache.
      Type Parameters:
        `K` - Key type.
        `V` - Value type.
      Parameters:
        `cacheName` - Cache name.
        `key` - Object key.
      Returns:
        Previous value associated with specified key, possibly `null`.
      Throws:
        `javax.cache.CacheException` - Thrown if any exception occurs.

    - #### containsKey

          <K> boolean containsKey(String cacheName,
                                  K key)

      Returns `true` if this cache contains a mapping for the specified key.
      Type Parameters:
        `K` - Key type.
      Parameters:
        `cacheName` - Cache name.
        `key` - Object key.
      Returns:
        `true` if this cache contains a mapping for the specified key.

    - #### partition

          int partition(String cacheName,
                        Object key)

      Calculates partition number for given key.
      Parameters:
        `cacheName` - Cache name.
        `key` - Key.
      Returns:
        Partition.

    - #### validateNode

          @Nullable
          @Nullable IgniteNodeValidationResult validateNode(ClusterNode node)

      Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.
      Parameters:
        `node` - Joining node.
      Returns:
        Validation result or `null` in case of success.

    - #### validateNode

          @Nullable
          @Nullable IgniteNodeValidationResult validateNode(ClusterNode node,
                                                                      DiscoveryDataBag discoData)

      Parameters:
        `node` - Node.
        `discoData` - Disco data.
      Returns:
        Validation result or `null` in case of success.

    - #### authenticatedSubjects

          Collection<SecuritySubject> authenticatedSubjects()
                                                     throws IgniteException

      Gets collection of authenticated subjects together with their permissions.
      Returns:
        Collection of authenticated subjects.
      Throws:
        `IgniteException` - If any exception occurs.

    - #### authenticatedSubject

          SecuritySubject authenticatedSubject(UUID subjId)
                                        throws IgniteException

      Gets security subject based on subject ID.
      Parameters:
        `subjId` - Subject ID.
      Returns:
        Authorized security subject.
      Throws:
        `IgniteException` - If any exception occurs.

    - #### messageFormatter

          MessageFormatter messageFormatter()

      Gets message formatter.
      Returns:
        Message formatter.

    - #### messageFactory

          MessageFactory messageFactory()

      Gets message factory.
      Returns:
        Message factory.

    - #### isStopping

          boolean isStopping()

      Returns:
        `True` if node started shutdown sequence.

    - #### tryFailNode

          boolean tryFailNode(UUID nodeId,
                              @Nullable
                              @Nullable String warning)

      Parameters:
        `nodeId` - Node ID.
        `warning` - Warning to be shown on all cluster nodes.
      Returns:
        If node was failed.

    - #### failNode

          void failNode(UUID nodeId,
                        @Nullable
                        @Nullable String warning)

      Parameters:
        `nodeId` - Node ID.
        `warning` - Warning to be shown on all cluster nodes.

    - #### addTimeoutObject

          void addTimeoutObject(IgniteSpiTimeoutObject c)

      Parameters:
        `c` - Timeout object.

    - #### removeTimeoutObject

          void removeTimeoutObject(IgniteSpiTimeoutObject c)

      Parameters:
        `c` - Timeout object.

    - #### nodeAttributes

          Map<String,Object> nodeAttributes()

      Returns:
        Current node attributes.

    - #### communicationFailureResolveSupported

          boolean communicationFailureResolveSupported()

      Returns:
        `True` if cluster supports communication error resolving.

    - #### resolveCommunicationFailure

          void resolveCommunicationFailure(ClusterNode node,
                                           Exception err)

      Parameters:
        `node` - Problem node.
        `err` - Error.

    - #### getOrCreateMetricRegistry

          ReadOnlyMetricRegistry getOrCreateMetricRegistry(String name)

      Returns existing or newly created instance of metric registry with given name.
      Parameters:
        `name` - Metric registry name.
      Returns:
        Existing or newly created instance of metric registry.

    - #### removeMetricRegistry

          void removeMetricRegistry(String name)

      Removes metric registry with given name.
      Parameters:
        `name` - Metric registry name.

    - #### metricRegistries

          Iterable<ReadOnlyMetricRegistry> metricRegistries()

      Returns all registered metric registries.
      Returns:
        All registered metric registries.

    - #### addMetricRegistryCreationListener

          void addMetricRegistryCreationListener(Consumer<ReadOnlyMetricRegistry> lsnr)

      Register listener which will be notified on metric registry creation.
      Parameters:
        `lsnr` - Listener.

${current.year} Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.16.0
Release Date | : December 15 2023