Class ConnectionResolver
java.lang.Object
org.pipservices3.components.connect.ConnectionResolver
- All Implemented Interfaces:
org.pipservices3.commons.config.IConfigurable
,org.pipservices3.commons.refer.IReferenceable
public class ConnectionResolver extends Object implements org.pipservices3.commons.config.IConfigurable, org.pipservices3.commons.refer.IReferenceable
Helper class to retrieve component connections.
If connections are configured to be retrieved from IDiscovery
,
it automatically locates IDiscovery
in component references
and retrieve connections from there using discovery_key
parameter.
### Configuration parameters ###
- connection:
- discovery_key: (optional) a key to retrieve the connection from
IDiscovery
- ... other connection parameters
- discovery_key: (optional) a key to retrieve the connection from
- connections: alternative to connection
- [connection params 1]: first connection parameters
- ...
- [connection params N]: Nth connection parameters
- ...
### References ###
- *:discovery:*:*:1.0 (optional)
IDiscovery
services to resolve connections
### Example ###
ConfigParams config = ConfigParams.fromTuples(
"connection.host", "10.1.1.100",
"connection.port", 8080
);
ConnectionResolver connectionResolver = new ConnectionResolver();
connectionResolver.configure(config);
connectionResolver.setReferences(references);
connectionResolver.resolve("123");
- See Also:
ConnectionParams
,IDiscovery
-
Constructor Summary
Constructors Constructor Description ConnectionResolver()
Creates a new instance of connection resolver.ConnectionResolver(org.pipservices3.commons.config.ConfigParams config)
Creates a new instance of connection resolver.ConnectionResolver(org.pipservices3.commons.config.ConfigParams config, org.pipservices3.commons.refer.IReferences references)
Creates a new instance of connection resolver. -
Method Summary
Modifier and Type Method Description void
add(ConnectionParams connection)
Adds a new connection to component connectionsvoid
configure(org.pipservices3.commons.config.ConfigParams config)
Configures component by passing configuration parameters.void
configure(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)
Configures component by passing configuration parameters.List<ConnectionParams>
getAll()
Gets all connections configured in component configuration.void
register(String correlationId, ConnectionParams connection)
Registers the given connection in all referenced discovery services.ConnectionParams
resolve(String correlationId)
Resolves a single component connection.List<ConnectionParams>
resolveAll(String correlationId)
Resolves all component connection.void
setReferences(org.pipservices3.commons.refer.IReferences references)
Sets references to dependent components.
-
Constructor Details
-
ConnectionResolver
public ConnectionResolver()Creates a new instance of connection resolver. -
ConnectionResolver
public ConnectionResolver(org.pipservices3.commons.config.ConfigParams config)Creates a new instance of connection resolver.- Parameters:
config
- (optional) component configuration parameters
-
ConnectionResolver
public ConnectionResolver(org.pipservices3.commons.config.ConfigParams config, org.pipservices3.commons.refer.IReferences references)Creates a new instance of connection resolver.- Parameters:
config
- (optional) component configuration parametersreferences
- (optional) component references
-
-
Method Details
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config, boolean configAsDefault)Configures component by passing configuration parameters.- Parameters:
config
- configuration parameters to be set.configAsDefault
- boolean parameter for default configuration. If "true" the default value will be added to the result.
-
configure
public void configure(org.pipservices3.commons.config.ConfigParams config)Configures component by passing configuration parameters.- Specified by:
configure
in interfaceorg.pipservices3.commons.config.IConfigurable
- Parameters:
config
- configuration parameters to be set.
-
setReferences
public void setReferences(org.pipservices3.commons.refer.IReferences references)Sets references to dependent components.- Specified by:
setReferences
in interfaceorg.pipservices3.commons.refer.IReferenceable
- Parameters:
references
- references to locate the component dependencies.
-
getAll
Gets all connections configured in component configuration. Redirect to Discovery services is not done at this point. If you need fully fleshed connection use resolve() method instead.- Returns:
- a list with connection parameters
-
add
Adds a new connection to component connections- Parameters:
connection
- new connection parameters to be added
-
register
public void register(String correlationId, ConnectionParams connection) throws org.pipservices3.commons.errors.ApplicationExceptionRegisters the given connection in all referenced discovery services. This method can be used for dynamic service discovery.- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.connection
- a connection to register.- Throws:
org.pipservices3.commons.errors.ApplicationException
- when error occured.- See Also:
IDiscovery
-
resolve
public ConnectionParams resolve(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionResolves a single component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.- Returns:
- resolved connection parameters or null if nothing was found.
- Throws:
org.pipservices3.commons.errors.ApplicationException
- when error occured.- See Also:
IDiscovery
-
resolveAll
public List<ConnectionParams> resolveAll(String correlationId) throws org.pipservices3.commons.errors.ApplicationExceptionResolves all component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.- Parameters:
correlationId
- (optional) transaction id to trace execution through call chain.- Returns:
- a list of resolved connections.
- Throws:
org.pipservices3.commons.errors.ApplicationException
- when error occured.- See Also:
IDiscovery
-