Instantiating Agents and Components

Instantiation of agents and components can happen in two ways
 * From the console by invoking a main function (allowed only in agents)
 * By using newType within the implementation of an agent or component

A User agent can be invoked from console by running it using the irun command and supplying its ID as an optional parameter (indus –irun   ), followed by other parameters for program processing if that is required.

In this case, the User agent is deployed into the container before transfer is passed to the main function in the agent implementation.
 * If an ID is passed as a main function parameter, the agent class implementation can access it with args[0] and use it to create an instance of the agent in the Indus container using newType which will make the instance available to the network.
 * If the ID is passed as a main function parameter and the implementation does not use it to create an instance of the agent in the container, the implementation will still serve as a client facing peer that can instantiate and invoke peers across the network. This is most commonly seen in Indus clients implementing only GUI functionality. However, if an Indus client facing peer implements a mix of pure client software like a GUI and business logic, it is advisable to use newType to create an instance of the agent in the Container before invoking business logic functions using instanceName.functionName. This will enable the state of the agent to be persisted in the Container for processing later on.
 * If an AgentID is not passed through main as a parameter, an agent class implementation can still use an ID (hard coded in the implementation by the developer) to instantiate agents in the Container.

A User agent can also be implemented without a main function. In that case, it can only be invoked from within the implementation of another User or Process agent using newType. If an AgentID is passed as a parameter using –irun to a User agent without a main function, it will be ignored so will be other parameters that may be passed through command line. When irun is used in the case of User agents without a main function, the agent will be deployed into the container and then control transferred back to the console.

The same instantiation rules apply to Process Agents barring the use of AgentID. A Process agent can be invoked from console by running it using the irun command (indus –irun  ), followed by other parameters for program processing if that is required. An agentID is not required to be passed for instantiation of Process agents as only one instance of a Process agent is allowed to exist across a network. In this case, the Process agent is deployed into the container before transfer is passed to the main function in the agent implementation
 * If a Process agent implements only client facing software such as a GUI, a developer may decide not to create a new instance of the agent in the container
 * However, if a Process agent implements a mix of application logic and client facing functionality, creating a new instance is advisable as it allows the state of the agent to be persisted. Like in the case of User agents, client facing functionality need to be invoked by simply calling the local function, not by invoking the same function in the newly created agent instance.
 * A Process agent can also be implemented without a main function. In that case, it can only be invoked from within the implementation of another User or Process agent using newType. If any parameters are passed to a Process agent without a main function, they will be ignored. When irun is used in the case of Process agents without a main function, the agent will be deployed into the container and then control transferred back to the console.

Components, both of Session and Service implementation types cannot implement a main function as they can only be invoked from within the class implementations of other agents and components using newType. The irun command used on components simply deploys them in the container before passing control back to the command console.