Interface NodeIdFunction

  • All Superinterfaces:
    LongSupplier
    All Known Implementing Classes:
    DefaultNodeIdFunction, HashNodeIdFunction, MacNodeIdFunction, RandomNodeIdFunction
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface NodeIdFunction
    extends LongSupplier
    It must return a number between 0 and 2^48-1. Use toExpectedRange(long) to set the output within the range 0 to 2^48-1. If necessary, use toMulticast(long) to set the multicast bit. It also sets the output within the range 0 to 2^48-1. Examples:
     // A `NodeIdFunction` that always returns a random number between 0 and 2^48-1.
     NodeIdFunction f = () -> NodeIdFunction.getRandom();
     
     // A `NodeIdFunction` that always returns the same number between 0 and 2^48-1.
     final long number = 1234567890;
     NodeIdFunction f = () -> NodeIdFunction.toExpectedRange(number);
     
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static long getMulticastRandom()
      This method return a new multicast random node identifier.
      static long getRandom()
      This method return a new random node identifier.
      static boolean isMulticast​(long nodeid)
      This method checks if the multicast bit of a node identifier is set.
      static long toExpectedRange​(long nodeid)
      This method clears the unnecessary leading bits so that the resulting number is in the range 0 to 2^48-1.
      static long toMulticast​(long nodeid)
      This method sets the multicast bit of a node identifier.
    • Method Detail

      • getRandom

        static long getRandom()
        This method return a new random node identifier.
        Returns:
        a node identifier in the range 0 to 2^48-1.
      • getMulticastRandom

        static long getMulticastRandom()
        This method return a new multicast random node identifier.
        Returns:
        a node identifier in the range 0 to 2^48-1.
      • toExpectedRange

        static long toExpectedRange​(long nodeid)
        This method clears the unnecessary leading bits so that the resulting number is in the range 0 to 2^48-1. The result is equivalent to n % 2^48.
        Parameters:
        nodeid - the node identifier
        Returns:
        a node identifier in the range 0 to 2^48-1.
      • toMulticast

        static long toMulticast​(long nodeid)
        This method sets the multicast bit of a node identifier. It also clears the unnecessary leading bits so that the resulting number is within the range 0 to 281474976710655 (2^48-1).
        Parameters:
        nodeid - the node identifier
        Returns:
        a node identifier with the multicast bit set
      • isMulticast

        static boolean isMulticast​(long nodeid)
        This method checks if the multicast bit of a node identifier is set.
        Parameters:
        nodeid - a node identifier
        Returns:
        true if the node identifier is multicast