Class NodeIdentity
- java.lang.Object
-
- jmri.util.node.NodeIdentity
-
public class NodeIdentity extends java.lang.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 Summary
Fields Modifier and Type Field Description protected static java.lang.String
URL_SAFE_CHARACTERS
A string of 64 URL compatible characters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.String>
formerIdentities()
If network hardware on a node was replaced, the identity will change.java.util.List<java.lang.String>
getFormerIdentities()
static java.lang.String
networkIdentity()
Return the node's current network identity.static java.lang.String
storageIdentity()
Return the node's current storage identity for the active profile.static java.lang.String
storageIdentity(Profile profile)
Return the node's current storage identity.protected static java.util.UUID
uuidFromCompactString(java.lang.String compact)
Decodes the original UUID from a 22 character string generated byuuidToCompactString
.protected static java.lang.String
uuidToCompactString(java.util.UUID uuid)
Encodes a UUID into a 22 character URL compatible string.
-
-
-
Field Detail
-
URL_SAFE_CHARACTERS
protected static final java.lang.String URL_SAFE_CHARACTERS
A string of 64 URL compatible characters.Used by
uuidToCompactString
anduuidFromCompactString
.- See Also:
- Constant Field Values
-
-
Method Detail
-
networkIdentity
public static java.lang.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 ifMACADDRESS
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 formjmri-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 java.lang.String storageIdentity()
Return the node's current storage identity for the active profile. This is a convenience method that callsstorageIdentity(Profile)
with the result ofProfileManager.getActiveProfile()
.- Returns:
- A storage identity.
- See Also:
storageIdentity(Profile)
-
storageIdentity
public static java.lang.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 java.util.List<java.lang.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 java.lang.String uuidToCompactString(java.util.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 java.util.UUID uuidFromCompactString(java.lang.String compact)
Decodes the original UUID from a 22 character string generated byuuidToCompactString
. 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
public java.util.List<java.lang.String> getFormerIdentities()
- Returns:
- the former identities; this is a combination of former network and storage identities
-
-