public final class Endpoint extends Object implements Comparable<Endpoint>, EndpointGroup
An 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.
| Modifier and Type | Method and Description |
|---|---|
String |
authority()
Converts this endpoint into the authority part of a URI.
|
void |
close()
Releases any underlying resources held by this object synchronously.
|
CompletableFuture<?> |
closeAsync()
Releases any underlying resources held by this object asynchronously.
|
int |
compareTo(Endpoint that) |
List<Endpoint> |
endpoints()
Returns the endpoints held by this
EndpointGroup. |
boolean |
equals(Object obj) |
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.
|
String |
ipAddr()
Returns the IP address of this endpoint.
|
StandardProtocolFamily |
ipFamily()
Returns the
StandardProtocolFamily of this endpoint's IP address. |
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 |
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 |
select(ClientRequestContext ctx)
Selects an
Endpoint from this EndpointGroup. |
EndpointSelectionStrategy |
selectionStrategy()
Returns the
EndpointSelectionStrategy of this EndpointGroup. |
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.
|
CompletableFuture<List<Endpoint>> |
whenReady()
Returns a
CompletableFuture which is completed when the initial Endpoints are ready. |
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, empty, initialEndpointsFuture, of, of, of, of, orElse, removeListenerpublic static Endpoint parse(String authority)
"<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 List<Endpoint> endpoints()
EndpointGroupEndpointGroup.endpoints in interface EndpointGrouppublic EndpointSelectionStrategy selectionStrategy()
EndpointGroupEndpointSelectionStrategy of this EndpointGroup.selectionStrategy in interface EndpointGrouppublic Endpoint select(ClientRequestContext ctx)
EndpointGroupEndpoint from this EndpointGroup.select in interface EndpointGroupselect in interface EndpointSelectorEndpoint selected by the EndpointSelectionStrategy,
which was specified when constructing this EndpointGroup.public CompletableFuture<List<Endpoint>> whenReady()
EndpointGroupCompletableFuture which is completed when the initial Endpoints are ready.whenReady in interface EndpointGrouppublic String host()
IllegalStateException - if this endpoint is not a host but a grouppublic 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 grouppublic 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(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, String path)
scheme and path.public URI toUri(SessionProtocol sessionProtocol)
SessionProtocol.sessionProtocol - the SessionProtocol for URI.public URI toUri(SessionProtocol sessionProtocol, String path)
SessionProtocol and path.sessionProtocol - the SessionProtocol for URI.path - the path for URI.public URI toUri(Scheme scheme, String path)
Scheme and the path.public CompletableFuture<?> closeAsync()
AsyncCloseablecloseAsync in interface AsyncCloseableCompletableFuture which is completed after the resources are releasedpublic void close()
AsyncCloseableclose in interface AsyncCloseableclose in interface AutoCloseablepublic int compareTo(Endpoint that)
compareTo in interface Comparable<Endpoint>Copyright © 2020 LeanCloud. All rights reserved.