Class NodeIdentity

java.lang.Object
jmri.util.node.NodeIdentity

public class NodeIdentity
extends Object
Provide unique identities for JMRI.

A list of former identities is retained to aid in migrating from the former identity to the new identity.

Currently the storageIdentity is a randomly generated UUID, that is also used for backwards compatibility with JMRI 4.14. If we find a reliable cross-platform mechanism to tie that to the machine's unique identity (from the CPU or motherboard), not from a NIC, this may change. If a JMRI 4.14 generated UUID is available, it is retained and used as the storageIdentity.

  • Field Details

  • Method Details

    • networkIdentity

      public static String networkIdentity()
      Return the node's current network identity. For historical purposes, the network identity is also referred to as the node or node identity.
      Returns:
      A network identity. If this identity is not in the form jmri-MACADDRESS-profileId, or if MACADDRESS is a multicast MAC address, this identity should be considered unreliable and subject to change across JMRI restarts. Note that if the identity is in the form jmri-MACADDRESS the JMRI instance has not loaded a configuration profile, and the network identity will change once that a configuration profile is loaded.
    • storageIdentity

      public static String storageIdentity()
      Return the node's current storage identity for the active profile. This is a convenience method that calls storageIdentity(Profile) with the result of ProfileManager.getActiveProfile().
      Returns:
      A storage identity.
      See Also:
      storageIdentity(Profile)
    • storageIdentity

      public static String storageIdentity​(Profile profile)
      Return the node's current storage identity. This can be used in networked file systems to ensure per-computer storage is available.

      Note this only ensure uniqueness if the preferences path is not shared between multiple computers as documented in FileUtil.getPreferencesPath() (the most common cause of this would be sharing a user's home directory in its entirety between two computers with similar operating systems as noted in getPreferencesPath()).

      Parameters:
      profile - The profile to get the identity for. This is only needed to check that the identity should not be in an older format.
      Returns:
      A storage identity. If this identity is not in the form of a UUID or jmri-UUID-profileId, this identity should be considered unreliable and subject to change across JMRI restarts. When generating a new storage ID, the form is always a UUID and other forms are used only to ensure continuity where other forms may have been used in the past.
    • formerIdentities

      public static List<String> formerIdentities()
      If network hardware on a node was replaced, the identity will change.
      Returns:
      A list of other identities this node may have had in the past.
    • uuidToCompactString

      protected static String uuidToCompactString​(UUID uuid)
      Encodes a UUID into a 22 character URL compatible string. This is used to store the UUID in a manner compatible with JMRI 4.14.

      From an example by Tom Lobato.

      Parameters:
      uuid - the UUID to encode
      Returns:
      the 22 character string
    • uuidFromCompactString

      protected static UUID uuidFromCompactString​(String compact)
      Decodes the original UUID from a 22 character string generated by uuidToCompactString. This is used to store the UUID in a manner compatible with JMRI 4.14.
      Parameters:
      compact - the 22 character string
      Returns:
      the original UUID
    • getFormerIdentities

      Returns:
      the former identities; this is a combination of former network and storage identities