Class DomainSocketAddress

java.lang.Object
java.net.SocketAddress
java.net.InetSocketAddress
com.linecorp.armeria.common.util.DomainSocketAddress
All Implemented Interfaces:
Serializable

@UnstableApi public final class DomainSocketAddress extends InetSocketAddress
An InetSocketAddress that refers to a Unix domain socket path. This class extends InetSocketAddress to ensure the backward compatibility with existing Armeria API that uses InetSocketAddress in its API. This address will have the following properties:
  • hostname and hostString - "unix:<path>", e.g. "unix:/var/run/server.sock"
  • address - an IPv6 address that falls into IPv6 Discard Prefix

Pitfalls

Comparing two DomainSocketAddresses using InetSocketAddress.equals(Object) will always return true because there's no way to override InetSocketAddress.equals(Object), which compares only the IP addresses for resolved addresses. You should never use DomainSocketAddress as a key of a Map, or as an element of a Set; consider using Endpoint instead.

See Also:
  • Method Details

    • of

      public static DomainSocketAddress of(Path path)
      Returns a newly created DomainSocketAddress with the specified Path to the Unix domain socket.
    • of

      public static DomainSocketAddress of(String path)
      Returns a newly created DomainSocketAddress with the specified path to the Unix domain socket.
    • of

      public static DomainSocketAddress of(io.netty.channel.unix.DomainSocketAddress nettyAddr)
      Returns a newly created DomainSocketAddress with the Unix domain socket path of the specified Netty address.
    • isDomainSocketAddress

      public static boolean isDomainSocketAddress(InetAddress addr)
      Returns whether the specified InetAddress matches the special IPv6 address of DomainSocketAddress. For example:
      
       DomainSocketAddress sockAddr = DomainSocketAddress.of("/var/run/server.sock");
       InetAddress inetAddr = sockAddr.getAddress();
       assert isDomainSocketAddress(inetAddr);
       
    • path

      public String path()
      Returns the path to the Unix domain socket.
    • isAbstract

      public boolean isAbstract()
      Returns true if this address is in the abstract namespace.
    • authority

      public String authority()
      Returns the authority (host) form of this address which can be used as a part of URI.
    • asNettyAddress

      public io.netty.channel.unix.DomainSocketAddress asNettyAddress()
      Converts this address to a Netty DomainSocketAddress.
      Returns:
      the converted Netty address
    • asEndpoint

      public Endpoint asEndpoint()
      Converts this address to an Endpoint.
    • toString

      public String toString()
      Returns a string representation of this address, such as "/path/to/sock" or "@sock" (abstract namespace).
      Overrides:
      toString in class InetSocketAddress