OP resolver (v0.3)

From Native Big Data Documentation
Jump to: navigation, search


In op , we have some functions used to interact with urp's and urn's...

Creating distributed objects

In op objects are created with the 'new' function:

var urp = "urp:obj:/test3";
var obj = [1,2,3,4,5,6,7,8,9];
var fragments = 3;
var server_list = null;
var replicas = 1;
var s = new(urp, obj, fragments, server_list, replicas);
"done"

The parameters of the new function are:

  • urp: The urp of the resource to be created.
  • obj: The object to transform in a resource.
  • fragments: If the object is an Array the size of each fragment. If the object is a Hash the number of fragments.
  • server_list: An array with a list of the urp's of the servers where the fragments will be stored. If null the object will be created

in the server tha runs the script.

  • replicas: The number of copies for every fragment. If more than one, the fragments will be stored in mirror mode on more than one server. The servers will be picked up from the server list.

The new command will return the proxy object that points to the object.

This script will store an array in two servers and will return '6'

var o = new("urp:obj:/test3", [1,2,3,4,5,6,7,8,9,10], 3, ["urp:server:/GRAY", "urp:server:/ANAKIN"], 2);
o[5]


Accessing distributed objects

In op objects are accessible with the 'i2r' , 'i2o' and i2rr functions:

i2o will return a proxy object that points to the resource. The following script will load the object created in the last example and will return its 6'th value (6):

var o = i2o("urp:obj:/test3");
o[5]

i2r will return a local object clonned from the resource. The following script will load the object created in the last example and will return its 6'th value (6):

var o = i2r("urp:obj:/test3");
o[5]

The differece between i2r and i2o is that i2o is a distributed object. This means than operations can be distributed over the NBD network and the object will be saved if it changes.

i2rr function will load a copy of the object pointed by a uri in RAM. i2rr only loads the object in the current server once and the object is a copy of the current object. Each access to the object in this server in the future will be using the local copy in RAM.

var o = i2rr("urp:obj:/test3");
o[5]