Re: [Asterisk-java-users] Timeout when hanging up
Brought to you by:
srt
From: Brett S. <bs...@no...> - 2005-11-08 21:53:10
|
Thanks for your help. I don't think you were the only one with you brain switched off, now that you point it out the problem is obvious. I'm not terribly interested in the result of the hangup so I would agree option 'a' should work nicely. Once again many thanks for you help. Brett. Stefan Reuter wrote: >Hi Brett, > >thank you for the trace. >Everything behaves correctly. I just had my brain switched off ;) > >At first some background information about how Asterisk-Java works: >Generally when using the ManagerConnection there are two threads >involved. Your "normal" application thread ("Main") and an addtional >thread for the ManagerReader. >The ManagerReader thread reads repsonses and events from Asterisk and >dispatches them to the event and repsonse handlers. > >What happened in your case is the following: > >You register an event handler that is called on a NewChannelEvent. This >event hanler is called from the ManagerReader thread. Now you send a >HangupAction to Asterisk and wait for the response. The response can >only be read and dispatched by the ManagerReader thread but that >ManagerReader thread is already blocked waiting for the response... a >deadlock. > >So what to do in such a case? >Generally don't do anything that blocks the ManagerReader thread in >event handlers. So you have two options: >a) send the HangupAction in a non-blocking way: >managerConnection.sendAction(hangup, null); >b) create an additional thread that does the hangup and only >asynchronously inform that thread in your handleEvent() method > >I think a) will be sufficient in this case. (but you loose the resposne >to the hangup action) > >=Stefan > > > > |