This section describes the intialization, execution, and shutdown callbacks for in-process output adapters, and provides an example of a typical callback pattern for output adapters.
A typical in-process output adapter gets data from the Sybase CEP Engine and publishes to some destination. The tutorial output adapter, like the tutorial input adapter, provides additional routines of interest for adapter developers.
The three callbacks for an output in-process adapter are:
Initialization: Initialize the adapter in anticipation of receiving messages from the Sybase CEP Engine and sending the messages to some external data sink. This includes such activities as opening sockets, verifying the existence of files and/or directories, and pinging network connections. Any relevant state information created must be saved.
Execution: The user queries for any messages. If a message is available, execution callback extracts relevant information from the message and handles the information according to your adapter code. This includes, but is not limited to, creating CSV and XML files, filtering according to some criteria, and redirecting to some data sink. The exact mechanism is highly dependent on your intentions. Whether one or multiple messages are processed depends on the Sybase CEP message queue. If no messages are available, the routine will usually return to the caller. Note that the output adapter execute function may be called even if no messages are available. You may be interested in maintaining connections, querying external events, and so on.
Shutdown: The Sybase CEP Engine has receives information that the adapter should shut down either from someone clicking the "Stop" button in Studio, or from another source. The shutdown routine should perform whatever shutdown operations pertain to the adapter: closing sockets, closing database connections, closing files, flushing buffers, and so on. Release any resources obtained from the Sybase CEP Engine. In particular, call C8AdapterSetSessionState(adapter_ptr, NULL) to allow the Sybase CEP Engine to release internal resources.
A typical pattern for an output adapter is:
C8Bool my_output_c8adapter_initialize(C8Adapter *adapter_ptr) { // Do initialization if needed. This includes session and // persistent data creation. See the input adapter for examples. } C8Bool my_output_c8adapter_execute(C8Adapter *adapter_ptr) { C8Message *msg = NULL; // The output adapter setup is the same as the input adapter. ... // Receive messages and process. // As long as the engine provides messages, the adapter // should process them. while (C8AdapterIsInterrupted(adapter_ptr) != C8_TRUE && C8AdapterReceiveMessage(adapter_ptr) != NULL) { // Publish message to the external user destination ... // Destroy message C8MessageDestroy(msg); } return C8_TRUE; } void my_output_c8adapter_shutdown(C8Adapter *adapter_ptr) { // The shutdown matches the pattern in the input adapter. }