[Asterisk-java-users] Multithreaded AGI script
Brought to you by:
srt
From: Sebastian G. <sc...@gm...> - 2012-09-25 17:52:03
|
Hi, I´m using AGI scripts for the first time, I have now my server with the default AGI server and mapping via the Class Name, all that working ok. the thing is that I want to be able to make a monitor thread, that be able to append some commands also to the AGI channel. I put here an example, I want that while executing the streamFiles, the system also executes on that channel the verbose log. is this possible??? this won´t work, the monitor apparently can't intervene in the AgiChannel. for example: THE SCRIPT CLASS: @Override public void service(AgiRequest request, AgiChannel channel) throws AgiException { // Answer the channel... answer(); Monitor r = new Monitor(channel,request); new Thread(r).start(); // ...say hello... streamFile("demo-nogo"); streamFile("tt-monkeysintro"); streamFile("tt-weasels"); streamFile("demo-nogo"); // ...and hangup. hangup(); } THE MONITOR CLASS public class Monitor implements Runnable { private AgiChannel chan; private AgiRequest req; public Monitor(AgiChannel channel, AgiRequest request) { chan = channel; req = request; } @Override public void run() { while(true) { try { chan.verbose("ASYNC TEST", 1); Thread.sleep(1000); } catch (Exception ex) { Logger.getLogger(Monitor.class.getName()).log(Level.SEVERE, null, ex); } } } |