KBEngine - KBEngine dbmgr

KBEngine API

KBEngine

KBEngine module

This KBEngine module provides Python scripts to control the dbmgr process to handle entity login queries and data access.

Member functions

def addTimer( initialOffset, repeatOffset=0, callbackObj=None ):
def delTimer( id ):

Callbacks

def onDBMgrReady( ):
def onDBMgrShutDown( ):
def onReadyForShutDown( ):
def onSelectAccountDBInterface( accountName ):

Member functions documentation

def addTimer( initialOffset, repeatOffset=0, callbackObj=None ):

Function description:
Registers a timer. The timer triggers the callback function specified by callbackObj. The callback will be executed the first time after "initialOffset" seconds, and then executed once every "repeatOffset" seconds.

Example:
# Here is an example of using addTimer
        import KBEngine
 
        # Add a timer, perform the first time after 5 seconds, and execute once every 1 second. The user parameter is 9
        KBEngine.addTimer( 5, 1, onTimer_Callbackfun )
 
        # Add a timer and execute it after 1 second. The default user parameter is 0.
        KBEngine.addTimer( 1, onTimer_Callbackfun )
 
    def onTimer_Callbackfun( id ):
        print "onTimer_Callbackfun called: id %i" % ( id )
        # If this is a repeated timer, it is no longer needed, call the following function to remove: 
        #     KBEngine.delTimer( id )

parameters:

initialOffset float, specifies the time interval in seconds for the timer to register the first callback.
repeatOffset float, specifies the time interval (in seconds) after each execution of the first callback execution. You must remove the timer with the function delTimer, otherwise it will continue to repeat. Values less than or equal to 0 will be ignored.
callbackObj function, the specified callback function object.

returns:

integer, this function returns the internal id of the timer. This id can be used to remove the timer using delTimer.

def delTimer( id ):

Function description:

The delTimer function is used to remove a registered timer. The removed timer is no longer executed. Single-shot timers are automatically removed after the callback is executed, and it is not necessary to use delTimer to remove it. If the delTimer function receives an invalid id (for example, it was removed), it will generate an error.

A use case is in the KBEngine.addTimer example.

parameters:

id integer, specifies the timer id to remove.


Callback functions documentation

def onDBMgrReady( ):

Function description:

This function is called back when the current process is ready.
Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

def onDBMgrShutDown( ):

Function description:

This function is called when the process shuts down.
Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

def onReadyForShutDown( ):

Function description:

If this function is implemented in a script, the callback function is called when the process is ready to exit.

You can use this callback to control when the process exits.

Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

returns:

bool, if it returns True, it allows the process to exit. Returning other values will cause the process to ask again after a period of time.

def onSelectAccountDBInterface( accountName ):

Function description:

When implemented in a script, this callback returns the database interface corresponding to an account. After the interface is selected, the dbmgr operations related to this account are completed by the corresponding database interface.

Database interfaces are defined in kbengine_defaults.xml->dbmgr->databaseInterfaces.
Use this function to determine which database the account should be stored in based on accountName.

Note: This callback interface must be implemented in the portal module ( kbengine_defaults.xml ->entryScriptFile).

parameters:

accountName string, the name of the account.

returns:

string, the database interface name (database interfaces are defined in kbengine_defaults.xml->dbmgr->databaseInterfaces).