Thread: [Asterisk-java-users] FastAGI - creation of new AGIScript instance
Brought to you by:
srt
From: Alex <ab...@ga...> - 2005-09-28 18:54:05
|
Hi again: I have a question about the FastAGI implementation in Asterisk-Java. When Asterisk sends a request and the AGIServer processes it, does it = create a fresh new instance (object) of my AGIScript class? Or somehow it's using an old one? My question arises because when I make a second call, I print an = attribute of my AGIScript class on the first line of the method = "service". It's printing the value of the previous call. Thanks, Alejandro |
From: Stefan R. <sr...@re...> - 2005-09-28 19:40:59
|
> =20 > I have a question about the FastAGI implementation in Asterisk-Java. > When Asterisk sends a request and the AGIServer processes it, does it > create a fresh new instance (object) of my AGIScript class? > Or somehow it's using an old one? Currently there is only one instance of each AGIScript that serves every request so all instance variables are global to all calls. Is this a problem for you? I already thought about a config option to specify that behavior but till now there have been no such requests. =3DStefan |
From: Alex <ab...@ga...> - 2005-09-28 20:03:18
|
Hi Stefan: To tell you the truth, I allways tought that the AGIServer created one instance per call. So, it is good to know now that it's not that way. But this leads me to another question. How do you handle multiple calls with this architecture? If you do, can you please send me a working example? Thank you very much, Alejandro ----- Original Message ----- From: "Stefan Reuter" <sr...@re...> To: <ast...@li...> Sent: Wednesday, September 28, 2005 4:40 PM Subject: Re: [Asterisk-java-users] FastAGI - creation of new AGIScriptinstance |
From: Stefan R. <sr...@re...> - 2005-09-28 20:35:46
|
On Wed, 2005-09-28 at 17:04 -0300, Alex wrote: > Hi Stefan: >=20 > To tell you the truth, I allways tought that the AGIServer created one > instance per call. So, it is good to know now that it's not that way. > But this leads me to another question. How do you handle multiple calls w= ith > this architecture? If you do, can you please send me a working example? the easiest way is to declare your call-local variables in the service method instead of using attributes declared at class level. =3DStefan |
From: Alex <ab...@ga...> - 2005-09-28 20:55:27
|
Stefan: Thank you very much for taking the time to answer. I understand what you are saying, but inside the service method, I would be having (for instance) a list of "active calls" in which I would have to store the request and channel objects (received by the service method). And then, how do I play something in a given call? I'm asking this because the methods to answer/play/hangup... in version 0.2 doesn't have the channel parameter anymore. I've already tried to create a thread for each call, inside the service method, and when I issue any of the answer/play/hangup... methods, I get this error message: "Trying to send command from an invalid thread" Looks like AGIConnectionHandler.getChannel() is returning null in that case. Thanks again, Alejandro |
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 |
From: Alex <ab...@ga...> - 2005-09-29 14:34:16
|
Hi Stefan: I can't find the way to control the threads you mention. I'm surely missing something. What I want to do is play some greeting asynchronously in one of the active calls. Imagine that the caller and the agent are connected, and the agent clicks a button in my client application to send some text to the caller. How could I unlink the agent from the call, and play the greeting to the caller? Thanks, Alejandro |
From: Stefan R. <sr...@re...> - 2005-09-29 23:19:10
|
ok i didnt get that context. to do what you want you have to use the manager api and fastagi. what will that client application look like? e.g. how are the calls (asterisk channels) and the client application session linked? do you only want the announcement to be played to the caller or to both the caller and the agent? |
From: Alex <ab...@ga...> - 2005-09-30 13:50:55
|
Hi Stefan: Yes, in fact I'm using both the Manager api and fastagi. Yesterday, I come up with a possible solution to my problem, and it's this (maybe can be of help to someone else): I have a Server App that includes the AGIServer and has communication with all the Client Apps (the ones that the agents use). This server also is connected to Asterisk via the Manager api, so I could receive all the events and react to them. When Asterisk receives a call, the AGIServer calls the "service" method of my AGI Script, it answers the call, plays some greetings, and waits for commands of the Server App. The communication between the AGI Script and the Server App is made with network sockets. I have to work a little more in this to make sure that everything will work the way I'm thinking. The announcement will only be played to the caller, and to do that, I must release the agent from the call. Also to make the agent available to receive the next call. Well... what do you think? Thanks, Alejandro > ok i didnt get that context. > to do what you want you have to use the manager api and fastagi. > what will that client application look like? e.g. how are the calls > (asterisk channels) and the client application session linked? > do you only want the announcement to be played to the caller or to both > the caller and the agent? |
From: Stefan R. <sr...@re...> - 2005-10-03 12:17:17
|
> I have a Server App that includes the AGIServer and has communication wit= h > all the Client Apps (the ones that the agents use). This server also is > connected to Asterisk via the Manager api, so I could receive all the eve= nts > and react to them. > When Asterisk receives a call, the AGIServer calls the "service" method o= f > my AGI Script, it answers the call, plays some greetings, and waits for > commands of the Server App. > The communication between the AGI Script and the Server App is made with > network sockets. I have to work a little more in this to make sure that > everything will work the way I'm thinking. if the server app and the agi scripts run in the same virtual machine you dont need any network communication between the two. > The announcement will only be played to the caller, and to do that, I mus= t > release the agent from the call. Also to make the agent available to rece= ive > the next call. if you dont have to reconnect the caller and the agent again after the announcement has been played just using the redirect action will be fine. it will hang up the agent and forward the call to the agi script |