Start the node's synchronization.
MCO_RET mco_iot_replicator_sync(mco_iot_replicator_h repl, mco_iot_agent_id_t agent_id, int flags);
repl | The replicator object | ||||||||||||||||
agent_id |
The
|
||||||||||||||||
flags |
The bitmask value of a combination of the following synchronization flags:
|
The function starts the node's synchronization. Note that:
a ) If the
MCO_IOT_SYNC_WAIT
flag is not set, the function returns immediately after the data is written to the socket. The subsequent events, receiving ack for the push and data for the pull, must be handled in the callbacksb) The flags
MCO_IOT_SYNC_NONBLOCK
andMCO_IOT_SYNC_WAIT
are incompatiblec) The flag
MCO_IOT_SYNC_WAIT
is not allowable when theagent_id
isMCO_IOT_ALL_AGENTS
(it can’t synchronously wait for all agents to respond)
MCO_S_OK | Synchronization successfully started |
MCO_S_IOT_NO_NEW_DATA | No new data were inserted or updated since the previous call of mco_iot_replicator_sync() . Note that this is not error but status code |
MCO_E_IOT_INVALID_HANDLE | Invalid replicator handle repl |
MCO_E_ILLEGAL_PARAM | Incompatible parameter values (e.g. neither PULL nor PUSH specified; NONBLOCK and WAIT specified together etc.) |
MCO_E_IOT_WRONG_AGENT_ID | The agent_id is not valid
|
MCO_E_IOT_AGENT_NOT_FOUND | The device or server with the specified agent_id was not found |
MCO_E_NOMEM | Unable to allocate memory for internal structures |
MCO_E_WRITE_STREAM | Unable to write the replicated data to the socket |
MCO_E_SESLIMIT | Or other connect() errors if the function can't create a database connection |
mco_trans_start() errors |
Error starting a transaction |
errors |
Error committing a transaction |
other errors | Other errors can happen when accessing database to serialize changes |
The code snippet below initializes the ARF (IoT) runtime, opens and connects the database, creates the communicator and replicator objects, then connects and synchronizes the replicator:
int main(int argc, char *argv[]) { mco_db_params_t db_params; mco_device_t dev; mco_db_h db; mco_iot_replicator_params_t repl_params; mco_iot_comm_params_t comm_params; mco_iot_replicator_h repl; mco_iot_comm_h comm; const char *conn_string = (argc > 1) ? argv[1] : "127.0.0.1:15000"; ... /* Initialize eXtremeDB and IoT runtimes */ mco_error_set_handler(&sample_errhandler); mco_runtime_start(); mco_iot_init(); /* Create database */ dev.type = MCO_MEMORY_CONV; dev.assignment = MCO_MEMORY_ASSIGN_DATABASE; dev.size = DEVICE_DATABASE_SIZE; dev.dev.conv.ptr = (void*)malloc(dev.size); mco_db_params_init (&db_params); db_params.db_max_connections = 5; if (argc > 2) { db_params.iot_agent_id = atoi(argv[2]); /* Override the agent_id in the schema */ } CHECK(mco_db_open_dev(db_name, iotdevice_get_dictionary(), &dev, 1, &db_params)); CHECK(mco_db_connect(db_name, &db)); mco_iot_comm_params_init(&comm_params); CHECK(mco_iot_comm_create(&comm_params, &comm)); mco_iot_replicator_params_init(&repl_params); CHECK(mco_iot_replicator_create(db, comm, &repl_params, &repl)); ... CHECK(mco_iot_replicator_connect(repl, conn_string, 2*1000, 0)); ... CHECK(mco_iot_replicator_sync(repl, MCO_IOT_SERVER_AGENT_ID, MCO_IOT_SYNC_PULL | MCO_IOT_SYNC_PUSH | MCO_IOT_SYNC_WAIT)); }