Context newType Main

Context, newType and Main
Indus is a language for distributed computing. An Indus program that is implemented to run on a distributed network is the same as one implemented to run on a local machine. This is facilitated by new features in Indus like a program’s Context and mechanism to invoke agents and components over a network. As is probably evident by now, an Indus program executes in an Indus container. The Indus container provides services (see Chapter 5 for details) to agents and components hosted in them. An Indus container uses the Context of an agent or component to provide it with services such as service discovery, local and remote connections, transactions and policies. A program’s Context is therefore separate from the program itself that constructs and populates it.


 * 1.3.1 Contexts

A Context is of type Object.

A Context is created dynamically when an Agent or Component is instantiated. A Context of an Agent or Component contains meta-data on it. Meta-data contained in a Context is used for


 * Discovery of remote components and agents the component or agent communicates with
 * Establishing inter-operable, fault tolerant connections with remote components and agents
 * Routing messages across a network by the shortest, fault tolerant available to an agent or component
 * Specifying additional behavior at run time, i.e. setting contracts or policies
 * Facilitating Transaction management

When an agent or component is instantiated, it constructs its context and configures it according to information set by the programmer in the context constructor of the agent/component implementation.

For example:
 * public Context cx;
 * public Context{
 * //Set the context attributes
 * cx = new Context(this);
 * cx.setServantType(cx.USER);
 * cx.setPeerDetails("192.168.1.152",9001);
 * }

The Indus compiler checks for
 * Presence of the Context constructor
 * Referencing any Context only by using the cx handle

Setting of the ServantType correctly that allows only specific agent and component implementation types in Indus (see Section 1.4 and 1.5 below) A Context must be declared as public.


 * 1.3.2 newType

Before we discuss implementation types of agents and components in Indus, it is important to understand the use of newType in an Indus agent and component implementation.

newType in Indus is different from new in Java. Both facilitate class instantiation but in Indus, instantiations of classes that implement agents and components can also be done across a distributed network. This implies that newType in Indus also involves service discovery across a network.

In addition, newType realize the concept of client side handles and server side instances in Indus. Instances in Indus are of several types and these are referred to as ‘Implementation types’ in Section 1.4 and 1.5 below. Instances of agents and components behave differently in Indus by their implementation type, for example, some instances may be persistent and others not.

In Indus, newType is being used as
 * ClassName ClientHandle = newType ClassName([ServerInstanceID])

Where, ServerInstanceID is optional and where ClientHandle corresponds to the ServerInstance created using newType.


 * 1.3.3 Use of main

main(String[ ] args) does not get the same treatment in Indus as in Java. Like in Java, an Indus application or a set of Indus classes must have a main function to become accessible or invocable. However, main functions are not allowed to be implemented in Indus components as components are only supposed to be invoked from within Indus agent implementations. Even in the case of agents, main is used differently in the case of different agent implementation types (see Section 1.6 for details).

Next : Implementation of types Agents