Interface DiscoveryStrategy

All Known Implementing Classes:
CompositeDiscovery, DnsDiscovery, EnvironmentDiscovery, FileBasedDiscovery, KubernetesApiDiscovery, MulticastDiscovery, StaticDiscovery

public interface DiscoveryStrategy
A strategy for discovering peer addresses in a LoomCache cluster.

Implementations provide different discovery mechanisms:

  • Static lists from configuration (StaticDiscovery)
  • File-based peer lists with watch support (FileBasedDiscovery)
  • Environment variables for Docker/Kubernetes (EnvironmentDiscovery)
  • UDP multicast announcements for LAN discovery (MulticastDiscovery)
  • DNS-based discovery for Kubernetes headless services (DnsDiscovery)

Thread Safety: All implementations must be thread-safe and handle errors gracefully. Blocking operations (e.g., DNS lookups) should use virtual threads where appropriate.

Since:
1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Discover available peers.
    Get the name of this discovery strategy.
    void
    Start the discovery strategy.
    void
    Stop the discovery strategy and release resources.
  • Method Details

    • discoverPeers

      List<PeerAddress> discoverPeers()
      Discover available peers.

      Returns a snapshot of currently known peers. If no peers are available, an empty list is returned (not null). The returned list is mutable and modifications should not affect internal strategy state.

      Returns:
      list of discovered peer addresses; empty list if none available
    • start

      void start() throws Exception
      Start the discovery strategy.

      Initializes the discovery mechanism and starts any background threads or I/O operations (e.g., watching files, listening to multicast, resolving DNS). Implementations must handle errors gracefully and should not leave resources in an inconsistent state if startup fails.

      Throws:
      Exception - if startup fails; specific exceptions depend on implementation
    • stop

      void stop()
      Stop the discovery strategy and release resources.

      Cleanly shuts down the discovery mechanism, including stopping any background threads and closing I/O resources. Safe to call multiple times and must be idempotent (calling twice should have no additional effect).

    • getName

      String getName()
      Get the name of this discovery strategy.

      Used for logging, metrics, and debugging purposes.

      Returns:
      human-readable strategy name (e.g., "FileBasedDiscovery", "MulticastDiscovery")