Extends: ConfigParams
Description
The ConnectionParams class allows you to create connection parameters used to connect to external services.
Important points
- Usually, connection parameters are used together with credential parameters, but are stored separately from these more protected and 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.
Constructors
Creates a new ConnectionParams object and fills it with values.
ConnectionParams([values])
- values: dynamic - (optional) object to be converted into key-value pairs to initialize this connection.
Instance methods
getDiscoveryKey
Gets the key to retrieve this connection from DiscoveryService. If this key is null, then all parameters are already present.
String? getDiscoveryKey()
- returns: String? - resolved options or error.
getHost
Gets the host name or IP address.
String? getHost()
- returns: String? - host name or IP address.
getPort
Gets the port number.
int? getPort()
- returns: int? - port number.
getPortWithDefault
Gets the port number with default value.
int getPortWithDefault(int defaultPort)
- defaultPort: int - default port number.
- returns: int - port number.
getProtocol
Gets the connection protocol.
String? getProtocol([String? defaultValue])
- defaultValue: String? - (optional) default protocol
- returns: String? - connection protocol or default value if it’s not set.
getProtocolWithDefault
Gets the connection protocol with default value.
String getProtocolWithDefault(String defaultValue)
- defaultValue: String - (optional) default protocol
- returns: String - connection protocol or the default value if it’s not set.
getUri
Gets the resource URI or connection string. Usually it includes all connection parameters in it.
String? getUri()
- returns: String? - resource URI or connection string.
setDiscoveryKey
Sets the key to retrieve these parameters from DiscoveryService.
void setDiscoveryKey(String? value)
- value: String? - new key to a retrieve connection.
setHost
Sets the host name or IP address.
void setHost(String? value)
- value: String? - new host name or IP address.
setPort
Sets the port number.
void setPort(int value)
- value: int - new port number.
setProtocol
Sets the connection protocol.
void setProtocol(String? value)
- value: String? - new connection protocol.
setUri
Sets the resource URI or connection string.
void setUri(String value)
- value: String - new resource URI or connection string.
useDiscovery
Checks if these connection parameters shall be retrieved from DiscoveryService. The connection parameters are redirected to DiscoveryService when discovery_key parameter is set.
bool useDiscovery()
- returns: bool - true if the connection shall be retrieved from DiscoveryService
Static methods
fromConfig
Retrieves a single ConnectionParams from configuration parameters from “connection” section. If “connections” section is present instead, then it returns only the first connection element.
static
List<ConnectionParams?> manyFromConfig(ConfigParams config)
- config: ConfigParams - ConnectionParams, containing a section named “connection(s)”.
- returns: List<ConnectionParams?> - generated ConnectionParams object.
fromString
Creates a new ConnectionParams object filled with key-value pairs serialized as a string.
static
ConnectionParams fromString(String line)
-
line: String - string with serialized key-value pairs as “key1=value1;key2=value2;…" Example: “Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z”
-
returns: ConnectionParams - new ConnectionParams object.
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.
static
ConnectionParams fromTuples(List<dynamic> tuples)
-
tuples: List<dynamic> - tuples to fill a new ConnectionParams object.
-
returns: ConnectionParams - new ConnectionParams object.
manyFromConfig
Retrieves all ConnectionParams from configuration parameters from “connections” section. If “connection” section is present instead, then it returns a list with only one ConnectionParams.
static
List<ConnectionParams> manyFromConfig(ConfigParams config)
-
config: ConfigParams - configuration parameters to retrieve connections
-
returns: List<ConnectionParams> - list of retrieved ConnectionParams
Examples
var connection = ConnectionParams.fromTuples([
'protocol', 'http',
'host', '10.1.1.100',
'port', '8080',
'cluster', 'mycluster'
]);
var host = connection.getHost(); // Result: '10.1.1.100'
var port = connection.getPort(); // Result: 8080
var cluster = connection.getAsNullableString('cluster'); // Result: 'mycluster'