ConnectionResolver

Helper class used to retrieve component connections.

Description

The ConnectionResolver class is used to retrieve component connections.

Important points

  • If the connections are configured to be retrieved from IDiscovery, the connection resolver will automatically locate IDiscovery in component references and retrieve the connections from there using the discovery_key parameter.

Configuration parameters

connection:

  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • : other connection parameters

connections: alternative to connection

  • [connection params 1]: first connection parameters
    • : connection parameters for key 1
  • [connection params N]: Nth connection parameters
    • : connection parameters for key N

References

  • *:discovery:*:*:1.0 - (optional) IDiscovery services to resolve connections

Constructors

Creates a new instance of connection resolver.

public ConnectionResolver(ConfigParams config, IReferences references)

  • config: ConfigParams - (optional) component configuration parameters
  • references: IReferences - (optional) component references

Instance methods

add

Adds a new connection to component connections

public void add(ConnectionParams connection)

configure

Configures component by passing configuration parameters.

public void configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

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.

public List<ConnectionParams> getAll()

register

Registers the given connection in all referenced discovery services. This method can be used for dynamic service discovery.

public void register(IContext context, ConnectionParams connection) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through call chain.
  • connection: ConnectionParams - a connection to register.

resolve

Resolves a single component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.

public ConnectionParams resolve(IContext context) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through call chain.
  • returns: ConnectionParams - resolved connection parameters or null if nothing was found.

resolveAll

Resolves all component connection. If connections are configured to be retrieved from Discovery service it finds a IDiscovery and resolves the connection there.

public List resolveAll(IContext context) throws ApplicationException

  • context: IContext - (optional) a context to trace execution through call chain.
  • returns: ConnectionParams[] - a list of resolved connections.

setReferences

Sets references to dependent components.

public void setReferences(IReferences references)

  • references: IReferences - references to locate the component dependencies.

Examples

{
  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