Package org.apache.curator.x.discovery
Class UriSpec
- java.lang.Object
-
- org.apache.curator.x.discovery.UriSpec
-
- All Implemented Interfaces:
java.lang.Iterable<UriSpec.Part>
public class UriSpec extends java.lang.Object implements java.lang.Iterable<UriSpec.Part>
An abstraction for specifying a URI for an instance allowing for variable substitutions.
A Uri spec is a string with optional replacement fields. A replacement field begins with an open brace and ends with a close brace. The value between the braces is the name of the field. e.g. "{scheme}://foo.com:{port}" has two replacement fields named "scheme" and "port". Several pre-defined fields are listed as constants in this class (e.g.
FIELD_SCHEME
).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UriSpec.Part
Represents one token in the Uri spec
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FIELD_ADDRESS
If aServiceInstance
is passed when building, the replacement isServiceInstance.getAddress()
static java.lang.String
FIELD_CLOSE_BRACE
Always replaced with '}' - i.e.static java.lang.String
FIELD_ID
If aServiceInstance
is passed when building, the replacement isServiceInstance.getId()
static java.lang.String
FIELD_NAME
If aServiceInstance
is passed when building, the replacement isServiceInstance.getName()
static java.lang.String
FIELD_OPEN_BRACE
Always replaced with '{' - i.e.static java.lang.String
FIELD_PORT
If aServiceInstance
is passed when building, the replacement isServiceInstance.getPort()
static java.lang.String
FIELD_REGISTRATION_TIME_UTC
If aServiceInstance
is passed when building, the replacement isServiceInstance.getRegistrationTimeUTC()
static java.lang.String
FIELD_SCHEME
This defaults to "http".static java.lang.String
FIELD_SERVICE_TYPE
If aServiceInstance
is passed when building, the replacement isServiceInstance.getServiceType()
static java.lang.String
FIELD_SSL_PORT
If aServiceInstance
is passed when building, the replacement isServiceInstance.getSslPort()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(UriSpec.Part part)
Add a part to the end of the listjava.lang.String
build()
Build into a UriSpec stringjava.lang.String
build(java.util.Map<java.lang.String,java.lang.Object> variables)
Build into a UriSpec stringjava.lang.String
build(ServiceInstance<?> serviceInstance)
Build into a UriSpec stringjava.lang.String
build(ServiceInstance<?> serviceInstance, java.util.Map<java.lang.String,java.lang.Object> variables)
Build into a UriSpec stringboolean
equals(java.lang.Object o)
java.util.List<UriSpec.Part>
getParts()
int
hashCode()
java.util.Iterator<UriSpec.Part>
iterator()
void
remove(UriSpec.Part part)
Remove the given part
-
-
-
Field Detail
-
FIELD_SCHEME
public static final java.lang.String FIELD_SCHEME
This defaults to "http". If aServiceInstance
is passed when building and an sslPort is specified in the instance, the replacement is "https".- See Also:
- Constant Field Values
-
FIELD_NAME
public static final java.lang.String FIELD_NAME
If aServiceInstance
is passed when building, the replacement isServiceInstance.getName()
- See Also:
- Constant Field Values
-
FIELD_ID
public static final java.lang.String FIELD_ID
If aServiceInstance
is passed when building, the replacement isServiceInstance.getId()
- See Also:
- Constant Field Values
-
FIELD_ADDRESS
public static final java.lang.String FIELD_ADDRESS
If aServiceInstance
is passed when building, the replacement isServiceInstance.getAddress()
- See Also:
- Constant Field Values
-
FIELD_PORT
public static final java.lang.String FIELD_PORT
If aServiceInstance
is passed when building, the replacement isServiceInstance.getPort()
- See Also:
- Constant Field Values
-
FIELD_SSL_PORT
public static final java.lang.String FIELD_SSL_PORT
If aServiceInstance
is passed when building, the replacement isServiceInstance.getSslPort()
- See Also:
- Constant Field Values
-
FIELD_REGISTRATION_TIME_UTC
public static final java.lang.String FIELD_REGISTRATION_TIME_UTC
If aServiceInstance
is passed when building, the replacement isServiceInstance.getRegistrationTimeUTC()
- See Also:
- Constant Field Values
-
FIELD_SERVICE_TYPE
public static final java.lang.String FIELD_SERVICE_TYPE
If aServiceInstance
is passed when building, the replacement isServiceInstance.getServiceType()
- See Also:
- Constant Field Values
-
FIELD_OPEN_BRACE
public static final java.lang.String FIELD_OPEN_BRACE
Always replaced with '{' - i.e. this is how to insert a literal '{'- See Also:
- Constant Field Values
-
FIELD_CLOSE_BRACE
public static final java.lang.String FIELD_CLOSE_BRACE
Always replaced with '}' - i.e. this is how to insert a literal '}'- See Also:
- Constant Field Values
-
-
Method Detail
-
build
public java.lang.String build()
Build into a UriSpec string- Returns:
- UriSpec string
-
build
public java.lang.String build(ServiceInstance<?> serviceInstance)
Build into a UriSpec string- Parameters:
serviceInstance
- instance to use for pre-defined replacement fields- Returns:
- UriSpec string
-
build
public java.lang.String build(java.util.Map<java.lang.String,java.lang.Object> variables)
Build into a UriSpec string- Parameters:
variables
- a mapping of field replacement names to values. Note: any fields listed in this map override pre-defined fields- Returns:
- UriSpec string
-
build
public java.lang.String build(ServiceInstance<?> serviceInstance, java.util.Map<java.lang.String,java.lang.Object> variables)
Build into a UriSpec string- Parameters:
serviceInstance
- instance to use for pre-defined replacement fieldsvariables
- a mapping of field replacement names to values. Note: any fields listed in this map override pre-defined fields- Returns:
- UriSpec string
-
iterator
public java.util.Iterator<UriSpec.Part> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<UriSpec.Part>
-
getParts
public java.util.List<UriSpec.Part> getParts()
- Returns:
- the parts
-
add
public void add(UriSpec.Part part)
Add a part to the end of the list- Parameters:
part
- part to add
-
remove
public void remove(UriSpec.Part part)
Remove the given part- Parameters:
part
- the part
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-