java.lang.Object
net.i2p.data.TunnelId
Tunnel identifier: a 32-bit unsigned value, held in a long, that names a tunnel within the network database and in lease sets.
Value:
- Valid range is 1 to
MAX_ID_VALUE(0xffffffff). 0 is reserved for a direct reply in a DatabaseStoreMessage, and the no-argument constructor leaves the invalid value -1 in place until the ID is set by a constructor argument,setTunnelId(long)orreadBytes(InputStream). - Uniqueness is only local: each router picks and enforces its own IDs, nothing here generates or checks them.
Comparison:
equals(Object)requires an instance of TunnelId, so unlikeSimpleDataStructurethis class is safe to mix with other types in a Set or Map.hashCode()is the low 32 bits of the ID, which is the whole valid range.
Mutability and thread safety:
- Not immutable: the ID is a plain non-volatile long that
setTunnelId(long),readBytes(InputStream)and the constructors can replace, even after the object has been shared. Publish or synchronize the object, or replace it, rather than mutating a TunnelId another thread may already hold. - A TunnelId whose ID is set before publication and never changed afterwards can be shared freely between threads.
Field Summary
Modifier and TypeFieldDescriptionprivate longLOCKING: this, seesetTunnelId(long).static final longMaximum tunnel ID value (2^32 - 1).Constructor Summary
Method Summary
All MethodsModifier and TypeMethodDescriptionbooleanTwo TunnelIds are equal when their IDs are equal.longTunnel ID, or -1 if not set or not yet read.inthashCode()The low 32 bits of the ID, which is the whole valid range, or -1 if the ID is not set.voidreadBytes(InputStream in) Read the tunnel ID from a stream.final voidsetTunnelId(long id) Sets the tunnel ID for this lease, replacing any previous value.toString()The ID in decimal.voidwriteBytes(OutputStream out) Write the tunnel ID to a stream.
Field Details
_tunnelId
private long _tunnelIdLOCKING: this, seesetTunnelId(long).MAX_ID_VALUE
public static final long MAX_ID_VALUEMaximum tunnel ID value (2^32 - 1).- See Also:
Constructor Details
TunnelId
public TunnelId()Create a TunnelId with the invalid value -1, for reading from a stream or for setTunnelId().TunnelId
public TunnelId(long id) 1 to 0xffffffff.- Parameters:
id- 1 to 0xffffffff- Throws:
IllegalArgumentException- if less than or equal to zero or greater than max value
Method Details
getTunnelId
public long getTunnelId()Tunnel ID, or -1 if not set or not yet read.- Returns:
- the tunnel ID
setTunnelId
public final void setTunnelId(long id) Sets the tunnel ID for this lease, replacing any previous value.- Parameters:
id- 1 to 0xffffffff- Throws:
IllegalArgumentException- if less than or equal to zero or greater than max value
readBytes
Read the tunnel ID from a stream.- Parameters:
in- the input stream to read from- Throws:
DataFormatException- if the data is invalidIOException- if there is an error reading
writeBytes
Write the tunnel ID to a stream.- Parameters:
out- the output stream to write to- Throws:
DataFormatException- if the data is invalidIOException- if there is an error writing
equals
hashCode
toString