My Project
|
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::CNPLRuntimeState * | m_rts |
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
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]
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]
const char * ParaScripting::ParaNPLRuntimeState::GetName | ( | ) | const |
return the name of this runtime state.
if "", it is considered an anonymous name
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.
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});
input | this 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 |
bool ParaScripting::ParaNPLRuntimeState::IsValid | ( | ) |
if this is a valid state.
luabind::object ParaScripting::ParaNPLRuntimeState::PeekMessage | ( | int | nIndex, |
const object & | inout | ||
) |
inout | this 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. |
luabind::object ParaScripting::ParaNPLRuntimeState::PopMessageAt | ( | int | nIndex, |
const object & | inout | ||
) |
pop message at given index.
usually we need to call peek() first.
inout | this 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 |
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.
onResetScode | the code to be executed immediately after runtime state is reset. default to NULL. |
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]
int ParaScripting::ParaNPLRuntimeState::Start | ( | ) |
start this runtime state in a worker thread
bool ParaScripting::ParaNPLRuntimeState::Stop | ( | void | ) |
Stop the worker thread.
this will stop processing messages in the thread.
void ParaScripting::ParaNPLRuntimeState::WaitForMessage2 | ( | int | nMessageCount | ) |
nMessageCount | if not negative, this function will immediately return when the message queue size is bigger than this value. |