Algorithm Overview

The C/C++ subfunctions in an in-process adapter run only when called by Sybase CEP Server. This section describes the Sybase CEP Server callback functions.

Each in-process adapter must provide three or four subfunctions that can be called by the server:

Because these functions must be registered with and called by the server, they are sometimes referred to as callback functions.

The actual names of the functions may be chosen by you; for convenience, we will refer to them as the initialize(), execute(), and shutdown() functions.

The initialize() function is called once. This function performs the required initialization steps. For example, if the adapter is an input adapter, the initialize() function opens or connects to the data source. If the data source is a file, then the initialize() function will open the input file. The initialize() function may also read parameters such as the location of the input and allocate memory.

The execute() function is called periodically. If the adapter is an input adapter, the execute() function reads one or more rows from the data source, does any required data conversion, and sends that data to a stream. If the adapter is an output adapter, the execute() function reads one or more rows from the data stream, does any required data conversion, and sends the data to a data destination.
Note: By calling the execute() function periodically, whether there is data or not, the server gives the adapter a chance to check for other conditions, such as timeouts, as well as to check for data.

The shutdown() function is called when the server would like to stop the in-process adapter. Typically this is when the server itself is going to shut down. The shutdown() function should do any appropriate cleanup, such as closing files, releasing and so on.

When one of these functions is called, the server passes the function a pointer to a C8Adapter object. This C8Adapter object stores information about this particular instance of the adapter. You can have multiple instances of your own adapter running simultaneously, just as you can have multiple copies of a built-in adapter running simultaneously. An adapter pointer is required for many of the calls to the Sybase CEP API. For example, if you want to get the schema of the stream used by a particular instance of an adapter, then you will call the C8AdapterGetSchema() function and pass it the C8Adapter pointer that indicates which adapter (and thus which stream) the function should return the schema of.

Each of these functions can call other functions you write as well as various library functions that are part of the server or the In-process Adapter SDK. The library file that contains your in-process adapter contains the three main functions as well as the other functions that support those main functions.