// Create low level VA representing processor cores, each VA element contains core 0 and core 1.Figure: Example of a JavaSymphony level-3 VA
VA c1 = new VA(new int[]{0,1},0);
VA c2 = new VA(new int[]{0,1},0);
VA c3 = new VA(new int[]{0,1},0);
VA c4 = new VA(new int[]{0,1},0);
//create a level 1 VA representing processor (in this case processor numbers are suplied as first argument and level value as second argument)
VA p1 = new VA(new int[]{0,1},1);
VA p2 = new VA(new int[]{0,1},1);
//Adds cores to processors
p1.addVA(c1); p1.addVA(c2);
p2.addVA(c3); p2.addVA(c4)
JSConstraints constr;
VA v1 = new VA(2); // simple level-1 VA
VA v2 = new VA(2,constr); // level-1 VA for which constraints holds
//Add processors to machines (level-2 VA), and machine to a cluster (level-3 VA)
v1.addVA(p1); v2.addVA(p2);
VA v3 = new VA(3,2); v3.addVA(v1); v3.addVA(v2);
VA v1 = new VA(5, new int[][] { {1,2,1}, {2,2} } );
VA v2 = new VA(4, new int[] {4,2} );v1.lock(); // lock v1 before modifying it
....
v1.addVA(v2);
v1.free(new int[] {2,1});
....
v1.unlock(); // unlock v1 after changes are done
....
v1.free(); // delete VA when it is not needed anymore
....For a detailed list of system parameters see the appropriate example.
// **** v1 will be a level-2 VA
float cpuIdle = v1.getSysParamAsFloat(JSConstraints.C_CPU_IDLE);
String sURL = v1.getSysParameterAsString(JSConstraints.C_HOST_URL);
int iSwap = v1.getSysParameterAsInt(JSConstraints.C_SWAP_AVAILABLE);
....
VA v2 = v1.getPred(v1.getLevel() + 1); // obtain the VA level and parent VA of v1
VA vn = v2.getVA(n); // obtain the n-th successor of v2
VA vLocal = VA.getLocalNode(); // obtain the local level-2 VA on which the code is running
....
int nrLeveli = v4.nrVA(i); // number of level-i VAs in v4
....
// how to traverse level-i VAs of v4
VAEnum e= v4.enumerateVA(i);
while (e.hasMoreVA())
{
VA v5 = e.nextVA();
..... // do some processing on v5....
}
.....
....We can also verify if initial constraints or new ones hold for a specific VA, like in the following excerpt:
JSConstraints constr = new JSConstraints();
constr.setConstraints(JSConstraints.C_HOST_URL , "!=", "milena");
constr.setConstraints(JSConstraints.C_CPU_IDLE , ">=", 90.0f);
constr.setConstraints(JSConstraints.C_CPU_SYS , "<=", 50);
constr.setConstraints(JSConstraints.C_MEMORY_FREE_KB , ">=", 10240);
....
VA v1 = new VA(2, constr); // requesting a level-2 VA which conforms the constraints in constr
....
....
boolean initialHolds = v.constrHold(); // check if initial constraints still hold
boolean itHolds = v.constrHold(constr); // check if new defined constraints constr hold
....
....
JSCodebase codebase = new JSCodebase(); // initialize a codebase
....
// **** adding a class file, an archive or an URL to the codebase
codebase.add("../classes.jar");
codebase.add("..testclass.class");
URL classURL = new URL("http://www.par.univie.ac.at/JS/test/file.class");
codebase.add(classURL);
...
codebase.load(v); // load the codebase on the VA v
codebase.free(); // free the codebase - its associated memory
....
VA v1 = new VA(2); // allocate a level-2 VA
VA v2 = new VA(4,....); // allocate level-4 VA
VA vLocal = VA.getLocalNode(); // get local level-2 VA
JSConstraints constr;
Object[] args = new Object[] {new Integer(10)}; // parameters for the new object as list of objects
....
//***** generate an object of class "ClassName''
JSObject obj1 = new JSObject("ClassName'' [, args] [, constr] [, vLocal]);
//***** generate an object on a higher level VA; JRS decides on which level-1 VA of v2 this object will be generated
JSObject obj1 = new JSObject("ClassName'',[args,] v2);
//***** generate object on a specific VA v1
JSObject obj1 = new JSObject("ClassName'',[args,] v1);
//***** convert a non-JSObject obj to a JS object obj2
ClassName obj = new ClassName(...);
JSObject obj2 = JSObject.convertToJSObject(obj [,multiThreaded]);
//***** Craete a single-threaded SJSObject on local node.
SJSObject sobj1 = new SJSObject(true,"ClassName",args);
//***** Craete a multi-threaded SJSObject on a Level-2 VA
SJSObject sobj2 = new SJSObject(false,"ClassName",args,v1);
boolean multiThreaded = true;
JSObject obj1 = new JSObject(multiThreaded, "ClassName'' [,args] [,v]);//***** objects can be made single- or multi-threaded at runtime
obj1.singleThreaded();
obj1.multiThreaded();
JSObject obj;
....
obj.lock() // lock object
.... // do some method invocation for the object -- no interruption from other threads
obj.unlock(); // unlock object
JSObject obj = new JSObject(ClassName'');
....
Object[] params = new Object[] {new Param1(), new Param2()}
Class[] paramTypes = new Class[] {Param1.getClass(),Param2.getClass()}; // optional types list
ResultClass result = (ResultClass)obj.sinvoke("methodName", params [,paramTypes] );
//**** invoke remote method with parameters; a handle is returned to refer to the method's result in the future
Object[] params = {new Param1(), new Param2()};
Class[] paramTypes = new Class[] {Param1.getClass(), Param2.getClass()};
ResultHandle handle = obj.ainvoke(``methodName'',params [,paramType]);
....
//**** verify whether result is available
if (handle.isReady()) {
// wait for result to arrive in blocking mode
ResultClass result = (ResultClass)handle.getResult ();
}
else
// do something else
....
//**** wait for result to arrive in blocking mode without checking for the result to be available
ResultClass result = (ResultClass)handle.getResult();
....
Object[] params = {new Param1(), new Param2()};
Class[] paramTypes = new Class[] {Param1.getClass(), Param2.getClass()};
obj.oinvoke(``methodName'',params [,paramTypes] );
JSConstraints constr;
VA v1 = new VA(2); VA v2 = new VA(5,...);
JSCodebase cb; JSObject obj;
boolean moveCodebase = true;
....
VA v3 = obj.getVA();
// **** if v3 on which obj resides has less than 50 % idle time or constr do not hold for v3
if (v3.getSysParam(JSConstraints.C_CPU_IDLE) < 50) || !v3.constrHold(constr))
{
obj.migrate(); // migrate object to a node destined by JRS
obj.migrate(constr, moveCodebase); // migrate object to a node according to a set of constraints and move all codebases as well
obj.migrate(v1); // migrate object to a specific node/level-1 VA
obj.migrate(v2); // migrate object to a node of v2 to be destined by JRS//**** specific codebase is moved to the destination VA
obj.migrate(va, cb);
obj.migrate(constr, cb);
obj.migrate(cb);
}
....
JSObject obj; String str;
str = obj.store(); // save object on external storage