Build TOP Environments

For developer

Common

Synchronous and Asynchronous
About Classes

ChmpxNode Class

ChmpxNode::InitializeOnServer()
ChmpxNode::InitializeOnSlave()
ChmpxNode::Open()
ChmpxNode::Close()
ChmpxNode::Send()
ChmpxNode::Broadcast()
ChmpxNode::Receive() - For slave node
ChmpxNode::Receive() - For server node
ChmpxNode::Reply()
ChmpxNode::IsChmpxExit()


Common

Synchronous and Asynchronous

The methods of the classes provided by CHMPX Node.js addon library support synchronous and asynchronous processing by specifying the callback function.
Methods that support asynchronous processing can accept the arguments of the callback function.
In addition, these can specify event handlers as on or onXXXXX as asynchronous processing.
Developers can perform asynchronous processing using callback functions or event handlers.
Callback function arguments and event handlers are not specified, these methods act as synchronization processes.

About Classes

CHMPX Node.js addon library provides ChmpxNode class. Initialize this ChmpxNode class as a client of the server node and communicate as a server node side client. It initializes it as a client of the slave node and communicates as a slave node side client.


ChmpxNode Class

This is the main class provided by CHMPX Node.js addon library.
You can use this class to communicate as server node side client and slave node side client.

A sample to create this class object is shown below.

Below are the methods of the ChmpxNode class and those explanation.

ChmpxNode::InitializeOnServer()

This method initializes ChmpxNode object for on chmpx server node.

Format

bool InitializeOnServer(String   filepath,
                        bool     is_auto_rejoin = false,
                        Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

If you call the method argument is_auto_rejoin with false, it will return an error immediately when the CHMPX server node process is not running. If is_auto_rejoin is set to true, when the CHMPX server node process is not running, this method will be blocked until it is started up.
To wait until the CHMPX process is restarted, you can easily implement the client program by setting this argument to true.

ChmpxNode::InitializeOnSlave()

This method initializes ChmpxNode object for on chmpx slave node.

Format

bool InitializeOnSlave(String   filepath,
                       bool     is_auto_rejoin = false,
                       Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

If you call the method argument is_auto_rejoin with false, it will return an error immediately when the CHMPX slave node process is not running. If is_auto_rejoin is set to true, when the CHMPX slave node process is not running, this method will be blocked until it is started up.
To wait until the CHMPX process is restarted, you can easily implement the client program by setting this argument to true.

ChmpxNode::Open()

Connect the ChmpxNode object to the CHMPX slave node side and obtain the message ID.
The ChmpxNode object must be initialized in advance for the slave node.

Format

Buffer Open(bool     no_giveup_rejoin = false,
            Callback cbfunc = null
)

Arguments

Return Values

Return the message ID if success, and on error return null.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

The ChmpxNode object must be initialized in advance for the slave node.
If no_giveup_rejoin is set to true, it blocks until the CHMPX slave node process starts up.
If you specify false, if the CHMPX slave node process is not running, try to connect up to the trial upper limit.
The maximum number of trials is set when the CHMPX slave node process is started.

ChmpxNode::Close()

Discard(close) the message ID connected to the CHMPX slave node.

Format

bool Close(Buffer   msgid,
           Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

ChmpxNode::Send()

The data is sent from the ChmpxNode object connected to the CHMPX slave node side to the CHMPX server node side.

Format

int Send(Buffer   msgid,
         Buffer   body,
         bool     is_routing = true,
         Callback cbfunc = null
)

Arguments

Return Values

Return the CHMPX server node count which received the data for success, and on error return -1.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

The CHMPX server node process can be multiplexed according to the setting at startup.
When sending data from a slave node to a multiplexed CHMPX server node, it can route it to an auxiliary CHMPX server node when it can not connect to the target CHMPX server node.
If is_routing is set to true, if the CHMPX server node process is multiplexed, routing delivery is performed.
If set to false, the transmitted data will not be routed and delivered.

ChmpxNode::Broadcast()

Data is sent from the ChmpxNode object connected to the CHMPX slave node side to all CHMPX server nodes.

Format

int Broadcast(Buffer   msgid,
              Buffer   body,
              Callback cbfunc = null
)

Arguments

Return Values

Return the CHMPX server node count which received the data for success, and on error return -1.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

ChmpxNode::Receive() - For slave node

The ChmpxNode object connected to the CHMPX slave node receives the data from the CHMPX server node side.

Format

Function formats are different depending on synchronous and asynchronous.

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

In the case of synchronization, the callback functions Binary compkt and Buffer data for asynchronous are set in the array as the outarr argument.

ChmpxNode::Receive() - For server node

The ChmpxNode object connected to the CHMPX server node receives data from the CHMPX slave node side.

Format

Function formats are different depending on synchronous and asynchronous.

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

In the case of synchronization, the callback functions Binary compkt and Buffer data for asynchronous are set in the array as the outarr argument.

ChmpxNode::Reply()

Data is replied from the ChmpxNode object connected to the CHMPX server node to the CHMPX slave node side.

Format

bool Reply(Buffer   compkt
          Buffer   body,
          Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

This method is used by the client program of the CHMPX server node to reply to the CHMPX slave node.
To return data to the source CHMPX slave node, use Binary compkt returned when receiving data.

ChmpxNode::IsChmpxExit()

This method makes sure CHMPX process is running.

Format

bool IsChmpxExit(void)

Arguments

n/a

Return Values

Return false if the CHMPX process is running, and true if it is not running.

Examples

Build TOP Environments