Home / Class/ LocalAddress Class — netty Architecture

LocalAddress Class — netty Architecture

Architecture documentation for the LocalAddress class in LocalAddress.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  75e2c848_9167_e870_68a4_151dea170b28["LocalAddress"]
  e84c8567_dc7c_56af_b527_014f8b95016d["LocalAddress.java"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|defined in| e84c8567_dc7c_56af_b527_014f8b95016d
  5fe1b034_4e39_6d33_3e87_fcfabf8088ff["LocalAddress()"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|method| 5fe1b034_4e39_6d33_3e87_fcfabf8088ff
  f36084ab_3d07_bb37_d369_bbe4b170986c["String()"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|method| f36084ab_3d07_bb37_d369_bbe4b170986c
  d905841d_84ed_2054_ecf5_c3fd0779281b["hashCode()"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|method| d905841d_84ed_2054_ecf5_c3fd0779281b
  15ff3e7d_187b_1851_5418_966127c2af3d["equals()"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|method| 15ff3e7d_187b_1851_5418_966127c2af3d
  f4ebbe00_e024_64b8_bd20_11bf55a01e2c["compareTo()"]
  75e2c848_9167_e870_68a4_151dea170b28 -->|method| f4ebbe00_e024_64b8_bd20_11bf55a01e2c

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/local/LocalAddress.java lines 29–97

public final class LocalAddress extends SocketAddress implements Comparable<LocalAddress> {

    private static final long serialVersionUID = 4644331421130916435L;

    public static final LocalAddress ANY = new LocalAddress("ANY");

    private final String id;
    private final String strVal;

    /**
     * Creates a new ephemeral port based on the ID of the specified channel.
     * Note that we prepend an upper-case character so that it never conflicts with
     * the addresses created by a user, which are always lower-cased on construction time.
     */
    LocalAddress(Channel channel) {
        StringBuilder buf = new StringBuilder(16);
        buf.append("local:E");
        buf.append(Long.toHexString(channel.hashCode() & 0xFFFFFFFFL | 0x100000000L));
        buf.setCharAt(7, ':');
        id = buf.substring(6);
        strVal = buf.toString();
    }

    /**
     * Creates a new instance with the specified ID.
     */
    public LocalAddress(String id) {
        this.id = checkNonEmptyAfterTrim(id, "id").toLowerCase();
        strVal = "local:" + this.id;
    }

    /**
     * Creates a new instance with a random ID based on the given class.
     */
    public LocalAddress(Class<?> cls) {
        this(cls.getSimpleName() + '/' + UUID.randomUUID());
    }

    /**
     * Returns the ID of this address.
     */
    public String id() {
        return id;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof LocalAddress)) {
            return false;
        }

        return id.equals(((LocalAddress) o).id);
    }

    @Override
    public int compareTo(LocalAddress o) {
        return id.compareTo(o.id);
    }

    @Override
    public String toString() {
        return strVal;
    }
}

Frequently Asked Questions

What is the LocalAddress class?
LocalAddress is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/local/LocalAddress.java.
Where is LocalAddress defined?
LocalAddress is defined in transport/src/main/java/io/netty/channel/local/LocalAddress.java at line 29.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free