Apama 10.3.1 | Apama Documentation | Developing Apama Applications | Developing EPL Plug-ins | Writing EPL Plug-ins in C++ | Creating a plug-in using C++ | Handling thread-specific data in plug-ins
 
Handling thread-specific data in plug-ins
The correlator executes plug-ins on a number of internal threads which may change over time, including spawning new threads or destroying old threads. If a plug-in needs to store any state in thread-local variables, then - as well as cleaning up this state when the plug-in unloads - it also needs to clean it up when a thread is destroyed. To enable this, plug-ins can register to receive a callback whenever the correlator destroys a thread. This is done by subclassing ThreadEndedHandler with an implementation of threadEnded() and then passing an instance of your subclass to the receiveThreadEndedCallbacks() method on CorrelatorInterface. receiveThreadEndedCallbacks takes ownership of the handler and may only be called once per plug-in.
class MyThreadHandler: public ThreadEndedHandler {
public:
virtual void threadEnded() {
// cleanup code here
}
};
MyPlugin(): base_plugin_t("MyPlugin")
{
getCorrelator().receiveThreadEndedCallbacks(
MyThreadHandler::ptr_t(new MyThreadHandler()));
}

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.