Tutorial: Building an Rogue Wave Server Application > Using Dynamic Modeling Services > Defining the Behavior of the Application > The OnLoad Function
 
The OnLoad Function
This task consists in defining an OnLoad script function in a text file which will be read by the dynamic server at startup. This function will be invoked from the dynamic server main function after the model has been initialized. Its performs the following actions:
*Create some objects
*Initialize their state
*Declare some objects to the dynamic view server
Write the OnLoad method as follows:
function OnLoad(args)
{
var network = new Network("TheNetwork");
MvServer.DeclObjectLabel(network, network.identifier);
 
for (i=0; i<4; i++) {
var name = "Domain_" + i;
var d = new Domain(name);
network.domains.add(d);
var nodes = new Array(5);
for (j=0; j<5; j++) {
nodes[j] = new Node();
nodes[j].name = "Node_" + i + "_" + j;
d.nodes.add(nodes[j]);
}
for (k=0; k<4; k++) {
var l = new Line();
l.name = "Link_" + i + "_" + k;
l.input = nodes[k];
l.output = nodes[k+1];
var r = Math.random() * 10;
l.capacity = Math.round(r);
d.lines.add(l);
}
}
 
}
The first line creates a new Network object. As you have declared the Network class as “identified”, you can specify a name in the constructor. And because you have declared a dictionary for this class, this new instance will be automaticaly stored in that dictionary.
The second line declares the instance of the class Network to the dynamic view server so that this instance will be accessible from the Connection Panel.
The rest of the code creates several instances of the other classes of the Network model.

Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.