Package com.linecorp.armeria.client
Class Endpoint
- java.lang.Object
-
- com.linecorp.armeria.client.Endpoint
-
- All Implemented Interfaces:
Comparable<Endpoint>
public final class Endpoint extends Object implements Comparable<Endpoint>
A remote endpoint that refers to a single host or a group of multiple hosts.A host endpoint has
host()
, optionalipAddr()
and optionalport()
. It can be represented as"<host>"
or"<host>:<port>"
in the authority part of a URI. It can have an IP address if the host name has been resolved and thus there's no need to query a DNS server.A group endpoint has
groupName()
and it can be represented as"group:<groupName>"
in the authority part of a URI. It can be resolved into a host endpoint withresolve(ClientRequestContext)
.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
authority()
Converts this endpoint into the authority part of a URI.int
compareTo(Endpoint that)
boolean
equals(Object obj)
String
groupName()
Returns the group name of this endpoint.int
hashCode()
boolean
hasIpAddr()
Returns whether this endpoint has an IP address resolved.String
host()
Returns the host name of this endpoint.String
ipAddr()
Returns the IP address of this endpoint.StandardProtocolFamily
ipFamily()
Returns theStandardProtocolFamily
of this endpoint's IP address.boolean
isGroup()
Returnstrue
if this endpoint refers to a group.boolean
isIpAddrOnly()
Returns whether this endpoint's host name is an IP address.static Endpoint
of(String host)
Creates a new hostEndpoint
with unspecified port number.static Endpoint
of(String host, int port)
Creates a new hostEndpoint
.static Endpoint
of(String host, int port, int weight)
Deprecated.Useof(String, int)
andwithWeight(int)
, e.g.static Endpoint
ofGroup(String name)
Creates a new groupEndpoint
.static Endpoint
parse(String authority)
Parse the authority part of a URI.int
port()
Returns the port number of this endpoint.int
port(int defaultValue)
Returns the port number of this endpoint.Endpoint
resolve(ClientRequestContext ctx)
Resolves this endpoint into a host endpoint associated with the specifiedClientRequestContext
.String
toString()
URI
toUri(Scheme scheme)
Converts this endpoint into a URI using theScheme
.URI
toUri(Scheme scheme, String path)
Converts this endpoint into a URI using theScheme
and thepath
.URI
toUri(SessionProtocol sessionProtocol)
Converts this endpoint into a URI using theSessionProtocol
.URI
toUri(SessionProtocol sessionProtocol, String path)
Converts this endpoint into a URI using theSessionProtocol
andpath
.URI
toUri(String scheme)
Converts this endpoint into a URI using thescheme
.URI
toUri(String scheme, String path)
Converts this endpoint into a URI using thescheme
andpath
.int
weight()
Returns the weight of this endpoint.Endpoint
withDefaultPort(int defaultPort)
Returns a new host endpoint with the specified default port number.Endpoint
withIpAddr(String ipAddr)
Returns a new host endpoint with the specified IP address.Endpoint
withWeight(int weight)
Returns a new host endpoint with the specified weight.
-
-
-
Method Detail
-
parse
public static Endpoint parse(String authority)
Parse the authority part of a URI. The authority part may have one of the following formats:"group:<groupName>"
for a group endpoint"<host>:<port>"
for a host endpoint"<host>"
for a host endpoint with no port number specified
"127.0.0.1:8080"
and"[::1]:8080"
.
-
of
public static Endpoint of(String host, int port)
Creates a new hostEndpoint
.- Throws:
IllegalArgumentException
- ifhost
is not a valid host name orport
is not a valid port number
-
of
public static Endpoint of(String host)
Creates a new hostEndpoint
with unspecified port number.- Throws:
IllegalArgumentException
- ifhost
is not a valid host name
-
of
@Deprecated public static Endpoint of(String host, int port, int weight)
Deprecated.Creates a new hostEndpoint
.
-
isGroup
public boolean isGroup()
Returnstrue
if this endpoint refers to a group.
-
resolve
public Endpoint resolve(ClientRequestContext ctx)
Resolves this endpoint into a host endpoint associated with the specifiedClientRequestContext
.- Returns:
- the
Endpoint
resolved byEndpointGroupRegistry
.this
if this endpoint is already a host endpoint.
-
groupName
public String groupName()
Returns the group name of this endpoint.- Throws:
IllegalStateException
- if this endpoint is not a group but a host
-
host
public String host()
Returns the host name of this endpoint.- Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
ipAddr
@Nullable public String ipAddr()
Returns the IP address of this endpoint.- Returns:
- the IP address, or
null
if the host name is not resolved yet - Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
hasIpAddr
public boolean hasIpAddr()
Returns whether this endpoint has an IP address resolved. This method is a shortcut ofipAddr() != null
.- Returns:
true
if and only if this endpoint has an IP address.- Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
isIpAddrOnly
public boolean isIpAddrOnly()
Returns whether this endpoint's host name is an IP address.- Returns:
true
if and only if this endpoint's host name is an IP address- Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
ipFamily
@Nullable public StandardProtocolFamily ipFamily()
Returns theStandardProtocolFamily
of this endpoint's IP address.- Returns:
- the
StandardProtocolFamily
of this endpoint's IP address, ornull
if the host name is not resolved yet - Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
port
public int port()
Returns the port number of this endpoint.- Throws:
IllegalStateException
- if this endpoint is not a host but a group, or this endpoint does not have its port specified.
-
port
public int port(int defaultValue)
Returns the port number of this endpoint.- Parameters:
defaultValue
- the default value to return when this endpoint does not have its port specified- Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
withDefaultPort
public Endpoint withDefaultPort(int defaultPort)
Returns a new host endpoint with the specified default port number.- Returns:
- the new endpoint whose port is
defaultPort
if this endpoint does not have its port specified.this
if this endpoint already has its port specified. - Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
withIpAddr
public Endpoint withIpAddr(@Nullable String ipAddr)
Returns a new host endpoint with the specified IP address.- Returns:
- the new endpoint with the specified IP address.
this
if this endpoint has the same IP address. - Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
withWeight
public Endpoint withWeight(int weight)
Returns a new host endpoint with the specified weight.- Returns:
- the new endpoint with the specified weight.
this
if this endpoint has the same weight. - Throws:
IllegalStateException
- if this endpoint is not a host but a group
-
weight
public int weight()
Returns the weight of this endpoint.
-
authority
public String authority()
Converts this endpoint into the authority part of a URI.- Returns:
- the authority string
-
toUri
public URI toUri(String scheme)
Converts this endpoint into a URI using thescheme
.- Parameters:
scheme
- thescheme
forURI
.- Returns:
- the URI
-
toUri
public URI toUri(String scheme, @Nullable String path)
Converts this endpoint into a URI using thescheme
andpath
.
-
toUri
public URI toUri(SessionProtocol sessionProtocol)
Converts this endpoint into a URI using theSessionProtocol
.- Parameters:
sessionProtocol
- theSessionProtocol
forURI
.- Returns:
- the URI
-
toUri
public URI toUri(SessionProtocol sessionProtocol, @Nullable String path)
Converts this endpoint into a URI using theSessionProtocol
andpath
.- Parameters:
sessionProtocol
- theSessionProtocol
forURI
.path
- thepath
forURI
.- Returns:
- the URI
-
toUri
public URI toUri(Scheme scheme, @Nullable String path)
Converts this endpoint into a URI using theScheme
and thepath
.
-
compareTo
public int compareTo(Endpoint that)
- Specified by:
compareTo
in interfaceComparable<Endpoint>
-
-