Class MulticastDiscovery
- All Implemented Interfaces:
DiscoveryStrategy
Each node periodically announces itself to a multicast group. Announcements contain: nodeId,host,port
Configuration: - Multicast group: 239.0.0.1:5555 (configurable) - Announcement interval: 5 seconds - Peer timeout: 30 seconds (peers expire if no announcement received)
Uses virtual threads for announcement and listening. Thread-safe with ConcurrentHashMap for peer tracking.
-
Constructor Summary
ConstructorsConstructorDescriptionMulticastDiscovery(String nodeId, String host, int port) Create a multicast discovery strategy.MulticastDiscovery(String nodeId, String host, int port, String multicastGroup, int multicastPort) Create a multicast discovery strategy with custom multicast group. -
Method Summary
-
Constructor Details
-
MulticastDiscovery
-
MulticastDiscovery
public MulticastDiscovery(String nodeId, String host, int port, String multicastGroup, int multicastPort) Create a multicast discovery strategy with custom multicast group.- Parameters:
nodeId- this node's identifierhost- this node's host addressport- this node's portmulticastGroup- multicast group IP (e.g., "239.0.0.1")multicastPort- multicast port (e.g., 5555)
-
-
Method Details
-
start
Description copied from interface:DiscoveryStrategyStart 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.
- Specified by:
startin interfaceDiscoveryStrategy- Throws:
Exception- if startup fails; specific exceptions depend on implementation
-
stop
public void stop()Description copied from interface:DiscoveryStrategyStop 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).
- Specified by:
stopin interfaceDiscoveryStrategy
-
discoverPeers
Description copied from interface:DiscoveryStrategyDiscover 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.
- Specified by:
discoverPeersin interfaceDiscoveryStrategy- Returns:
- list of discovered peer addresses; empty list if none available
-
getName
Description copied from interface:DiscoveryStrategyGet the name of this discovery strategy.Used for logging, metrics, and debugging purposes.
- Specified by:
getNamein interfaceDiscoveryStrategy- Returns:
- human-readable strategy name (e.g., "FileBasedDiscovery", "MulticastDiscovery")
-