org.apache.ignite.spi.discovery.tcp.ipfinder.zk

## Class TcpDiscoveryZookeeperIpFinder

- java.lang.Object
- - org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter
  - - org.apache.ignite.spi.discovery.tcp.ipfinder.zk.TcpDiscoveryZookeeperIpFinder

- All Implemented Interfaces:
    TcpDiscoveryIpFinder

      public class TcpDiscoveryZookeeperIpFinder
      extends TcpDiscoveryIpFinderAdapter

  This TCP Discovery IP Finder uses Apache ZooKeeper (ZK) to locate peer nodes when bootstrapping in order to join the cluster. It uses the Apache Curator library to interact with ZooKeeper in a simple manner. Specifically, it uses the `ServiceDiscovery` recipe, which makes use of ephemeral nodes in ZK to register services.

  There are several ways to instantiate the TcpDiscoveryZookeeperIpFinder:

- By providing an instance of `CuratorFramework` directly, in which case no ZK Connection String is required.
  By providing a ZK Connection String through `setZkConnectionString(String)`, and optionally a `RetryPolicy` through the setter. If the latter is not provided, a default `ExponentialBackoffRetry` policy is used, with a base sleep time of 1000ms and 10 retries.
  By providing a ZK Connection String through system property `PROP_ZK_CONNECTION_STRING`. If this property is set, it overrides the ZK Connection String passed in as a property, but it does not override the `CuratorFramework` if provided.
You may customise the base path for services, as well as the service name. By default `BASE_PATH` and `SERVICE_NAME` are use respectively. You can also choose to enable or disable duplicate registrations. See `setAllowDuplicateRegistrations(boolean)` for more details.

See Also:
  Apache ZooKeeper, Apache Curator

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `PROP_ZK_CONNECTION_STRING` System property name to provide the ZK Connection String.

    - ### Fields inherited from class org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter

      `ignite`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TcpDiscoveryZookeeperIpFinder()` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getBasePath()`
    `Collection<InetSocketAddress>` | `getRegisteredAddresses()` Gets all addresses registered in this finder.
    `org.apache.curator.RetryPolicy` | `getRetryPolicy()`
    `String` | `getServiceName()`
    `String` | `getZkConnectionString()`
    `boolean` | `isAllowDuplicateRegistrations()` * @return The value of this flag.
    `void` | `onSpiContextDestroyed()` Callback invoked prior to stopping grid before SPI context is destroyed.
    `void` | `registerAddresses(Collection<InetSocketAddress> addrs)` Registers new addresses.
    `TcpDiscoveryZookeeperIpFinder` | `setAllowDuplicateRegistrations(boolean allowDuplicateRegistrations)`
    `TcpDiscoveryZookeeperIpFinder` | `setBasePath(String basePath)`
    `TcpDiscoveryZookeeperIpFinder` | `setCurator(org.apache.curator.framework.CuratorFramework curator)`
    `TcpDiscoveryZookeeperIpFinder` | `setRetryPolicy(org.apache.curator.RetryPolicy retryPolicy)`
    `TcpDiscoveryZookeeperIpFinder` | `setServiceName(String serviceName)`
    `TcpDiscoveryZookeeperIpFinder` | `setShared(boolean shared)` Sets shared flag.
    `TcpDiscoveryZookeeperIpFinder` | `setZkConnectionString(String zkConnectionString)`
    `void` | `unregisterAddresses(Collection<InetSocketAddress> addrs)` Unregisters provided addresses.

    - ### Methods inherited from class org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinderAdapter

      `close, discoveryClientMode, initializeLocalAddresses, isShared, onSpiContextInitialized, spiContext, toString`

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

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

