Re: [Asterisk-java-users] FastAGI - creation of newAGIScriptinstance
Brought to you by:
srt
|
From: Stefan R. <sr...@re...> - 2005-09-28 21:39:24
|
Its much easier...
thread handling is done by Asterisk-Java, so each call is served in one
thread but uses the same instance of your AGIScript. In 0.2-rc1 the
channel is bound to that thread so you dont need to pass it to the
answer/play/hangup/... methods, therefore you must not start another
thread or you will receive the error you just described.
Here is a short example:
import java.io.IOException;
import net.sf.asterisk.fastagi.AGIChannel;
import net.sf.asterisk.fastagi.AGIException;
import net.sf.asterisk.fastagi.AGIRequest;
import net.sf.asterisk.fastagi.BaseAGIScript;
import net.sf.asterisk.fastagi.DefaultAGIServer;
public class TestAGI extends BaseAGIScript
{
public void service(AGIRequest request, AGIChannel channel)
throws AGIException
{
// call local variables go here
String phoneNumber;
=20
// answer the call
answer();
=20
// read phone number, timeout 30 seconds, max length 10 digits
phoneNumber =3D getData("privacy-prompt", 30000, 10);
=20
// play entered number
if (phoneNumber !=3D null)
{
sayDigits(phoneNumber);
}
// end the call
streamFile("vm-goodbye");
hangup();
}
public static void main(String[] args) throws IOException
{
new DefaultAGIServer().startup();
}
}
=3DStefan
|