My Project
Public Member Functions | Public Attributes | List of all members
ParaScripting::ParaNPLRuntimeState Class Reference

A runtime state contains the scripting runtime stack and can be run in a single thread. More...

#include <ParaScriptingNPL.h>

Public Member Functions

 ParaNPLRuntimeState (NPL::CNPLRuntimeState *rts_)
 
 ParaNPLRuntimeState (NPL::NPLRuntimeState_ptr rts_)
 
bool IsValid ()
 if this is a valid state. More...
 
const char * GetName () const
 return the name of this runtime state. More...
 
object GetField (const char *sFieldname, const object &output)
 
void SetField (const char *sFieldname, const object &input)
 
int Start ()
 start this runtime state in a worker thread More...
 
bool Stop ()
 Stop the worker thread. More...
 
void Reset ()
 it is like starting a fresh new runtime state. More...
 
void Reset1 (const char *onResetScode)
 
object GetStats (const object &input)
 get statistics about this runtime environment. More...
 
int GetCurrentQueueSize ()
 Get the current number of messages in the input message queue. More...
 
int GetProcessedMsgCount ()
 the total number of message processed by this runtime state since start. More...
 
int GetMsgQueueSize ()
 get the message queue size. More...
 
void SetMsgQueueSize (int nSize=500)
 set the message queue size. More...
 
void WaitForMessage ()
 simply wait for the next message to arrive.
 
void WaitForMessage2 (int nMessageCount)
 
object PeekMessage (int nIndex, const object &inout)
 
object PopMessageAt (int nIndex, const object &inout)
 pop message at given index. More...
 

Public Attributes

NPL::CNPLRuntimeStatem_rts
 

Detailed Description

A runtime state contains the scripting runtime stack and can be run in a single thread.

An NPL runtime state is message driven, however we also support timer and several other event callbacks. Normally we only use this class to start a new runtime, or get statistics about a runtime

Member Function Documentation

§ GetCurrentQueueSize()

int ParaScripting::ParaNPLRuntimeState::GetCurrentQueueSize ( )

Get the current number of messages in the input message queue.

Sometimes, a monitor or dispatcher logics may need to know the queue size of all NPL runtime states. and a dispatcher will usually need to add new messages to the NPL state with smallest queue size. This function will lock the message queue to retrieve the queue size, so do not call it very often, but use a timer to query it on some interval. [thread safe]

§ GetMsgQueueSize()

int ParaScripting::ParaNPLRuntimeState::GetMsgQueueSize ( )

get the message queue size.

default to 500. For busy server side, we can set this to something like 5000 [thread safe]

§ GetName()

const char * ParaScripting::ParaNPLRuntimeState::GetName ( ) const

return the name of this runtime state.

if "", it is considered an anonymous name

§ GetProcessedMsgCount()

int ParaScripting::ParaNPLRuntimeState::GetProcessedMsgCount ( )

the total number of message processed by this runtime state since start.

If this number does not increase, perhaps the processing is blocking somewhere, and we should take actions. [Not thread safe] in most cases, it will return correct result even in multi-threaded environment, but since we do not use lock, unexpected result may return. This function is usually used for stat printing and monitoring.

§ GetStats()

luabind::object ParaScripting::ParaNPLRuntimeState::GetStats ( const object input)

get statistics about this runtime environment.

e.g. local stats = NPL.GetStats({connection_count = true, nids_str=true, nids = true});

Parameters
inputthis should be a table containing mapping from string to true. function will return a new table by replacing true with the actual data. such as {["connection_count"] = true, ["nids_str"] = true }, supported fields are "connection_count" : total connection. "nids_str": commar separated list of nids. "nids": a table array of nids "loadedfiles": a table array of loaded files in the current NPL runtime state
Returns
{connection_count = 10, nids_str="101,102,"}

§ IsValid()

bool ParaScripting::ParaNPLRuntimeState::IsValid ( )

if this is a valid state.

§ PeekMessage()

luabind::object ParaScripting::ParaNPLRuntimeState::PeekMessage ( int  nIndex,
const object inout 
)
Parameters
inoutthis should be a table {filename=true, code=true, msg=true}, specify which part of the message to retrieve in return value. {filename=true} will only retrieve the filename, because it is faster if code is big.
Returns
: msg table {filename, code, msg} if exist, or nil.

§ PopMessageAt()

luabind::object ParaScripting::ParaNPLRuntimeState::PopMessageAt ( int  nIndex,
const object inout 
)

pop message at given index.

usually we need to call peek() first.

Parameters
inoutthis should be a table {filename=true, code=true, process=true}, specify which part of the message to retrieve in return value. {filename=true} will only retrieve the filename, because it is faster if code is big. if inout.process == true, we will pop and process the message via standard activation. if inout.process == false, we will pop without processing the message, in which case the caller may need to process it manually
Returns
: msg table {filename, code, msg, result} if exist, or filename will be false. result is only available if process is true

§ Reset()

void ParaScripting::ParaNPLRuntimeState::Reset ( )

it is like starting a fresh new runtime state.

All memory, tables, timers, pending messages are removed. this function only takes effect on the next message loop. So there can be other clean up code following this function.

Parameters
onResetScodethe code to be executed immediately after runtime state is reset. default to NULL.

§ SetMsgQueueSize()

void ParaScripting::ParaNPLRuntimeState::SetMsgQueueSize ( int  nSize = 500)

set the message queue size.

default to 500. For busy server side, we can set this to something like 5000 [thread safe]

§ Start()

int ParaScripting::ParaNPLRuntimeState::Start ( )

start this runtime state in a worker thread

Returns
the number of threads that are currently working on the runtime state. normally this is 1. only dll runtime state may have more than one worker thread.

§ Stop()

bool ParaScripting::ParaNPLRuntimeState::Stop ( void  )

Stop the worker thread.

this will stop processing messages in the thread.

§ WaitForMessage2()

void ParaScripting::ParaNPLRuntimeState::WaitForMessage2 ( int  nMessageCount)
Parameters
nMessageCountif not negative, this function will immediately return when the message queue size is bigger than this value.

The documentation for this class was generated from the following files: