Shutdown in C/C++

This section describes the shutdown function and other activities that you should perform as part of shutdown.

The shutdown function prepares to release all resources the adapter has acquired. Actions such as buffer flushing, file closing, socket and/or database disconnection should be performed. You might wish to print an activity summary on Sybase CEP Server log.

The shutdown is similar to:

void user_input_c8adapter_shutdown(C8Adapter *i_adapter_ptr) 
{     C8UInt l_data_size = 0; 
    MySessionState *l_session_ptr = (struct MySessionState*) 
        C8AdapterGetSessionState(i_adapter_ptr); 
    MyPersistentData *l_persistent_ptr = 
        (MyPersistentData*)C8AdapterGetPersistentState(i_adapter_ptr, 
            &l_data_size); 
    if(l_persistent_ptr) { 
        printf("Closing data source. Lines processed: %d\n", 
            l_persistent_ptr->m_number_lines_read); 
        C8AdapterSetPersistentState(i_adapter_ptr, (void *) NULL, 0); 
    } else { 
        printf("Cannot get persistent data in shutdown!\n"); 
    } 
    // Close the session state 
    C8AdapterSetSessionState(i_adapter_ptr, NULL); 
    if(l_session_ptr) { 
        C8Free((void*)l_session_ptr); 
    } else { 
        printf("Cannot get session data in shutdown!\n"); 
    } 
    return; 
}

Session state and persistent state are retrieved from the Sybase CEP Engine. The number of lines processed is displayed on the Sybase CEP window.

The C8AdapterSetSessionState() call releases the Sybase CEP Engine resources that were acquired for this adapter.

Important: The call to the shutdown() function is a blocking call. Some server operations may not run while the shutdown() function is running, and therefore you should write your shutdown() function so that it finishes quickly (preferably in less than one second).