Bashj programming guide

De Lillois Fractale Wiki
Aller à la navigation Aller à la recherche

This is a complement to the general bashj presentation page.

Understanding the architectire of bashj

The key idea behind bashj is the eexcution of a bashj server. It is JVM perfromin essentially two tasks

  1. translating bashj code into bash code
  2. execute any java method call for any running bashj client

The benefit of this is the extreme efficiency of this minimal architecture.

But the developper of a bashs script should be aware of the fact that any global component of the JVM (static variables, Threads,...) will be shared with all other bashj clients launched.

For instance if a client modifies a static variable during the execution of a bashj script, the next execution of the same script will start with the modified value of that variable. This may be convenient ... or not, depending on siuations. 

Using bashj as a pure java 'interpreter'

It is possible to create a bashj page without nay bash line. In this case, the interpreter will automatically call and execute the method  static void main(String... a) , as in this example:

#!/usr/bin/bashj
#@java
static void main(String... a)
{u.p("Hello world, welcome to bashj");}

This minimal but complete code will execute normally.

Convenience u methods

Various convenience methods are include with bashj. It is recommended to cheks their list using the command

bashj -u

or their javadoc.

Inter process communication using bashj

Given the persistence faetures of the bashj server, it is easy to set up fast IPC between bashj scripts.

The following u methods allow to set and get inter process variables:

public static void set(String key,String value,boolean scriptSpecific,boolean persist)
public static String get(String key,boolean scriptSpecific,boolean persist)

The scriptSpecific flag indicates if this value is shared or not with other scripts. These values will be kept during successive calls of the calling scripts, until the server is stopped.

The persist flag indicates whether the values should persist in the host  file system. These values will be saved when the server is stopped.