Re: [Asterisk-java-devel] Does each received event creates a new Thread?
Brought to you by:
srt
From: Robert S. <rs...@as...> - 2016-02-14 22:34:29
|
The problem is that the reader thread for the asterisk-manager connection is used to handle the event, so if you push out any manager command/action you can't get the response because you are holding the reader thread. You must therefore do it on a separate asterisk-manager connection - and I would suggest separate thread as well, I can't recall if there is anything like ThreadLocal used in the manager connection implementation but it would be the safest option. On 15/02/16 08:17, Jose Baez wrote: > > Yes, I know. I took care of that already. > Thanks. > > But if i send and action that gets a 'response' (not an event) I guess > there is no problem to do it inside event handler, isn't it? > > El 14/02/2016 20:59, "S. Brett Sutton" <bs...@no... > <mailto:bs...@no...>> escribió: > > Yes you can create a new thread within the event handler. > > But 'safe', that will depend on what you do!!! > > It is actually often 'necessary' to create a new thread. For > instance if you fire an action that needs an event response then > you can't do that from the event handler as the event will be > blocked because you are in the event handling thread. > > On 12/02/16 19:13, Jose Baez wrote: >> >> Thanks for explanation. So, is it safe to create a new thread >> inside handleevent() to minimize blocking in main thread? >> >> Hehe, the code I posted is a piece of code extracted from full >> code that it is worlking. :) >> >> Thank you. >> >> El 12/02/2016 02:56, "S. Brett Sutton" <bs...@no... >> <mailto:bs...@no...>> escribió: >> > >> > By your code won't work as you haven't registered yourself as a >> listener. >> > >> > Have a look at the Hello Events example here; >> > >> > >> https://maven.reucon.com/projects/public/asterisk-java/1.0.0.CI-SNAPSHOT/asterisk-java/tutorial.html >> > >> > >> > >> > >> > >> > >> > On 12/02/16 11:09, S. Brett Sutton wrote: >> >> >> >> No, events are generated from a single 'event handling loop'. >> >> >> >> So whilst the event will generated in a different thread to >> you main thread all events come from one thread. >> >> >> >> Note: this does have implications when processing events. If >> the processing logic does long running tasks then you can block >> the event thread. If you do this for too long than asterisk will >> disconnect the manager connection. >> >> >> >> Brett >> >> >> >> On 11/02/16 21:32, Jose Baez wrote: >> >>> >> >>> Hello! >> >>> >> >>> >> >>> With this lines of code, when I receive a new Event, is a new >> Thread created for each "handleEvent()" ? Or will "handleEvent()" >> start to run when the previous "handleEvent" is completely finished? >> >>> >> >>> public class AsteriskJava implements ManagerEventListener { >> >>> >> >>> ... >> >>> ... >> >>> >> >>> public static main () { >> >>> >> >>> try { >> >>> >> >>> AsteriskJava asteriskJava = new AsteriskJava(); >> >>> asteriskJava.run(); >> >>> >> >>> } catch { } >> >>> } >> >>> >> >>> @Override >> >>> public void onManagerEvent(ManagerEvent event) { >> >>> >> >>> if (event.getClass() == NewExtenEvent.class) { >> >>> handleEvent((NewExtenEvent) event); >> >>> } >> >>> else if ((event.getClass() == ... >> >>> ... >> >>> ... >> >>> >> >>> } >> >>> >> >>> protected void handleEvent (NewExtenEvent event) { } >> >>> ... >> >>> ... >> >>> >> >>> } >> >>> ___ >> >>> ___ >> >>> >> >>> >> >>> >> >>> Thank you. >> >>> >> >>> >> >>> >> >>> >> >>> >> >>> >> ------------------------------------------------------------------------------ >> >>> Site24x7 APM Insight: Get Deep Visibility into Application >> Performance >> >>> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month >> >>> Monitor end-to-end web transactions and take corrective >> actions now >> >>> Troubleshoot faster and improve end-user experience. Signup Now! >> >>> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 >> >>> >> >>> >> >>> >> >>> _______________________________________________ >> >>> Asterisk-java-devel mailing list >> >>> Ast...@li... >> <mailto:Ast...@li...> >> >>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel >> >> >> >> >> > >> > >> > >> ------------------------------------------------------------------------------ >> > Site24x7 APM Insight: Get Deep Visibility into Application >> Performance >> > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month >> > Monitor end-to-end web transactions and take corrective actions now >> > Troubleshoot faster and improve end-user experience. Signup Now! >> > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 >> > _______________________________________________ >> > Asterisk-java-devel mailing list >> > Ast...@li... >> <mailto:Ast...@li...> >> > https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel >> > >> >> >> >> ------------------------------------------------------------------------------ >> Site24x7 APM Insight: Get Deep Visibility into Application Performance >> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month >> Monitor end-to-end web transactions and take corrective actions now >> Troubleshoot faster and improve end-user experience. Signup Now! >> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 >> >> >> _______________________________________________ >> Asterisk-java-devel mailing list >> Ast...@li... >> <mailto:Ast...@li...> >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > _______________________________________________ > Asterisk-java-devel mailing list > Ast...@li... > <mailto:Ast...@li...> > https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel > > > > ------------------------------------------------------------------------------ > Site24x7 APM Insight: Get Deep Visibility into Application Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140 > > > _______________________________________________ > Asterisk-java-devel mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel |