Discovering data sources
If your application needs to find available data sources, implement the following steps:
1. Create a new Discovery event.
2. Use the Discovery event’s findAvailableServers action.
3. Create a handler action to perform callback actions on the results of the findAvailableServers action.
4. In the handler action, declare a variable for a DataSource event.
The definitions for the two forms of the findAvailableServers action are:
action findAvailableServers(
float timeout,
action < string, sequence<DataSource> > callback )
and
action findAvailableServersFull(
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
serviceID to talk to this DataSource.
name — The name of the
DataSource such as ODBC, JDBC, or Sim.
extraParams — Optional parameters.
The relevant code in the samples\adbc\api-example\ADBC_Example.mon file is similar to this:
com.apama.database.Discovery adbc :=
new com.apama.database.Discovery;
adbc.findAvailableServers(TIME_TO_WAIT, handleAvailableServers);
action handleAvailableServers(string error,
sequence<com.apama.database.DataSource> results)
{
if error.length() != 0 then {
log "Error occurred getting available data sources: " +
error at ERROR;
}
else {
if results.size() > 0 then {
// Save off first service ID found.
// Assumes first data source has at least one db
if getDbServiceId() = "" then {
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;
}
}
}
Copyright © 2013
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.