Class ConnectionParams
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,String>
org.pipservices3.commons.data.StringValueMap
org.pipservices3.commons.config.ConfigParams
org.pipservices3.components.connect.ConnectionParams
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,String>
public class ConnectionParams
extends org.pipservices3.commons.config.ConfigParams
Contains connection parameters to connect to external services.
They are used together with credential parameters, but usually stored
separately from more protected sensitive values.
### Configuration parameters ###
- discovery_key: key to retrieve parameters from discovery service
- protocol: connection protocol like http, https, tcp, udp
- host: host name or IP address
- port: port number
- uri: resource URI or connection string with all parameters in it
In addition to standard parameters ConnectionParams may contain any number of custom parameters
### Example ###
Example ConnectionParams object usage:
ConnectionParams connection = ConnectionParams.fromTuples(
"protocol", "http",
"host", "10.1.1.100",
"port", "8080",
"cluster", "mycluster"
);
String host = connection.getHost(); // Result: "10.1.1.100"
int port = connection.getPort(); // Result: 8080
String cluster = connection.getAsNullableString("cluster"); // Result: "mycluster"
- See Also:
ConfigParams
,CredentialParams
,ConnectionResolver
,IDiscovery
, Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
Constructor Summary
Constructors Constructor Description ConnectionParams()
Creates a new connection parameters and fills it with values.ConnectionParams(Map<?,?> map)
Creates a new connection parameters and fills it with values. -
Method Summary
Modifier and Type Method Description static ConnectionParams
fromConfig(org.pipservices3.commons.config.ConfigParams config)
Retrieves a single ConnectionParams from configuration parameters from "connection" section.static ConnectionParams
fromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
Retrieves a single ConnectionParams from configuration parameters from "connection" section.static ConnectionParams
fromString(String line)
Creates a new ConnectionParams object filled with key-value pairs serialized as a string.static ConnectionParams
fromTuples(Object... tuples)
Creates a new ConnectionParams object filled with provided key-value pairs called tuples.String
getDiscoveryKey()
Gets the key to retrieve this connection from DiscoveryService.String
getHost()
Gets the host name or IP address.int
getPort()
Gets the port number.String
getProtocol()
Gets the connection protocol.String
getProtocol(String defaultValue)
Gets the connection protocol.String
getUri()
Gets the resource URI or connection string.static List<ConnectionParams>
manyFromConfig(org.pipservices3.commons.config.ConfigParams config)
Retrieves all ConnectionParams from configuration parameters from "connections" section.static List<ConnectionParams>
manyFromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
Retrieves all ConnectionParams from configuration parameters from "connections" section.void
setDiscoveryKey(String value)
Sets the key to retrieve these parameters from DiscoveryService.void
setHost(String value)
Sets the host name or IP address.void
setPort(int value)
Sets the port number.void
setProtocol(String value)
Sets the connection protocol.void
setUri(String value)
Sets the resource URI or connection string.boolean
useDiscovery()
Checks if these connection parameters shall be retrieved from DiscoveryService.Methods inherited from class org.pipservices3.commons.config.ConfigParams
addSection, fromValue, getSection, getSectionNames, mergeConfigs, override, setDefaults
Methods inherited from class org.pipservices3.commons.data.StringValueMap
append, clone, fromMaps, fromTuplesArray, get, getAsArray, getAsArrayWithDefault, getAsBoolean, getAsBooleanWithDefault, getAsDateTime, getAsDateTimeWithDefault, getAsDouble, getAsDoubleWithDefault, getAsDuration, getAsDurationWithDefault, getAsEnum, getAsEnumWithDefault, getAsFloat, getAsFloatWithDefault, getAsInteger, getAsIntegerWithDefault, getAsLong, getAsLongWithDefault, getAsMap, getAsMapWithDefault, getAsNullableArray, getAsNullableBoolean, getAsNullableDateTime, getAsNullableDouble, getAsNullableDuration, getAsNullableEnum, getAsNullableFloat, getAsNullableInteger, getAsNullableLong, getAsNullableMap, getAsNullableString, getAsNullableType, getAsObject, getAsObject, getAsString, getAsStringWithDefault, getAsType, getAsTypeWithDefault, getAsValue, setAsObject, setAsObject, toString
Methods inherited from class java.util.HashMap
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
Constructor Details
-
ConnectionParams
public ConnectionParams()Creates a new connection parameters and fills it with values. -
ConnectionParams
Creates a new connection parameters and fills it with values.- Parameters:
map
- (optional) an object to be converted into key-value pairs to initialize this connection.
-
-
Method Details
-
useDiscovery
public boolean useDiscovery()Checks if these connection parameters shall be retrieved from DiscoveryService. The connection parameters are redirected to DiscoveryService when discovery_key parameter is set.- Returns:
- true if connection shall be retrieved from DiscoveryService
- See Also:
getDiscoveryKey()
-
getDiscoveryKey
Gets the key to retrieve this connection from DiscoveryService. If this key is null, than all parameters are already present.- Returns:
- the discovery key to retrieve connection.
- See Also:
useDiscovery()
-
setDiscoveryKey
Sets the key to retrieve these parameters from DiscoveryService.- Parameters:
value
- a new key to retrieve connection.
-
getProtocol
Gets the connection protocol.- Returns:
- the connection protocol.
-
getProtocol
Gets the connection protocol.- Parameters:
defaultValue
- (optional) the default protocol- Returns:
- the connection protocol or the default value if it's not set.
-
setProtocol
Sets the connection protocol.- Parameters:
value
- a new connection protocol.
-
getHost
Gets the host name or IP address.- Returns:
- the host name or IP address.
-
setHost
Sets the host name or IP address.- Parameters:
value
- a new host name or IP address.
-
getPort
public int getPort()Gets the port number.- Returns:
- the port number.
-
setPort
public void setPort(int value)Sets the port number.- Parameters:
value
- a new port number.
-
getUri
Gets the resource URI or connection string. Usually it includes all connection parameters in it.- Returns:
- the resource URI or connection string.
-
setUri
Sets the resource URI or connection string.- Parameters:
value
- a new resource URI or connection string.
-
fromString
Creates a new ConnectionParams object filled with key-value pairs serialized as a string.- Parameters:
line
- a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"- Returns:
- a new ConnectionParams object.
- See Also:
StringValueMap.fromString(String)
-
fromTuples
Creates a new ConnectionParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.- Parameters:
tuples
- the tuples to fill a new ConnectionParams object.- Returns:
- a new ConnectionParams object.
-
manyFromConfig
public static List<ConnectionParams> manyFromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)Retrieves all ConnectionParams from configuration parameters from "connections" section. If "connection" section is present instead, than it returns a list with only one ConnectionParams.- Parameters:
config
- a configuration parameters to retrieve connectionsconfigAsDefault
- boolean parameter for default configuration. If "true" the default value will be added to the result.- Returns:
- a list of retrieved ConnectionParams
-
manyFromConfig
public static List<ConnectionParams> manyFromConfig(org.pipservices3.commons.config.ConfigParams config)Retrieves all ConnectionParams from configuration parameters from "connections" section. If "connection" section is present instead, than it returns a list with only one ConnectionParams.- Parameters:
config
- a configuration parameters to retrieve connections- Returns:
- a list of retrieved ConnectionParams
-
fromConfig
public static ConnectionParams fromConfig(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)Retrieves a single ConnectionParams from configuration parameters from "connection" section. If "connections" section is present instead, then is returns only the first connection element.- Parameters:
config
- ConnectionParams, containing a section named "connection(s)".configAsDefault
- boolean parameter for default configuration. If "true" the default value will be added to the result.- Returns:
- the generated ConnectionParams object.
- See Also:
manyFromConfig(ConfigParams, boolean)
-
fromConfig
Retrieves a single ConnectionParams from configuration parameters from "connection" section. If "connections" section is present instead, then is returns only the first connection element.- Parameters:
config
- ConnectionParams, containing a section named "connection(s)".- Returns:
- the generated ConnectionParams object.
- See Also:
manyFromConfig(ConfigParams)
-