public final class Endpoint extends Object implements Comparable<Endpoint>, EndpointGroup
A host endpoint has host(), optional ipAddr() and optional port(). 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 with
resolve(ClientRequestContext).
| Modifier and Type | Method and Description |
|---|---|
String |
authority()
Converts this endpoint into the authority part of a URI.
|
int |
compareTo(Endpoint that) |
List<Endpoint> |
endpoints()
Return the endpoints held by this
EndpointGroup. |
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.
|
boolean |
hasPort()
Returns whether this endpoint has a port number specified.
|
String |
host()
Returns the host name of this endpoint.
|
CompletableFuture<List<Endpoint>> |
initialEndpointsFuture()
Returns a
CompletableFuture which is completed when the initial Endpoints are ready. |
String |
ipAddr()
Returns the IP address of this endpoint.
|
StandardProtocolFamily |
ipFamily()
Returns the
StandardProtocolFamily of this endpoint's IP address. |
boolean |
isGroup()
Returns
true 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 host
Endpoint with unspecified port number. |
static Endpoint |
of(String host,
int port)
Creates a new host
Endpoint. |
static Endpoint |
of(String host,
int port,
int weight)
Deprecated.
Use
of(String, int) and withWeight(int),
e.g. Endpoint.of("foo.com", 80).withWeight(500). |
static Endpoint |
ofGroup(String name)
Creates a new group
Endpoint. |
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 specified
ClientRequestContext. |
String |
toString() |
URI |
toUri(Scheme scheme)
Converts this endpoint into a URI using the
Scheme. |
URI |
toUri(Scheme scheme,
String path)
Converts this endpoint into a URI using the
Scheme and the path. |
URI |
toUri(SessionProtocol sessionProtocol)
Converts this endpoint into a URI using the
SessionProtocol. |
URI |
toUri(SessionProtocol sessionProtocol,
String path)
Converts this endpoint into a URI using the
SessionProtocol and path. |
URI |
toUri(String scheme)
Converts this endpoint into a URI using the
scheme. |
URI |
toUri(String scheme,
String path)
Converts this endpoint into a URI using the
scheme and path. |
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 |
withoutDefaultPort(int defaultPort)
Returns a new host endpoint with the default port number removed.
|
Endpoint |
withoutPort()
Returns a new host endpoint with its port number unspecified.
|
Endpoint |
withPort(int port)
Returns a new host endpoint with the specified port number.
|
Endpoint |
withWeight(int weight)
Returns a new host endpoint with the specified weight.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitaddListener, awaitInitialEndpoints, awaitInitialEndpoints, close, empty, of, of, orElse, removeListenerpublic static Endpoint parse(String authority)
"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".public static Endpoint of(String host, int port)
Endpoint.IllegalArgumentException - if host is not a valid host name or
port is not a valid port numberpublic static Endpoint of(String host)
Endpoint with unspecified port number.IllegalArgumentException - if host is not a valid host name@Deprecated public static Endpoint of(String host, int port, int weight)
of(String, int) and withWeight(int),
e.g. Endpoint.of("foo.com", 80).withWeight(500).Endpoint.public boolean isGroup()
true if this endpoint refers to a group.public Endpoint resolve(ClientRequestContext ctx)
ClientRequestContext.Endpoint resolved by EndpointGroupRegistry.
this if this endpoint is already a host endpoint.public List<Endpoint> endpoints()
EndpointGroupEndpointGroup.endpoints in interface EndpointGrouppublic CompletableFuture<List<Endpoint>> initialEndpointsFuture()
EndpointGroupCompletableFuture which is completed when the initial Endpoints are ready.initialEndpointsFuture in interface EndpointGrouppublic String groupName()
IllegalStateException - if this endpoint is not a group but a hostpublic String host()
IllegalStateException - if this endpoint is not a host but a group@Nullable public String ipAddr()
null if the host name is not resolved yetIllegalStateException - if this endpoint is not a host but a grouppublic boolean hasIpAddr()
ipAddr() != null.true if and only if this endpoint has an IP address.IllegalStateException - if this endpoint is not a host but a grouppublic boolean isIpAddrOnly()
true if and only if this endpoint's host name is an IP addressIllegalStateException - if this endpoint is not a host but a group@Nullable public StandardProtocolFamily ipFamily()
StandardProtocolFamily of this endpoint's IP address.StandardProtocolFamily of this endpoint's IP address, or
null if the host name is not resolved yetIllegalStateException - if this endpoint is not a host but a grouppublic int port()
IllegalStateException - if this endpoint is not a host but a group, or
this endpoint does not have its port specified.public int port(int defaultValue)
defaultValue - the default value to return when this endpoint does not have its port specifiedIllegalStateException - if this endpoint is not a host but a grouppublic boolean hasPort()
true if and only if this endpoint has a port number.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withPort(int port)
port - the new port numberthis if this endpoint has the same port number with the specified one.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withoutPort()
this if this endpoint does not have a port already.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withDefaultPort(int defaultPort)
defaultPort - the default port numberdefaultPort if this endpoint does not have its port
specified. this if this endpoint already has its port specified.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withoutDefaultPort(int defaultPort)
defaultPort - the default port numberthis if this endpoint had a different
port number than the specified default port number or this endpoint already does not have
a port number.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withIpAddr(@Nullable String ipAddr)
this if this endpoint has the same IP address.IllegalStateException - if this endpoint is not a host but a grouppublic Endpoint withWeight(int weight)
this if this endpoint has the same weight.IllegalStateException - if this endpoint is not a host but a grouppublic int weight()
public String authority()
public URI toUri(String scheme)
scheme.scheme - the scheme for URI.public URI toUri(String scheme, @Nullable String path)
scheme and path.public URI toUri(SessionProtocol sessionProtocol)
SessionProtocol.sessionProtocol - the SessionProtocol for URI.public URI toUri(SessionProtocol sessionProtocol, @Nullable String path)
SessionProtocol and path.sessionProtocol - the SessionProtocol for URI.path - the path for URI.public URI toUri(Scheme scheme, @Nullable String path)
Scheme and the path.public int compareTo(Endpoint that)
compareTo in interface Comparable<Endpoint>Copyright © 2020 LeanCloud. All rights reserved.