Build TOP Environments

For developer

Common

Synchronous and Asynchronous
About Classes
Permanent and Onetime Connection

k2hdkc Class

k2hdkc::Init()
k2hdkc::Clean()
k2hdkc::IsPermanent()
k2hdkc::GetValue()
k2hdkc::GetSubkeys()
k2hdkc::GetAttrs()
k2hdkc::SetValue()
k2hdkc::SetSubkeys()
k2hdkc::SetAll()
k2hdkc::Remove()
k2hdkc::Rename()
k2hdkc::QueuePush()
k2hdkc::QueuePop()
k2hdkc::QueueRemove()
k2hdkc::CasInit()
k2hdkc::CasGet()
k2hdkc::CasSet()
k2hdkc::CasIncDec()
k2hdkc::PrintVersion()


Common

Synchronous and Asynchronous

The methods of the classes provided by K2HDKC 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

K2HDKC Node.js addon library provides k2hdkc class.
This class provides connection and data manipulation to the K2HDKC.

Permanent and Onetime Connection

To connect to K2HDKC cluster using K2HDKC Node.js addon library, there are two methods of permanent connection and connection for each data operation(onetime connection).

Permanent Connection

When initializing main class k2hdkc object of K2HDKC Node.js addon library, establish connection to K2HDKC cluster.
All data manipulation of the K2HDKC cluster using this object is executed through the connection set up at initialization.
Permanent connection reduces the overhead for the connection to the K2HDKC cluster per data operation.

Onetime Connection (for each data operation)

Onetime Connection method connects to the K2HDKC cluster every operation of data and disconnects after completion of the processing.
Therefore, when initializing main class k2hdkc object of K2HDKC Node.js addon library, it does not connect to the K2HDKC cluster.
Onetime Connection overhead occurs for each data operation of the K2HDKC cluster.

Using Permanent and Onetime connection at same time

The setting of Permanent Connection and Onetime connection is each k2hdkc object and has no influence on each other.
Therefore, you can use these at the same time by creating k2hdkc objects for persistent connection and one time connection.


k2hdkc Class

K2HDKC Node.js addon library provides this k2hdkc class. This class is the only class of K2HDKC Node.js addon library.
You can use this class to connect to K2HDKC cluster and manipulate data int it.

A sample to create this class object is shown below.

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

k2hdkc::Init()

This method initializes the k2hdkc object for Permanent Connection or Onetime Connection.

Format

bool Init(String   conf = null,
          int      port = -1,
          bool     auto_rejoin = false,
          bool     no_giveup_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 type(four case) implementations.

k2hdkc::Clean()

This method performs the termination processing of k2hdkc object and destroys the object.

Format

bool Clean(void)

Arguments

n/a

Return Values

Always return true.

Examples

k2hdkc::IsPermanent()

This methods checks whether the k2hdkc object is initialized as a Permanent Connection.

Format

bool IsPermanent(void)

Arguments

n/a

Return Values

If the k2hdkc object is initialized as a Permanent Connection, it returns true. Otherwise it returns false.

Examples

k2hdkc::GetValue()

This method gets the key and subkey values from the K2HDKC cluster.

Format

Arguments

Return Values

In the case of synchronous processing, it returns the read value when it completes normally, and null if it is an error.
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 type(four case) implementations.

Notes

This method can specify keys and subkeys at the same time.
Normally, if you read the value of the key, you can read it by just specifying the key name.
The meaning of specifying the key and subkey at the same time is that the subkey must be associated with the key.
If the subkey is not tied to a key, this method does not read the value and returns an error.

k2hdkc::GetSubkeys()

This method gets the list of subkeys tied to the key.

Format

Arguments

Return Values

In the case of synchronous processing, when it completes normally, Array is returned as the list of subkeys, and null is returned in case of error.
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 type(four case) implementations.

k2hdkc::GetAttrs()

This method gets a list of attribute names set in the key.

Format

Arguments

Return Values

In the case of synchronous processing, when it completes normally, Array is returned as the list of read attribute names, null is returned in case of error.
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 type(four case) implementations.

k2hdkc::SetValue()

This method sets values for keys or subkeys under key.

Format

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 type(four case) implementations.

k2hdkc::SetSubkeys()

This method sets(overwrites) or clears the list of subkeys associated with the key.

Format

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 type(four case) implementations.

k2hdkc::SetAll()

This method sets the key value and subkey list at once.

Format

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 type(four case) implementations.

k2hdkc::Remove()

This method removes the key.

Format

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 type(four case) implementations.

k2hdkc::Rename()

This method changes the key name.

Format

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 type(four case) implementations.

k2hdkc::QueuePush()

This method pushes the data to K2HDKC queue.

Format

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 type(four case) implementations.

k2hdkc::QueuePop()

This method pops the data from K2HDKC queue.

Format

Arguments

Return Values

On successful completion, when it is Queue type, it returns the popped value.
For KeyQueue, set the key name and value to Array and return it.
If an error occurs, null is returned.
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 type(four case) implementations.

k2hdkc::QueueRemove()

This method removes the data from K2HDKC queue without reading the value.

Format

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 type(four case) implementations.

k2hdkc::CasInit()

This method initializes the key and value as CAS(Compare and Swap).

Format

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 type(four case) implementations.

k2hdkc::CasGet()

This method gets the value by key as CAS(Compare and Swap).

Format

Arguments

Return Values

It returns the value(int32) at normal termination. undefined is returned when an error such as the absence of the key exists.
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 type(four case) implementations.

k2hdkc::CasSet()

This method sets the value to the key as CAS(Compare and Swap).

Format

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 type(four case) implementations.

k2hdkc::CasIncDec()

This method increments/decrements the value for the key as CAS(Compare and Swap).

Format

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 type(four case) implementations.

k2hdkc::PrintVersion()

This method puts the version about K2HDKC Node.js addon library.

Format

bool PrintVersion(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hdkc = require('bindings')('k2hdkc');
var dkcobj = new k2hdkc();

dkcobj.PrintVersion();
Build TOP Environments