Apama Predictive Analytics Plug-in 10.15 | Apama Predictive Analytics Plug-in | Working with Predictive Analytics Plug-in | Loading custom resources
 
Loading custom resources
The Predictive Analytics Plug-in supports adding and removing custom resources like lookup tables and custom functions. You can follow these steps to load and use custom functions in EPL.
*To add or remove custom resources in an EPL script
1. Create an instance of ServiceParams.
com.apama.pa.pmml.ServiceParams serviceParams :=
(new com.apama.pa.pmml.ServiceParamsHelper).create();
2. Add any custom resource either with absolute path or relative path.
serviceParams.addResource(CUSTOM_RESOURCE_NAME1);
serviceParams.addResource(CUSTOM_RESOURCE_NAME2);
The Predictive Analytics Plug-in also supports adding and removing resources at runtime through ResourceManager API. ResourceManager API can be accessed by calling getResourceManager() on the ServiceHandler object received in service initialization onServiceInitialised callback.
action onServiceInitialised(ServiceHandler servicehandler)
{
serviceHandler := servicehandler;

ResourceManager resourcemanager := serviceHandler.getResourceManager();
resourcemanager.addResource("CUSTOM_RESOURCE_NAME1");
resourcemanager.addResource("CUSTOM_RESOURCE_NAME2");
resourcemanager.addResource("CUSTOM_RESOURCE_NAME3");

ModelManager modelmanager := serviceHandler.getModelManager();
//Add MODEL_NAME1 from PMML_PATH1
modelmanager.addModel("PMML_PATH1");

//Add MODEL_NAME2 from PMML_PATH2
modelmanager.addModel("PMML_PATH2");

//application code ...

//remove model when done
modelmanager.removeModel("MODEL_NAME1");
modelmanager.removeModel("MODEL_NAME1");

//remove resource when done
resourcemanager.removeResource("CUSTOM_RESOURCE_NAME1");
resourcemanager.removeResource("CUSTOM_RESOURCE_NAME2");
resourcemanager.removeResource("CUSTOM_RESOURCE_NAME3");

}
You can also list the resources that are added by calling listResources() function using ResourceManager object. The resources are removed automatically when the engine stops, but it is recommended to explicitly remove the unused resources.
For more information, refer to the samples at:
*APAMA_HOME/samples/PredictiveAnalytics/ECommerceFraud Custom Functions
*APAMA_HOME/samples/PredictiveAnalytics/ECommerceFraud Custom Context