Scripted Agents with Janus
Since version 0.5, the Janus platform provides the ability to code the agents with scripting languages. Scripting languages permits to use Janus for people who do not want to code in Java programming language. Moreover, scripting languages permits to dynamically build programs for the agents.
Most scripting languages are dynamically typed. You can usually create new variables without predetermining the variable type, and you can reuse variables to store values of different types. Also, scripting languages tend to perform many type conversions automatically, for example, converting the number 10 to the text "10" as necessary. Although some scripting languages are compiled, most languages are interpreted. Script environments generally perform the script compilation and execution within the same process. Usually, these environments also parse and compile scripts into intermediate code when they are first executed.
These qualities of scripting languages help you write applications faster, execute commands repeatedly, and tie together components from different technologies. Special-purpose scripting languages can perform specific tasks more easily or more quickly than can more general-purpose languages. For example, many developers think that the Perl scripting language is a great way to process text and to generate reports. Other developers use the scripting languages available in bash or ksh command shells for both command and job control. Other scripting languages help to define user interfaces or web content conveniently. Developers might use the Java programming language and platform for any of these tasks, but scripting languages sometimes perform the job as well or better. This fact doesn't detract from the power and richness of the Java platform but simply acknowledges that scripting languages have an important place in the developer's toolbox.
Combining scripting languages with the Janus platform provides to the developers an opportunity to leverage the abilities of both environments. You can continue to use scripting languages for all the reasons you already have, and you can use the powerful Java class library to extend the abilities of those languages. If you are a Java language programmer, you now have the ability to ship applications that your customers can significantly and dynamically customize. The synergy between the Java platform and scripting languages produces an environment in which developers and end users can collaborate to create more useful, dynamic applications.
The Janus platform provides wrappers to several the script language interpreters that are compliant with the JSR 223. For the interpreter that are not JSR 223, their integration in the Janus platform may require more works, but it is possible. See the tutorial "Adding a script interpreter in Janus" for details.
Janus Features for Scripting Interpeters
It is easy to integrate a script language interpreter in the Janus platform if it is compliant with the JSR 223.
The Janus platform must provide an extension of the script language interpreter that ensures:
- all the scripts are executed in the context of a single agent;
- there is no sharing of variables between two agent execution contexts.
- the functions defined in the Janus platform API are accessible from the scripts.
In addition to the extension of the script interpreter, the Janus platform also provides an extension of the Agent class that is dedicated to the execution of a script. In this case, the functions
liveAgent</end>, and <code>endAgent are the script equivalents to the three Java functions of the agent's life cycle (aka.
Adding a Script Interpeter into Janus
The tutorial "Adding a Script Interpreter into Janus" details how to write the Java code to support a new script language.