- - ### Field Detail

    - #### PROP_ZK_CONNECTION_STRING

          public static final String PROP_ZK_CONNECTION_STRING

      System property name to provide the ZK Connection String.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TcpDiscoveryZookeeperIpFinder

          public TcpDiscoveryZookeeperIpFinder()

      Constructor.

  - ### Method Detail

    - #### onSpiContextDestroyed

          public void onSpiContextDestroyed()

      Callback invoked prior to stopping grid before SPI context is destroyed. Note that invoking SPI context after this callback is complete is considered illegal and may produce unknown results.
      Specified by:
        `onSpiContextDestroyed` in interface `TcpDiscoveryIpFinder`
      Overrides:
        `onSpiContextDestroyed` in class `TcpDiscoveryIpFinderAdapter`

    - #### getRegisteredAddresses

          public Collection<InetSocketAddress> getRegisteredAddresses()
                                                               throws IgniteSpiException

      Gets all addresses registered in this finder.
      Returns:
        All known addresses, potentially empty, but never `null`.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### registerAddresses

          public void registerAddresses(Collection<InetSocketAddress> addrs)
                                 throws IgniteSpiException

      Registers new addresses.

      Implementation should accept duplicates quietly, but should not register address if it is already registered.

      Parameters:
        `addrs` - Addresses to register. Not `null` and not empty.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### unregisterAddresses

          public void unregisterAddresses(Collection<InetSocketAddress> addrs)
                                   throws IgniteSpiException

      Unregisters provided addresses.

      Implementation should accept addresses that are currently not registered quietly (just no-op).

      Parameters:
        `addrs` - Addresses to unregister. Not `null` and not empty.
      Throws:
        `IgniteSpiException` - In case of error.

    - #### setCurator

          public TcpDiscoveryZookeeperIpFinder setCurator(org.apache.curator.framework.CuratorFramework curator)

      Parameters:
        `curator` - A `CuratorFramework` instance to use. It can already be in `STARTED` state.
      Returns:
        `this` for chaining.

    - #### getZkConnectionString

          public String getZkConnectionString()

      Returns:
        The ZooKeeper connection string, only if set explicitly. Else, it returns null.

    - #### setZkConnectionString

          public TcpDiscoveryZookeeperIpFinder setZkConnectionString(String zkConnectionString)

      Parameters:
        `zkConnectionString` - ZooKeeper connection string in case a `CuratorFramework` is not being set explicitly.
      Returns:
        `this` for chaining.

    - #### getRetryPolicy

          public org.apache.curator.RetryPolicy getRetryPolicy()

      Returns:
        Retry policy in use if, and only if, it was set explicitly. Else, it returns null.

    - #### setRetryPolicy

          public TcpDiscoveryZookeeperIpFinder setRetryPolicy(org.apache.curator.RetryPolicy retryPolicy)

      Parameters:
        `retryPolicy` - `RetryPolicy` to use in case a ZK Connection String is being injected, or if using a system property.
      Returns:
        `this` for chaining.

    - #### getBasePath

          public String getBasePath()

      Returns:
        Base path for service registration in ZK. Default value: `BASE_PATH`.

    - #### setBasePath

          public TcpDiscoveryZookeeperIpFinder setBasePath(String basePath)

      Parameters:
        `basePath` - Base path for service registration in ZK. If not passed, `BASE_PATH` will be used.
      Returns:
        `this` for chaining.

    - #### getServiceName

          public String getServiceName()

      Returns:
        Service name being used, in Curator terms. See `setServiceName(String)` for more information.

    - #### setServiceName

          public TcpDiscoveryZookeeperIpFinder setServiceName(String serviceName)

      Parameters:
        `serviceName` - Service name to use, as defined by Curator's {#link ServiceDiscovery} recipe. In physical ZK terms, it represents the node under `basePath`, under which services will be registered.
      Returns:
        `this` for chaining.

    - #### isAllowDuplicateRegistrations

          public boolean isAllowDuplicateRegistrations()

      * @return The value of this flag. See `setAllowDuplicateRegistrations(boolean)` for more details.

    - #### setAllowDuplicateRegistrations

          public TcpDiscoveryZookeeperIpFinder setAllowDuplicateRegistrations(boolean allowDuplicateRegistrations)

      Parameters:
        `allowDuplicateRegistrations` - Whether to register each node only once, or if duplicate registrations are allowed. Nodes will attempt to register themselves, plus those they know about. By default, duplicate registrations are not allowed, but you might want to set this property to `true` if you have multiple network interfaces or if you are facing troubles.
      Returns:
        `this` for chaining.

    - #### setShared

          public TcpDiscoveryZookeeperIpFinder setShared(boolean shared)

      Sets shared flag. If `true` then it is expected that IP addresses registered with IP finder will be seen by IP finders on all other nodes.
      Overrides:
        `setShared` in class `TcpDiscoveryIpFinderAdapter`
      Parameters:
        `shared` - `true` if this IP finder is shared.
      Returns:
        `this` for chaining.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020