Apama 10.15.2 | Connecting Apama Applications to External Components | Standard IAF Plug-ins | The Database Connector IAF Adapter (ADBC) | The ADBC Event application programming interface | Discovering data sources
 
Discovering data sources
If your application needs to find available data sources, implement the following steps.
*To discover data sources
1. Create a new Discovery event.
2. Use the Discovery event's findAvailableDataSources action.
3. Create a handler action to perform callback actions on the results of the findAvailableDataSources action.
4. In the handler action, declare a variable for a DataSource event.
The definitions for the two forms of the findAvailableDataSources action are:
action findAvailableDataSources(
  float timeout,
  action <string, sequence<DataSource>> callback )
and
action findAvailableDataSourcesFull(
  float timeout,
  dictionary<string,string> extraParams,
  action <string, sequence<DataSource>> callback )
The definition of the DataSource event is:
event DataSource
{  string serviceId;
  string name;
  dictionary<string,string> extraParams;
}
*serviceId — The service ID to talk to this DataSource.
*name — The name of the DataSource such as ODBC, JDBC, or Sim.
*extraParams — Optional parameters.
The relevant code is similar to this:
com.apama.database.Discovery adbc :=
new com.apama.database.Discovery;
adbc.findAvailableDataSources(TIME_TO_WAIT, handleAvailableServers);

action handleAvailableServers(string error,
sequence<com.apama.database.DataSource> results)  
{
    if error.length() != 0 {
      log "Error occurred getting available data sources: " +
           error at ERROR;
    }
    else {
      if results.size() > 0 {
        
        // Save off first service ID found.
        // Assumes first data source has at least one db
        if getDbServiceId() = "" {
           dbServiceId := results[0].serviceId;
        }
        com.apama.database.DataSource ds;
        log " DataSources: " at INFO;
        for ds in results {
            log " " + ds.name + " - " + ds.serviceId at INFO;
        }
        log "Finding Databases ..." at INFO;

        // ... other logic ...

      }
      else {
        log " No DataSources found" at INFO;
      }
    }    
  }