Class VersionCompatibilityManager

java.lang.Object
com.loomcache.common.protocol.VersionCompatibilityManager

public final class VersionCompatibilityManager extends Object
Manages version compatibility and feature negotiation across LoomCache nodes.

Responsibilities: 1. Determine compatibility between local and remote versions 2. Track compatible versions (same major version, within min/max bounds) 3. Resolve available features based on negotiated version 4. Support rolling upgrades with feature-aware messaging

Thread-safe: Uses ConcurrentHashMap for per-peer version tracking.

  • Constructor Details

    • VersionCompatibilityManager

      public VersionCompatibilityManager(LoomVersion localVersion)
      Create a version compatibility manager.
      Parameters:
      localVersion - the local node's version (must not be null)
      Throws:
      IllegalArgumentException - if localVersion is null
  • Method Details

    • forCurrentVersion

      public static VersionCompatibilityManager forCurrentVersion()
      Create a manager with the current build version.
      Returns:
      a new VersionCompatibilityManager
    • localVersion

      public LoomVersion localVersion()
      Get the local node's version.
      Returns:
      the local version
    • isCompatible

      public boolean isCompatible(LoomVersion remoteVersion)
      Check if a remote version is compatible with the local version.

      Compatibility rules: 1. Major versions must be equal (major version is a breaking change boundary) 2. Remote version must be >= minimum compatible version

      Parameters:
      remoteVersion - the version to check (must not be null)
      Returns:
      true if compatible, false otherwise
      Throws:
      IllegalArgumentException - if remoteVersion is null
    • registerPeerVersion

      public void registerPeerVersion(String peerId, LoomVersion version)
      Register a peer's version after successful handshake.

      This allows the manager to track which versions are present in the cluster and enables version-aware feature negotiation.

      Parameters:
      peerId - the peer's unique identifier (must not be null or blank)
      version - the peer's version (must not be null)
      Throws:
      IllegalArgumentException - if peerId is null/blank or version is null
    • getPeerVersion

      public @Nullable LoomVersion getPeerVersion(String peerId)
      Get the registered version for a peer.
      Parameters:
      peerId - the peer's identifier (must not be null or blank)
      Returns:
      the peer's version, or null if not registered
      Throws:
      IllegalArgumentException - if peerId is null or blank
    • getCompatibleFeatures

      public Set<Feature> getCompatibleFeatures(LoomVersion negotiatedVersion)
      Get features available given a negotiated version.

      A feature is available if the negotiated version is >= the version in which the feature was introduced (and same major version).

      Parameters:
      negotiatedVersion - the version to check features for (must not be null)
      Returns:
      an immutable set of available features
      Throws:
      IllegalArgumentException - if negotiatedVersion is null
    • getCompatibleFeaturesForPeer

      public Set<Feature> getCompatibleFeaturesForPeer(String peerId)
      Get features available for communication with a specific peer.

      Uses the minimum of local and peer versions to determine compatibility.

      Parameters:
      peerId - the peer's identifier (must not be null or blank)
      Returns:
      an immutable set of features available for this peer, or empty set if peer not registered
      Throws:
      IllegalArgumentException - if peerId is null or blank
    • allPeerVersions

      public Map<String, LoomVersion> allPeerVersions()
      Get all registered peer versions.

      Useful for cluster introspection and rolling upgrade monitoring.

      Returns:
      an immutable copy of the peer versions map
    • hasFeature

      public boolean hasFeature(LoomVersion version, Feature feature)
      Check if a feature is available for a given version.
      Parameters:
      version - the version to check (must not be null)
      feature - the feature to check (must not be null)
      Returns:
      true if the feature is available in the given version, false otherwise
      Throws:
      IllegalArgumentException - if version or feature is null
    • hasFeatureForPeer

      public boolean hasFeatureForPeer(String peerId, Feature feature)
      Check if a feature is available for communication with a specific peer.
      Parameters:
      peerId - the peer's identifier (must not be null or blank)
      feature - the feature to check (must not be null)
      Returns:
      true if the feature is available for this peer, false otherwise
      Throws:
      IllegalArgumentException - if peerId is null/blank or feature is null