7.3. Requesting Replication

This chapter describes how to request replication of an object and how to cancel a replication request.

7.3.1. Using Methods of Object

To request replication of an object to given node, call replicate_to() method of Object. To cancel replication of an object, call cancel_replication:

void Object::replicate_to
    (
    WeakPointer< Object > destination_node,
    const STime &         timeout
    );

void Object::cancel_replication
    (
    WeakPointer< Object > destination_node
    );

The destination_node argument must point to a node object (see Section 14.2, “Node Object”). This is an important difference from migration - while migration is addressed by destination object, replication request is addressed by destination node.

The timeout argument specifies simulation time when replication of the object will be stopped and the object replica will be destroyed. The replication timeout will be set to this value, even if replication request of the object to given node exists, and its replication timeout is larger. Setting the timeout to the past (default-constructed value of STime is always in the past) will effectively cancel the replication. Actually the cancel_replication is just a properly named shortcut for replicate_to with such timeout.

7.3.2. Node Object Pointers

Pointers in general are described in Chapter 5, Pointers, and node objects are described in Section 14.2, “Node Object”. This section just repeats the most useful information regarding object replication.

Pointer to a node object can be easily constructed from a node id:

NodeId node_id = ...;
WeakPointer< Object > node_object( ObjectId( node_id ) );

To get node id of the local node, call:

const NodeId local_node_id = System::get_local_node_id();

Because replicate_to() can be called remotely (see Chapter 8, Remote Procedure Call), it's easy to request replication of a remote object foo to local node:

Remote< Object > foo = ...;
foo->async_replicate_to( ObjectId( System::get_local_node_id() ), STime( 60.0 ) );

Obtaining pointer to node object of a client node is also relatively easy. When client connects to the simulation, it calls method client_connected() of AccountObjectInterface and passes pointer to its node object as the only argument:

virtual void AccountObjectInterface::client_connected
    (
    const WeakPointer< NodeObjectInterface > & node_object
    ) = 0;

Refer to Section 14.3, “Account Object” for information about account objects. You should also check implementation of account object in Massiv Demo (files src/demo/lib/shared/account_object.*).

7.3.3. Requesting Replication by RPC

Remote procedure call to a object can automatically trigger its replication to callee node. This is described in Section 8.5.1, “Triggering Replication by RPC”.