Class EtcdSeedNodeProvider
- java.lang.Object
-
- io.hekate.cluster.seed.etcd.EtcdSeedNodeProvider
-
- All Implemented Interfaces:
SeedNodeProvider
,ConfigReportSupport
public class EtcdSeedNodeProvider extends Object implements SeedNodeProvider, ConfigReportSupport
Etcd-based implementation ofSeedNodeProvider
interface.This provider uses Etcd key-value store to keep track of active seed nodes.
When this provider start it registers the local node's address using the following key structure:
[base_path]
/[namespace]
/ [node_address]In order to find existing seed nodes this provider scans for keys that has the following prefix:
[base_path]
/[namespace]
/Please see the documentation of
EtcdSeedNodeProviderConfig
class for more details about the available configuration options.
-
-
Constructor Summary
Constructors Constructor Description EtcdSeedNodeProvider(EtcdSeedNodeProviderConfig cfg)
Constructs new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
basePath()
Returns the base path for storing seed nodes information in Etcd.long
cleanupInterval()
Returns the time interval in milliseconds for the cluster service to perform the stale data cleaning.List<URI>
endpoints()
Returns an immutable list of Etcd endpoints.List<InetSocketAddress>
findSeedNodes(String namespace)
Returns the list of known seed node addresses.void
registerRemote(String namespace, InetSocketAddress node)
Registered the specified addresses within this provider.void
report(ConfigReporter report)
Report configuration.void
startDiscovery(String namespace, InetSocketAddress node)
Registers the local node address and starts this provider.void
stopDiscovery(String namespace, InetSocketAddress node)
Unregisters the local node address and stops this provider.void
suspendDiscovery()
Suspends discovery activities.String
toString()
void
unregisterRemote(String namespace, InetSocketAddress node)
Unregisters the specified address from this provider.
-
-
-
Constructor Detail
-
EtcdSeedNodeProvider
public EtcdSeedNodeProvider(EtcdSeedNodeProviderConfig cfg)
Constructs new instance.- Parameters:
cfg
- Configuration.
-
-
Method Detail
-
report
public void report(ConfigReporter report)
Description copied from interface:ConfigReportSupport
Report configuration.- Specified by:
report
in interfaceConfigReportSupport
- Parameters:
report
- Reporter.
-
basePath
public String basePath()
Returns the base path for storing seed nodes information in Etcd.- Returns:
- Base path for storing seed nodes information in Etcd.
- See Also:
EtcdSeedNodeProviderConfig.setBasePath(String)
-
endpoints
public List<URI> endpoints()
Returns an immutable list of Etcd endpoints.- Returns:
- immutable list of Etcd endpoints.
- See Also:
EtcdSeedNodeProviderConfig.setEndpoints(List)
-
findSeedNodes
public List<InetSocketAddress> findSeedNodes(String namespace) throws HekateException
Description copied from interface:SeedNodeProvider
Returns the list of known seed node addresses.- Specified by:
findSeedNodes
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).- Returns:
- List of known seed node addresses.
- Throws:
HekateException
- if failed to provide seed node addresses information due to the system failure.
-
startDiscovery
public void startDiscovery(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Registers the local node address and starts this provider.- Specified by:
startDiscovery
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Local node address.- Throws:
HekateException
- If failed to start discovery due to the system failure.
-
stopDiscovery
public void stopDiscovery(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Unregisters the local node address and stops this provider.- Specified by:
stopDiscovery
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Local node address.- Throws:
HekateException
- If failed to stop discovery due to the system failure.
-
cleanupInterval
public long cleanupInterval()
Description copied from interface:SeedNodeProvider
Returns the time interval in milliseconds for the cluster service to perform the stale data cleaning. If the returned value if less than or equals to zero then stale data cleaning will be disabled.- Specified by:
cleanupInterval
in interfaceSeedNodeProvider
- Returns:
- Time interval in milliseconds.
-
registerRemote
public void registerRemote(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Registered the specified addresses within this provider.This method is the part of a stale data cleanup activity and is performed by the cluster service if it detects that particular node is within its cluster topology but is not registered within this provider (i.e. not returned from
SeedNodeProvider.findSeedNodes(String)
method).- Specified by:
registerRemote
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Node address that should be registered.- Throws:
HekateException
- If node couldn't be registered due to the system failure.
-
unregisterRemote
public void unregisterRemote(String namespace, InetSocketAddress node) throws HekateException
Description copied from interface:SeedNodeProvider
Unregisters the specified address from this provider.This method is the part of a stale data cleanup activity and is called by the cluster service if it detects that there is no cluster node running at the specified address while this address is still registered within this provider (i.e. is returned from
SeedNodeProvider.findSeedNodes(String)
method).- Specified by:
unregisterRemote
in interfaceSeedNodeProvider
- Parameters:
namespace
- Cluster namespace (seeClusterServiceFactory.setNamespace(String)
).node
- Node address that should be unregistered.- Throws:
HekateException
- If node couldn't be unregistered due to the system failure.
-
suspendDiscovery
public void suspendDiscovery() throws HekateException
Description copied from interface:SeedNodeProvider
Suspends discovery activities.- Specified by:
suspendDiscovery
in interfaceSeedNodeProvider
- Throws:
HekateException
- If failed to suspend discovery activities due to some system failure.
-
-