Examples of use
This section contains sections of code that illustrate the ScenarioService API. The complete sample applications are located in the Apama installation’s samples\engine_client\javaScenarioService directory. The directory contains a README.txt file that describes how to build and run the sample applications including how to inject the necessary monitors. The samples are:
SimpleScenarioService.java — Sample 1, demonstrates the capabilites of the ScenarioService API.
SimpleScenarioDefinition.java — Sample 2, demonstrates the capabilities of the ScenarioDefinition class.
SimpleScenarioInstance.java — Sample 3, demonstrates how to manipulate the ScenarioInstance class.
FilteredScenarioInstance.java — Sample 4, extends Sample 3 to demonstrate how to filter a list of interested
ScenarioIds.
The following piece of code shows the recommended method of creating a ScenarioService object. First, it creates a ScenarioServiceListener and then uses the ScenarioServiceFactory method to create a new ScenarioService instance, passing in the listener as the forth argument.
// Create a listener for the ScenarioService
scenarioServiceListener = new ScenarioServiceListener();
// Get a IScenarioService instance from the ScenarioServiceFactory
scenarioService = ScenarioServiceFactory.createScenarioService(
"localhost",
ConnectionConstants.DEFAULT_ENGINE_PORT,
null,
scenarioServiceListener);
The following piece of code is an example of how to provide a listener for handling the PropertyChangeEvent events fired by the IScenarioService object.
private class ScenarioServiceListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent evt) {
if (!IScenarioService.PROPERTY_SCENARIO_ADDED.equals(
evt.getPropertyName())) {
// Example only cares about ADDED events and discards others
return;
}
IScenarioDefinition def = (IScenarioDefinition)evt.getNewValue();
// check if the event signifies the desired Scenario ID
if (null!=def && SCENARIO_ID.equals(def.getId())) {
// Now go do something useful with it...
createEditDelete(def);
}
}
}