| T a n e s h a N e t w o r k s |
Jast Agi is a framework for rapid development of FastAGI applications for the Asterisk PBX in Java.
I wrote it because I like Java and I needed something to do AGIs with. Now later, ofcause I noticed that someone had already done this work in the JAGIServer, you should probably check out both projects and evaluate which you like better. To sum up the main differences, JAGIServer uses a thread to keep track of each connection to Asterisk, while JastAgi uses java.nio and selectors to multiplex all in one thread.
Also, it is OpenSource and licensed under ApacheLicense - enough with the hype ;-)
If you dont know what AGI is, then likely you dont need this piece of software. You can find a spec. of AGI in Asterisk here: http://home.cogeco.ca/~camstuff/agi.html
You can do everything that you normally do in AGIs, except you cannot rely on the local filesystem to be the same as the one on the Asterisk machine. Eg. Record function can record a file, but you might not be able to access it since it could be on another physical box.
It is however great for eg. billing in Asterisk where you traditionally have the overhead of compiling and running a big Perl script.
Another advantage is that you're running in the multithreaded Java environment where you can easily extend functionality into very advanced applications, eg. for monitoring simultaneous calls.
This is for version 2 of JastAgi, it still needs little polishing.
//
// build a start node of what is going to happen
//
Node start = new Node(CommandFactory.createAnswer()).
transition(Transition.response(200).
set(new Node(CommandFactory.createStreamFile("tt-monkeys", null)))).
transition(Transition.error().
set(New Node(CommandFactory.createStreamFile("error", null))));
//
// create a new engine.
//
Engine agiEngine = new Engine();
//
// add our new handler for /test.
//
agiEngine.addHandler("/test", new StateHandler(start));
//
// make another handler and add it (shows how to get some code executed and delegate to an
// command for execution).
//
agiEngine.addHandler("/setdialstring", new StateHandler(new Action() {
// Implement Action
public void execute(Context context) throws AgiException {
// create some dialstring.
String dialString = new StringBuffer("SIP/").append(context.getExtension()).
append("@").append(getRandomGateway()).toString();
Command dialCmd = CommandFactory.createSetVariable("DIALSTRING", dialString);
dialCmd.execute(context);
}
});
//
// run the engine (in current thread), listening for connections on port 5071.
//
agiEngine.run(5071);
You can also see the full example in the CVS.
If you plan to use our work in your company or project then please consider to say thanks by giving us a few bucks for the time we put into this. You can click on the paypal button below to give 10 Euro - Thanks!
(So far: 0.00 EUR made on this project :-( )This can also be found in the CVS by following the link above. There is also some (possibly outdated) JastAgiJavadoc which you can read.