Thread: [Asterisk-java-users] EVENT LISTENER PROBLEM
Brought to you by:
srt
From: Daniele R. <dan...@gm...> - 2009-07-21 17:18:46
|
Hi, I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a small problem with ManagerEventListener. I'm using the listener to catch the event about a call that I've scheduled from Java. I create a automatic call in this mode: action.setContext(sContext); action.setExten(sExten); action.setPriority(new Integer(iPriority)); action.setTimeout(new Long(iTimeout)); action.setActionId(""+telefonata.getId()); action.setAsync(true); All works fine if I make only ONE call at same time, but if I try to make two or more calls I am not be able to detect wich events are of the first call and which are of the second call. The unique id of the events are not linked to the action that I've submitted and the actionId that I can set is not included in the response event. So how I can detect exactly the events of each call separatly? Thanks very much for your help! Best regards -- Daniele Renda |
From: Martin B. S. <ma...@mb...> - 2009-07-21 17:28:15
|
Hi Daniel, That snippet doesn't help much; you don't even provide the declaration of the action variable or how you send it. Any number of things could be going on here, and we don't really have enough information to diagnose the problem. Furthermore, depending on how your dialplan is setup, your ability to determine which events correspond to which calls could be impaired. We'd really need a complete example of how you create and send the action, and how you handle the response; we'd also need to see any relevant dialplan contexts that the call may go into. Good luck, Martin Daniele Renda wrote: > Hi, > I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a > small problem with ManagerEventListener. I'm using the listener to > catch the event about a call that I've scheduled from Java. I create a > automatic call in this mode: > > > action.setContext(sContext); > action.setExten(sExten); > action.setPriority(new Integer(iPriority)); > action.setTimeout(new Long(iTimeout)); > action.setActionId(""+telefonata.getId()); > action.setAsync(true); > > All works fine if I make only ONE call at same time, but if I try to make > two or more calls I am not be able to detect wich events are of the > first call and which are of the second call. > The unique id of the events are not linked to the action that I've > submitted and the actionId that I can set is not included in the > response event. So how I can detect exactly the events of each call > separatly? > > > Thanks very much for your help! > Best regards |
From: Daniele R. <dan...@gm...> - 2009-07-21 18:18:16
|
Hi Martin, the code is quite structurated but I try to paste the relevant points: *CREATE THE ACTION (in a thread. This action then is send to the Manager thread that send the action to Asterisk) action.setContext(sContext); action.setExten(sExten); action.setPriority(new Integer(iPriority)); action.setTimeout(new Long(iTimeout)); action.setActionId(""+telefonata.getId()); action.setAsync(true); *MANAGER (is a thread that send the action to Asterisk and waint ultil the HangupEvent is throw or untile timeout) ManagerConnectionFactory factory = new ManagerConnectionFactory(asteriskHost, asteriskManagerPort, asteriskManagerUser, asteriskManagerPsw); this.managerConnection = factory.createManagerConnection(); log.debug("Creata connessione al server Asterisk " + managerConnection.getState()); managerConnection.addEventListener(this.managerEventListener); managerConnection.sendAction(getAsteriskAction(), 300000000); try { Thread.sleep(180000); } catch (InterruptedException ex) { } } log.debug("Sto effettuato la disconnessione dal Manager di Asterisk sull'host " + managerConnection.getHostname()); managerConnection.logoff(); *EVENT LISTENER (the listener to asterisk Event) @Override public void onManagerEvent(ManagerEvent event) { log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); The listener is very long and intercept all the events to asterisk. *DIALPLAN The action that run from Java code is somethig as this: Dial(trunk/telephoneNumber), extension s, priority 1, context [context] exten => s,1,Answer() ;I play a message exten => s,2,Background(custom/message/intro) exten => s,3,Hangup() In few words, this is an automatic call system that calls many users and play them a simple vocal message. My problem is that in the events that asterisk send to me (througt Asterisk Java) there isn't something that tell to me which call the refers. Infact all calls go to [context] and all make same things. Thanks Best regards 2009/7/21 Martin B. Smith <ma...@mb...>: > Hi Daniel, > > That snippet doesn't help much; you don't even provide the declaration > of the action variable or how you send it. Any number of things could be > going on here, and we don't really have enough information to diagnose > the problem. > > Furthermore, depending on how your dialplan is setup, your ability to > determine which events correspond to which calls could be impaired. > > We'd really need a complete example of how you create and send the > action, and how you handle the response; we'd also need to see any > relevant dialplan contexts that the call may go into. > > Good luck, > > Martin > > > > Daniele Renda wrote: >> Hi, >> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >> small problem with ManagerEventListener. I'm using the listener to >> catch the event about a call that I've scheduled from Java. I create a >> automatic call in this mode: >> >> >> action.setContext(sContext); >> action.setExten(sExten); >> action.setPriority(new Integer(iPriority)); >> action.setTimeout(new Long(iTimeout)); >> action.setActionId(""+telefonata.getId()); >> action.setAsync(true); >> >> All works fine if I make only ONE call at same time, but if I try to make >> two or more calls I am not be able to detect wich events are of the >> first call and which are of the second call. >> The unique id of the events are not linked to the action that I've >> submitted and the actionId that I can set is not included in the >> response event. So how I can detect exactly the events of each call >> separatly? >> >> >> Thanks very much for your help! >> Best regards > > > ------------------------------------------------------------------------------ > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > -- Daniele Renda |
From: Martin B. S. <ma...@mb...> - 2009-07-21 19:07:25
|
What class is action? Is it OriginateAction? For OriginateActions, Asterisk-Java has the ability to give you all of the events associated with the OriginateAction, through the OriginateResponseEvent. In your case, you're asking Asterisk-Java to send an action, wait 300000000 ms for a resultant event, and then do nothing with it. You're also looking at ((AbstractChannelEvent)event).getUniqueId(), which is the unique name of the channel. It won't contain your actionId. Since you do *not* want to wait for the result of the originate (you want to do more originates), you may want to use the callback version: void sendAction(ManagerAction action, SendActionCallback callback) "Sends a ManagerAction to the Asterisk server and registers a callback handler to be called when the corresponding ManagerResponse is received." And then ideally, the response should be an OriginateResponse: void onResponse(ManagerResponse response) Finally, have you considered using a proxy so you aren't sending actions and handling events in the same thread? http://asterisk-java.org/development/apidocs/org/asteriskjava/manager/ManagerEventListenerProxy.html Good luck, Martin Daniele Renda wrote: > Hi Martin, > the code is quite structurated but I try to paste the relevant points: > *CREATE THE ACTION (in a thread. This action then is send to the > Manager thread that send the action to Asterisk) > action.setContext(sContext); > action.setExten(sExten); > action.setPriority(new Integer(iPriority)); > action.setTimeout(new Long(iTimeout)); > action.setActionId(""+telefonata.getId()); > action.setAsync(true); > > *MANAGER (is a thread that send the action to Asterisk and waint ultil > the HangupEvent is throw or untile timeout) > ManagerConnectionFactory factory = new > ManagerConnectionFactory(asteriskHost, asteriskManagerPort, > asteriskManagerUser, asteriskManagerPsw); > this.managerConnection = factory.createManagerConnection(); > log.debug("Creata connessione al server Asterisk " + > managerConnection.getState()); > managerConnection.addEventListener(this.managerEventListener); > managerConnection.sendAction(getAsteriskAction(), 300000000); > try { > Thread.sleep(180000); > } catch (InterruptedException ex) { > } > } > log.debug("Sto effettuato la disconnessione dal Manager di Asterisk > sull'host " + managerConnection.getHostname()); > managerConnection.logoff(); > > *EVENT LISTENER (the listener to asterisk Event) > @Override > public void onManagerEvent(ManagerEvent event) { > log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); > > The listener is very long and intercept all the events to asterisk. > > *DIALPLAN > The action that run from Java code is somethig as this: > Dial(trunk/telephoneNumber), extension s, priority 1, context > > [context] > exten => s,1,Answer() > ;I play a message > exten => s,2,Background(custom/message/intro) > exten => s,3,Hangup() > > In few words, this is an automatic call system that calls many users > and play them a simple vocal message. > My problem is that in the events that asterisk send to me (througt > Asterisk Java) there isn't something that tell to me which call the > refers. Infact all calls go to [context] and all make same things. > > Thanks > > Best regards > > > > 2009/7/21 Martin B. Smith <ma...@mb...>: >> Hi Daniel, >> >> That snippet doesn't help much; you don't even provide the declaration >> of the action variable or how you send it. Any number of things could be >> going on here, and we don't really have enough information to diagnose >> the problem. >> >> Furthermore, depending on how your dialplan is setup, your ability to >> determine which events correspond to which calls could be impaired. >> >> We'd really need a complete example of how you create and send the >> action, and how you handle the response; we'd also need to see any >> relevant dialplan contexts that the call may go into. >> >> Good luck, >> >> Martin >> >> >> >> Daniele Renda wrote: >>> Hi, >>> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >>> small problem with ManagerEventListener. I'm using the listener to >>> catch the event about a call that I've scheduled from Java. I create a >>> automatic call in this mode: >>> >>> >>> action.setContext(sContext); >>> action.setExten(sExten); >>> action.setPriority(new Integer(iPriority)); >>> action.setTimeout(new Long(iTimeout)); >>> action.setActionId(""+telefonata.getId()); >>> action.setAsync(true); >>> >>> All works fine if I make only ONE call at same time, but if I try to make >>> two or more calls I am not be able to detect wich events are of the >>> first call and which are of the second call. >>> The unique id of the events are not linked to the action that I've >>> submitted and the actionId that I can set is not included in the >>> response event. So how I can detect exactly the events of each call >>> separatly? >>> >>> >>> Thanks very much for your help! >>> Best regards >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Asterisk-java-users mailing list >> Ast...@li... >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >> > > > |
From: Daniele R. <dan...@gm...> - 2009-07-22 06:13:20
|
Hi Martin, yes the action is an OriginateAction. I've a problem with your example. Infact I'm using the listener beacuse of I'd like to catch all events of a call (che NewChannelEvent,NewStateEvent,DtmfEvent,HangupEvent,ecc ecc). Instead with the : managerConnection.sendAction(getAsteriskAction(), new SendActionCallback() { @Override public void onResponse(ManagerResponse response) { log.debug("received message "+response); } }); I'll received only ONE response to my action (probably: action queued successfuly). So this is the cause of the fact that I'm using a listener to the manager in order to catch every event. THanks Best regards 2009/7/21 Martin B. Smith <ma...@mb...>: > What class is action? Is it OriginateAction? > > For OriginateActions, Asterisk-Java has the ability to give you all of > the events associated with the OriginateAction, through the > OriginateResponseEvent. > > In your case, you're asking Asterisk-Java to send an action, wait > 300000000 ms for a resultant event, and then do nothing with it. > > You're also looking at ((AbstractChannelEvent)event).getUniqueId(), > which is the unique name of the channel. It won't contain your actionId. > > Since you do *not* want to wait for the result of the originate (you > want to do more originates), you may want to use the callback version: > > void sendAction(ManagerAction action, SendActionCallback callback) > > "Sends a ManagerAction to the Asterisk server and registers a callback > handler to be called when the corresponding ManagerResponse is received." > > And then ideally, the response should be an OriginateResponse: > void onResponse(ManagerResponse response) > > Finally, have you considered using a proxy so you aren't sending actions > and handling events in the same thread? > http://asterisk-java.org/development/apidocs/org/asteriskjava/manager/ManagerEventListenerProxy.html > > Good luck, > > Martin > > > > Daniele Renda wrote: >> Hi Martin, >> the code is quite structurated but I try to paste the relevant points: >> *CREATE THE ACTION (in a thread. This action then is send to the >> Manager thread that send the action to Asterisk) >> action.setContext(sContext); >> action.setExten(sExten); >> action.setPriority(new Integer(iPriority)); >> action.setTimeout(new Long(iTimeout)); >> action.setActionId(""+telefonata.getId()); >> action.setAsync(true); >> >> *MANAGER (is a thread that send the action to Asterisk and waint ultil >> the HangupEvent is throw or untile timeout) >> ManagerConnectionFactory factory = new >> ManagerConnectionFactory(asteriskHost, asteriskManagerPort, >> asteriskManagerUser, asteriskManagerPsw); >> this.managerConnection = factory.createManagerConnection(); >> log.debug("Creata connessione al server Asterisk " + >> managerConnection.getState()); >> managerConnection.addEventListener(this.managerEventListener); >> managerConnection.sendAction(getAsteriskAction(), 300000000); >> try { >> Thread.sleep(180000); >> } catch (InterruptedException ex) { >> } >> } >> log.debug("Sto effettuato la disconnessione dal Manager di Asterisk >> sull'host " + managerConnection.getHostname()); >> managerConnection.logoff(); >> >> *EVENT LISTENER (the listener to asterisk Event) >> @Override >> public void onManagerEvent(ManagerEvent event) { >> log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); >> >> The listener is very long and intercept all the events to asterisk. >> >> *DIALPLAN >> The action that run from Java code is somethig as this: >> Dial(trunk/telephoneNumber), extension s, priority 1, context >> >> [context] >> exten => s,1,Answer() >> ;I play a message >> exten => s,2,Background(custom/message/intro) >> exten => s,3,Hangup() >> >> In few words, this is an automatic call system that calls many users >> and play them a simple vocal message. >> My problem is that in the events that asterisk send to me (througt >> Asterisk Java) there isn't something that tell to me which call the >> refers. Infact all calls go to [context] and all make same things. >> >> Thanks >> >> Best regards >> >> >> >> 2009/7/21 Martin B. Smith <ma...@mb...>: >>> Hi Daniel, >>> >>> That snippet doesn't help much; you don't even provide the declaration >>> of the action variable or how you send it. Any number of things could be >>> going on here, and we don't really have enough information to diagnose >>> the problem. >>> >>> Furthermore, depending on how your dialplan is setup, your ability to >>> determine which events correspond to which calls could be impaired. >>> >>> We'd really need a complete example of how you create and send the >>> action, and how you handle the response; we'd also need to see any >>> relevant dialplan contexts that the call may go into. >>> >>> Good luck, >>> >>> Martin >>> >>> >>> >>> Daniele Renda wrote: >>>> Hi, >>>> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >>>> small problem with ManagerEventListener. I'm using the listener to >>>> catch the event about a call that I've scheduled from Java. I create a >>>> automatic call in this mode: >>>> >>>> >>>> action.setContext(sContext); >>>> action.setExten(sExten); >>>> action.setPriority(new Integer(iPriority)); >>>> action.setTimeout(new Long(iTimeout)); >>>> action.setActionId(""+telefonata.getId()); >>>> action.setAsync(true); >>>> >>>> All works fine if I make only ONE call at same time, but if I try to make >>>> two or more calls I am not be able to detect wich events are of the >>>> first call and which are of the second call. >>>> The unique id of the events are not linked to the action that I've >>>> submitted and the actionId that I can set is not included in the >>>> response event. So how I can detect exactly the events of each call >>>> separatly? >>>> >>>> >>>> Thanks very much for your help! >>>> Best regards >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> Asterisk-java-users mailing list >>> Ast...@li... >>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>> >> >> >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > -- Daniele Renda |
From: Martin B. S. <ma...@mb...> - 2009-07-23 02:55:55
|
Daniele, Have you considered using the Live API -- either using it directly or looking to it as a model for what you want to do? It tracks originates exactly like you're asking for, out of the box (and it's free and full of open source goodness!!!). (I'm a little short on time so I won't actually go and design/implement an example for your problem, so unless you have a minimal one that demonstrates the problem, I'm not going to be much help -- sorry!) Martin Daniele Renda wrote: > Hi Martin, > yes the action is an OriginateAction. > I've a problem with your example. Infact I'm using the listener > beacuse of I'd like to catch all events of a call (che > NewChannelEvent,NewStateEvent,DtmfEvent,HangupEvent,ecc ecc). > Instead with the : > > managerConnection.sendAction(getAsteriskAction(), new SendActionCallback() { > > @Override > public void onResponse(ManagerResponse response) { > log.debug("received message "+response); > } > }); > > I'll received only ONE response to my action (probably: action queued > successfuly). So this is the cause of the fact that I'm using a > listener to the manager in order to catch every event. > > THanks > > Best regards > > 2009/7/21 Martin B. Smith <ma...@mb...>: >> What class is action? Is it OriginateAction? >> >> For OriginateActions, Asterisk-Java has the ability to give you all of >> the events associated with the OriginateAction, through the >> OriginateResponseEvent. >> >> In your case, you're asking Asterisk-Java to send an action, wait >> 300000000 ms for a resultant event, and then do nothing with it. >> >> You're also looking at ((AbstractChannelEvent)event).getUniqueId(), >> which is the unique name of the channel. It won't contain your actionId. >> >> Since you do *not* want to wait for the result of the originate (you >> want to do more originates), you may want to use the callback version: >> >> void sendAction(ManagerAction action, SendActionCallback callback) >> >> "Sends a ManagerAction to the Asterisk server and registers a callback >> handler to be called when the corresponding ManagerResponse is received." >> >> And then ideally, the response should be an OriginateResponse: >> void onResponse(ManagerResponse response) >> >> Finally, have you considered using a proxy so you aren't sending actions >> and handling events in the same thread? >> http://asterisk-java.org/development/apidocs/org/asteriskjava/manager/ManagerEventListenerProxy.html >> >> Good luck, >> >> Martin >> >> >> >> Daniele Renda wrote: >>> Hi Martin, >>> the code is quite structurated but I try to paste the relevant points: >>> *CREATE THE ACTION (in a thread. This action then is send to the >>> Manager thread that send the action to Asterisk) >>> action.setContext(sContext); >>> action.setExten(sExten); >>> action.setPriority(new Integer(iPriority)); >>> action.setTimeout(new Long(iTimeout)); >>> action.setActionId(""+telefonata.getId()); >>> action.setAsync(true); >>> >>> *MANAGER (is a thread that send the action to Asterisk and waint ultil >>> the HangupEvent is throw or untile timeout) >>> ManagerConnectionFactory factory = new >>> ManagerConnectionFactory(asteriskHost, asteriskManagerPort, >>> asteriskManagerUser, asteriskManagerPsw); >>> this.managerConnection = factory.createManagerConnection(); >>> log.debug("Creata connessione al server Asterisk " + >>> managerConnection.getState()); >>> managerConnection.addEventListener(this.managerEventListener); >>> managerConnection.sendAction(getAsteriskAction(), 300000000); >>> try { >>> Thread.sleep(180000); >>> } catch (InterruptedException ex) { >>> } >>> } >>> log.debug("Sto effettuato la disconnessione dal Manager di Asterisk >>> sull'host " + managerConnection.getHostname()); >>> managerConnection.logoff(); >>> >>> *EVENT LISTENER (the listener to asterisk Event) >>> @Override >>> public void onManagerEvent(ManagerEvent event) { >>> log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); >>> >>> The listener is very long and intercept all the events to asterisk. >>> >>> *DIALPLAN >>> The action that run from Java code is somethig as this: >>> Dial(trunk/telephoneNumber), extension s, priority 1, context >>> >>> [context] >>> exten => s,1,Answer() >>> ;I play a message >>> exten => s,2,Background(custom/message/intro) >>> exten => s,3,Hangup() >>> >>> In few words, this is an automatic call system that calls many users >>> and play them a simple vocal message. >>> My problem is that in the events that asterisk send to me (througt >>> Asterisk Java) there isn't something that tell to me which call the >>> refers. Infact all calls go to [context] and all make same things. >>> >>> Thanks >>> >>> Best regards >>> >>> >>> >>> 2009/7/21 Martin B. Smith <ma...@mb...>: >>>> Hi Daniel, >>>> >>>> That snippet doesn't help much; you don't even provide the declaration >>>> of the action variable or how you send it. Any number of things could be >>>> going on here, and we don't really have enough information to diagnose >>>> the problem. >>>> >>>> Furthermore, depending on how your dialplan is setup, your ability to >>>> determine which events correspond to which calls could be impaired. >>>> >>>> We'd really need a complete example of how you create and send the >>>> action, and how you handle the response; we'd also need to see any >>>> relevant dialplan contexts that the call may go into. >>>> >>>> Good luck, >>>> >>>> Martin >>>> >>>> >>>> >>>> Daniele Renda wrote: >>>>> Hi, >>>>> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >>>>> small problem with ManagerEventListener. I'm using the listener to >>>>> catch the event about a call that I've scheduled from Java. I create a >>>>> automatic call in this mode: >>>>> >>>>> >>>>> action.setContext(sContext); >>>>> action.setExten(sExten); >>>>> action.setPriority(new Integer(iPriority)); >>>>> action.setTimeout(new Long(iTimeout)); >>>>> action.setActionId(""+telefonata.getId()); >>>>> action.setAsync(true); >>>>> >>>>> All works fine if I make only ONE call at same time, but if I try to make >>>>> two or more calls I am not be able to detect wich events are of the >>>>> first call and which are of the second call. >>>>> The unique id of the events are not linked to the action that I've >>>>> submitted and the actionId that I can set is not included in the >>>>> response event. So how I can detect exactly the events of each call >>>>> separatly? >>>>> >>>>> >>>>> Thanks very much for your help! >>>>> Best regards >>>> ------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> Asterisk-java-users mailing list >>>> Ast...@li... >>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>> >>> >>> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Asterisk-java-users mailing list >> Ast...@li... >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >> > > > |
From: Daniele R. <dan...@gm...> - 2009-07-23 10:03:00
|
Hi Martin, I've seen Live Api but it does not usefull for my case. Infact I need to get a very detailed lists of all events that are raised on the channel (SIP). I've wrote a small test case in order to explain better my problem: public class AsteriskManagerTest extends Thread { private SipEventListenerTest managerEventListener; private ManagerConnection managerConnection; private Logger log = Logger.getLogger(AsteriskManagerTest.class); private OriginateAction asteriskAction = null; public AsteriskManagerTest(String asteriskHost, int asteriskManagerPort, String asteriskManagerUser, String asteriskManagerPsw) { ManagerConnectionFactory factory = new ManagerConnectionFactory(asteriskHost, asteriskManagerPort, asteriskManagerUser, asteriskManagerPsw); this.managerConnection = factory.createManagerConnection(); log.debug("Creata connessione al server Asterisk " + managerConnection.getState()); } @Override public void run() { try { managerConnection.addEventListener(this.managerEventListener); managerConnection.login(); //CONTROLLO LA VALIDITA' DELL'AZIONE log.debug("getAsteriskAction().getChannel() " + getAsteriskAction().getChannel()); log.debug("getAsteriskAction().getContext() " + getAsteriskAction().getContext()); log.debug("getAsteriskAction().getExten() " + getAsteriskAction().getExten()); ResponseEvents risposte = managerConnection.sendEventGeneratingAction(getAsteriskAction(), 3000000); managerConnection.logoff(); this.managerEventListener = null; try { Thread.sleep(10000); } catch (InterruptedException ex) { } } catch (IllegalStateException ex) { log.error("Illegal State Exception", ex); } catch (IOException ex) { log.error("IO Exception", ex); } catch (AuthenticationFailedException ex) { log.error("AuthenticationFailedException", ex); } catch (TimeoutException ex) { log.info("TimeoutException" + ex.getMessage()); } log.info("**************************** FINE DEL RUN() ASTERISK_MANAGER ***************************************************"); } public static void main(String[] args) throws Exception { AsteriskManagerTest manager = null; for (int i = 0; i < 2; i++) { manager = new AsteriskManagerTest("host", 5038, "manager", "psw"); OriginateAction action = new OriginateAction(); if (i == 0) { action.setChannel("SIP/trunk/number1"); } else { action.setChannel("SIP/ehiweb/number2"); } action.setContext("outgoing"); action.setExten("s"); action.setPriority(new Integer(1)); action.setTimeout(new Long(30000)); action.setVariable("data", "12/01/18/30"); action.setActionId("PROVA"); manager.setAsteriskAction(action); //LISTENER manager.setManagerEventListener(new SipEventListenerTest()); System.out.println("**************************** START THREAD N." + i + " ASTERISK_MANAGER ***************************************************"); manager.start(); } } /** * @return the managerEventListener */ public ManagerEventListener getManagerEventListener() { return managerEventListener; } /** * @param managerEventListener the managerEventListener to set */ public void setManagerEventListener(SipEventListenerTest managerEventListener) { this.managerEventListener = managerEventListener; } /** * @return the asteriskAction */ public OriginateAction getAsteriskAction() { return asteriskAction; } /** * @param asteriskAction the asteriskAction to set */ public void setAsteriskAction(OriginateAction asteriskAction) { this.asteriskAction = asteriskAction; } } public class SipEventListenerTest extends CallManagerEvent implements ManagerEventListener { @Override public void onManagerEvent(ManagerEvent event) { log.debug("Event " + ((AbstractChannelEvent) event).getUniqueId() + " - " + event); } } And these are the log of the 2 simultaneous calls. 23/07/2009 11:22:22 DEBUG AsteriskManagerTest:34 - Creata connessione al server Asterisk INITIAL **************************** START THREAD N.0 ASTERISK_MANAGER *************************************************** 23/07/2009 11:22:22 DEBUG AsteriskManagerTest:34 - Creata connessione al server Asterisk INITIAL **************************** START THREAD N.1 ASTERISK_MANAGER *************************************************** 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:44 - getAsteriskAction().getChannel() SIP/trunk/3470841943 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:45 - getAsteriskAction().getContext() outgoing 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:46 - getAsteriskAction().getExten() s 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:44 - getAsteriskAction().getChannel() SIP/trunk/3400917567 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:45 - getAsteriskAction().getContext() outgoing 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:46 - getAsteriskAction().getExten() s 23/07/2009 11:22:23 DEBUG CallManagerEvent:19 - Event 1248340950.745 - org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 11:22:23 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.745',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',channelstatedesc='Down',systemHashcode=18019860] 23/07/2009 11:22:23 DEBUG CallManagerEvent:19 - Event 1248340950.745 - org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul 23 11:22:23 CEST 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.745',cidcallingpres='0',cidcallingprestxt='Presentation Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=17933228] 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 11:22:32 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.746',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',channelstatedesc='Down',systemHashcode=7486844] 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul 23 11:22:32 CEST 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.746',cidcallingpres='0',cidcallingprestxt='Presentation Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=1377187] 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 11:22:32 CEST 2009,privilege='call,all',causetxt='User busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.746',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=9004539] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.745',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',channelstatedesc='Down',systemHashcode=381299] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.745',cidcallingpres='0',cidcallingprestxt='Presentation Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=25377109] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.746',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',channelstatedesc='Down',systemHashcode=2693887] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.746',cidcallingpres='0',cidcallingprestxt='Presentation Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=22837328] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',causetxt='User busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.746',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=11626165] 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 11:22:33 CEST 2009,privilege='call,all',causetxt='User busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.745',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=31378924] 23/07/2009 11:22:42 INFO AsteriskManagerTest:65 - **************************** FINE DEL RUN() ASTERISK_MANAGER *************************************************** 23/07/2009 11:22:43 INFO AsteriskManagerTest:65 - **************************** FINE DEL RUN() ASTERISK_MANAGER *************************************************** As you can see, there are events of the 2 calls with 2 uniqueId different: 1248340950.746 and 1248340950.745 but I can't update the status of the call because I can't associate the unique id with my action. So I'm not be able to understand if 1248340950.745 is referred to call1 or call2. This is the question!! Thanks for any suggestion!! Best regards! 2009/7/23 Martin B. Smith <ma...@mb...>: > Daniele, > > Have you considered using the Live API -- either using it directly or > looking to it as a model for what you want to do? It tracks originates > exactly like you're asking for, out of the box (and it's free and full > of open source goodness!!!). > > (I'm a little short on time so I won't actually go and design/implement > an example for your problem, so unless you have a minimal one that > demonstrates the problem, I'm not going to be much help -- sorry!) > > Martin > > > Daniele Renda wrote: >> Hi Martin, >> yes the action is an OriginateAction. >> I've a problem with your example. Infact I'm using the listener >> beacuse of I'd like to catch all events of a call (che >> NewChannelEvent,NewStateEvent,DtmfEvent,HangupEvent,ecc ecc). >> Instead with the : >> >> managerConnection.sendAction(getAsteriskAction(), new SendActionCallback() { >> >> @Override >> public void onResponse(ManagerResponse response) { >> log.debug("received message "+response); >> } >> }); >> >> I'll received only ONE response to my action (probably: action queued >> successfuly). So this is the cause of the fact that I'm using a >> listener to the manager in order to catch every event. >> >> THanks >> >> Best regards >> >> 2009/7/21 Martin B. Smith <ma...@mb...>: >>> What class is action? Is it OriginateAction? >>> >>> For OriginateActions, Asterisk-Java has the ability to give you all of >>> the events associated with the OriginateAction, through the >>> OriginateResponseEvent. >>> >>> In your case, you're asking Asterisk-Java to send an action, wait >>> 300000000 ms for a resultant event, and then do nothing with it. >>> >>> You're also looking at ((AbstractChannelEvent)event).getUniqueId(), >>> which is the unique name of the channel. It won't contain your actionId. >>> >>> Since you do *not* want to wait for the result of the originate (you >>> want to do more originates), you may want to use the callback version: >>> >>> void sendAction(ManagerAction action, SendActionCallback callback) >>> >>> "Sends a ManagerAction to the Asterisk server and registers a callback >>> handler to be called when the corresponding ManagerResponse is received." >>> >>> And then ideally, the response should be an OriginateResponse: >>> void onResponse(ManagerResponse response) >>> >>> Finally, have you considered using a proxy so you aren't sending actions >>> and handling events in the same thread? >>> http://asterisk-java.org/development/apidocs/org/asteriskjava/manager/ManagerEventListenerProxy.html >>> >>> Good luck, >>> >>> Martin >>> >>> >>> >>> Daniele Renda wrote: >>>> Hi Martin, >>>> the code is quite structurated but I try to paste the relevant points: >>>> *CREATE THE ACTION (in a thread. This action then is send to the >>>> Manager thread that send the action to Asterisk) >>>> action.setContext(sContext); >>>> action.setExten(sExten); >>>> action.setPriority(new Integer(iPriority)); >>>> action.setTimeout(new Long(iTimeout)); >>>> action.setActionId(""+telefonata.getId()); >>>> action.setAsync(true); >>>> >>>> *MANAGER (is a thread that send the action to Asterisk and waint ultil >>>> the HangupEvent is throw or untile timeout) >>>> ManagerConnectionFactory factory = new >>>> ManagerConnectionFactory(asteriskHost, asteriskManagerPort, >>>> asteriskManagerUser, asteriskManagerPsw); >>>> this.managerConnection = factory.createManagerConnection(); >>>> log.debug("Creata connessione al server Asterisk " + >>>> managerConnection.getState()); >>>> managerConnection.addEventListener(this.managerEventListener); >>>> managerConnection.sendAction(getAsteriskAction(), 300000000); >>>> try { >>>> Thread.sleep(180000); >>>> } catch (InterruptedException ex) { >>>> } >>>> } >>>> log.debug("Sto effettuato la disconnessione dal Manager di Asterisk >>>> sull'host " + managerConnection.getHostname()); >>>> managerConnection.logoff(); >>>> >>>> *EVENT LISTENER (the listener to asterisk Event) >>>> @Override >>>> public void onManagerEvent(ManagerEvent event) { >>>> log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); >>>> >>>> The listener is very long and intercept all the events to asterisk. >>>> >>>> *DIALPLAN >>>> The action that run from Java code is somethig as this: >>>> Dial(trunk/telephoneNumber), extension s, priority 1, context >>>> >>>> [context] >>>> exten => s,1,Answer() >>>> ;I play a message >>>> exten => s,2,Background(custom/message/intro) >>>> exten => s,3,Hangup() >>>> >>>> In few words, this is an automatic call system that calls many users >>>> and play them a simple vocal message. >>>> My problem is that in the events that asterisk send to me (througt >>>> Asterisk Java) there isn't something that tell to me which call the >>>> refers. Infact all calls go to [context] and all make same things. >>>> >>>> Thanks >>>> >>>> Best regards >>>> >>>> >>>> >>>> 2009/7/21 Martin B. Smith <ma...@mb...>: >>>>> Hi Daniel, >>>>> >>>>> That snippet doesn't help much; you don't even provide the declaration >>>>> of the action variable or how you send it. Any number of things could be >>>>> going on here, and we don't really have enough information to diagnose >>>>> the problem. >>>>> >>>>> Furthermore, depending on how your dialplan is setup, your ability to >>>>> determine which events correspond to which calls could be impaired. >>>>> >>>>> We'd really need a complete example of how you create and send the >>>>> action, and how you handle the response; we'd also need to see any >>>>> relevant dialplan contexts that the call may go into. >>>>> >>>>> Good luck, >>>>> >>>>> Martin >>>>> >>>>> >>>>> >>>>> Daniele Renda wrote: >>>>>> Hi, >>>>>> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >>>>>> small problem with ManagerEventListener. I'm using the listener to >>>>>> catch the event about a call that I've scheduled from Java. I create a >>>>>> automatic call in this mode: >>>>>> >>>>>> >>>>>> action.setContext(sContext); >>>>>> action.setExten(sExten); >>>>>> action.setPriority(new Integer(iPriority)); >>>>>> action.setTimeout(new Long(iTimeout)); >>>>>> action.setActionId(""+telefonata.getId()); >>>>>> action.setAsync(true); >>>>>> >>>>>> All works fine if I make only ONE call at same time, but if I try to make >>>>>> two or more calls I am not be able to detect wich events are of the >>>>>> first call and which are of the second call. >>>>>> The unique id of the events are not linked to the action that I've >>>>>> submitted and the actionId that I can set is not included in the >>>>>> response event. So how I can detect exactly the events of each call >>>>>> separatly? >>>>>> >>>>>> >>>>>> Thanks very much for your help! >>>>>> Best regards >>>>> ------------------------------------------------------------------------------ >>>>> _______________________________________________ >>>>> Asterisk-java-users mailing list >>>>> Ast...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>>> >>>> >>>> >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> Asterisk-java-users mailing list >>> Ast...@li... >>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>> >> >> >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > -- Daniele Renda |
From: Stefan R. <ste...@re...> - 2009-07-23 10:47:18
Attachments:
signature.asc
|
Daniele Renda wrote: > I've seen Live Api but it does not usefull for my case. Infact I need > to get a very detailed lists of all events that are raised on the > channel (SIP). We are constantly seeking to improve the live API. Can you help us a bit by providing more detail about the notifications you are currently missing in the live API? Thanks, Stefan |
From: Daniele R. <dan...@gm...> - 2009-07-23 15:43:11
|
Hi Stefan, yes, in my opinion, are missing these events: -Hangup Event (very important for me) -Dtmf events (also this one is very important) Thanks very much Best regards 2009/7/23 Stefan Reuter <ste...@re...>: > Daniele Renda wrote: >> I've seen Live Api but it does not usefull for my case. Infact I need >> to get a very detailed lists of all events that are raised on the >> channel (SIP). > > We are constantly seeking to improve the live API. Can you help us a bit > by providing more detail about the notifications you are currently > missing in the live API? > > Thanks, > > Stefan > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > -- Daniele Renda |
From: Daniele R. <dan...@gm...> - 2009-07-23 10:54:38
|
I've forgotten to write that the problem is that Asterisk pbx is a shared pbx so there are many events that are not linked with the calls that I'm creating from the code. So, for me, is essential that I catch ONLY the events that are linked to my originate actions. Thanks very much! Best regards 2009/7/23 Daniele Renda <dan...@gm...>: > Hi Martin, > I've seen Live Api but it does not usefull for my case. Infact I need > to get a very detailed lists of all events that are raised on the > channel (SIP). > I've wrote a small test case in order to explain better my problem: > > public class AsteriskManagerTest extends Thread { > > private SipEventListenerTest managerEventListener; > private ManagerConnection managerConnection; > private Logger log = Logger.getLogger(AsteriskManagerTest.class); > private OriginateAction asteriskAction = null; > > public AsteriskManagerTest(String asteriskHost, int > asteriskManagerPort, String asteriskManagerUser, String > asteriskManagerPsw) { > ManagerConnectionFactory factory = new > ManagerConnectionFactory(asteriskHost, asteriskManagerPort, > asteriskManagerUser, asteriskManagerPsw); > this.managerConnection = factory.createManagerConnection(); > log.debug("Creata connessione al server Asterisk " + > managerConnection.getState()); > } > > @Override > public void run() { > try { > managerConnection.addEventListener(this.managerEventListener); > managerConnection.login(); > //CONTROLLO LA VALIDITA' DELL'AZIONE > > log.debug("getAsteriskAction().getChannel() " + > getAsteriskAction().getChannel()); > log.debug("getAsteriskAction().getContext() " + > getAsteriskAction().getContext()); > log.debug("getAsteriskAction().getExten() " + > getAsteriskAction().getExten()); > ResponseEvents risposte = > managerConnection.sendEventGeneratingAction(getAsteriskAction(), > 3000000); > > managerConnection.logoff(); > this.managerEventListener = null; > try { > Thread.sleep(10000); > } catch (InterruptedException ex) { > } > > } catch (IllegalStateException ex) { > log.error("Illegal State Exception", ex); > } catch (IOException ex) { > log.error("IO Exception", ex); > } catch (AuthenticationFailedException ex) { > log.error("AuthenticationFailedException", ex); > } catch (TimeoutException ex) { > log.info("TimeoutException" + ex.getMessage()); > } > log.info("**************************** FINE DEL RUN() > ASTERISK_MANAGER > ***************************************************"); > } > > public static void main(String[] args) throws Exception { > AsteriskManagerTest manager = null; > for (int i = 0; i < 2; i++) { > manager = new AsteriskManagerTest("host", 5038, "manager", "psw"); > OriginateAction action = new OriginateAction(); > if (i == 0) { > action.setChannel("SIP/trunk/number1"); > } else { > action.setChannel("SIP/ehiweb/number2"); > } > action.setContext("outgoing"); > action.setExten("s"); > action.setPriority(new Integer(1)); > action.setTimeout(new Long(30000)); > action.setVariable("data", "12/01/18/30"); > action.setActionId("PROVA"); > manager.setAsteriskAction(action); > //LISTENER > manager.setManagerEventListener(new SipEventListenerTest()); > System.out.println("**************************** START > THREAD N." + i + " ASTERISK_MANAGER > ***************************************************"); > manager.start(); > } > } > > /** > * @return the managerEventListener > */ > public ManagerEventListener getManagerEventListener() { > return managerEventListener; > } > > /** > * @param managerEventListener the managerEventListener to set > */ > public void setManagerEventListener(SipEventListenerTest > managerEventListener) { > this.managerEventListener = managerEventListener; > } > > /** > * @return the asteriskAction > */ > public OriginateAction getAsteriskAction() { > return asteriskAction; > } > > /** > * @param asteriskAction the asteriskAction to set > */ > public void setAsteriskAction(OriginateAction asteriskAction) { > this.asteriskAction = asteriskAction; > } > } > > > public class SipEventListenerTest extends CallManagerEvent implements > ManagerEventListener { > > @Override > public void onManagerEvent(ManagerEvent event) { > log.debug("Event " + ((AbstractChannelEvent) > event).getUniqueId() + " - " + event); > } > } > > And these are the log of the 2 simultaneous calls. > 23/07/2009 11:22:22 DEBUG AsteriskManagerTest:34 - Creata connessione > al server Asterisk INITIAL > **************************** START THREAD N.0 ASTERISK_MANAGER > *************************************************** > 23/07/2009 11:22:22 DEBUG AsteriskManagerTest:34 - Creata connessione > al server Asterisk INITIAL > **************************** START THREAD N.1 ASTERISK_MANAGER > *************************************************** > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:44 - > getAsteriskAction().getChannel() SIP/trunk/3470841943 > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:45 - > getAsteriskAction().getContext() outgoing > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:46 - > getAsteriskAction().getExten() s > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:44 - > getAsteriskAction().getChannel() SIP/trunk/3400917567 > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:45 - > getAsteriskAction().getContext() outgoing > 23/07/2009 11:22:23 DEBUG AsteriskManagerTest:46 - > getAsteriskAction().getExten() s > 23/07/2009 11:22:23 DEBUG CallManagerEvent:19 - Event 1248340950.745 - > org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 > 11:22:23 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.745',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',channelstatedesc='Down',systemHashcode=18019860] > 23/07/2009 11:22:23 DEBUG CallManagerEvent:19 - Event 1248340950.745 - > org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul > 23 11:22:23 CEST > 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.745',cidcallingpres='0',cidcallingprestxt='Presentation > Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=17933228] > 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 > 11:22:32 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.746',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',channelstatedesc='Down',systemHashcode=7486844] > 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul > 23 11:22:32 CEST > 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.746',cidcallingpres='0',cidcallingprestxt='Presentation > Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=1377187] > 23/07/2009 11:22:32 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 > 11:22:32 CEST 2009,privilege='call,all',causetxt='User > busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.746',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=9004539] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - > org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 > 11:22:33 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.745',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',channelstatedesc='Down',systemHashcode=381299] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - > org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul > 23 11:22:33 CEST > 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.745',cidcallingpres='0',cidcallingprestxt='Presentation > Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=25377109] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.NewChannelEvent[dateReceived=Thu Jul 23 > 11:22:33 CEST 2009,privilege='call,all',callerid='null',state='Down',channelstate='0',timestamp='null',calleridname='null',uniqueid='1248340950.746',exten='null',context='from_cheapnet',accountcode='null',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',channelstatedesc='Down',systemHashcode=2693887] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.NewCallerIdEvent[dateReceived=Thu Jul > 23 11:22:33 CEST > 2009,privilege='call,all',callerid='null',calleridname='null',timestamp='null',uniqueid='1248340950.746',cidcallingpres='0',cidcallingprestxt='Presentation > Allowed, Not Screened',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=22837328] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.746 - > org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 > 11:22:33 CEST 2009,privilege='call,all',causetxt='User > busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.746',server='null',calleridnum='null',channel='SIP/ehiweb-00b7b1a8',systemHashcode=11626165] > 23/07/2009 11:22:33 DEBUG CallManagerEvent:19 - Event 1248340950.745 - > org.asteriskjava.manager.event.HangupEvent[dateReceived=Thu Jul 23 > 11:22:33 CEST 2009,privilege='call,all',causetxt='User > busy',callerid='null',cause='17',calleridname='null',timestamp='null',uniqueid='1248340950.745',server='null',calleridnum='null',channel='SIP/ehiweb-00b7cdd8',systemHashcode=31378924] > 23/07/2009 11:22:42 INFO AsteriskManagerTest:65 - > **************************** FINE DEL RUN() ASTERISK_MANAGER > *************************************************** > 23/07/2009 11:22:43 INFO AsteriskManagerTest:65 - > **************************** FINE DEL RUN() ASTERISK_MANAGER > *************************************************** > > As you can see, there are events of the 2 calls with 2 uniqueId > different: 1248340950.746 and 1248340950.745 but I can't update the > status of the call because I can't associate the unique id with my > action. So I'm not be able to understand if 1248340950.745 is referred > to call1 or call2. This is the question!! > > Thanks for any suggestion!! > > Best regards! > > 2009/7/23 Martin B. Smith <ma...@mb...>: >> Daniele, >> >> Have you considered using the Live API -- either using it directly or >> looking to it as a model for what you want to do? It tracks originates >> exactly like you're asking for, out of the box (and it's free and full >> of open source goodness!!!). >> >> (I'm a little short on time so I won't actually go and design/implement >> an example for your problem, so unless you have a minimal one that >> demonstrates the problem, I'm not going to be much help -- sorry!) >> >> Martin >> >> >> Daniele Renda wrote: >>> Hi Martin, >>> yes the action is an OriginateAction. >>> I've a problem with your example. Infact I'm using the listener >>> beacuse of I'd like to catch all events of a call (che >>> NewChannelEvent,NewStateEvent,DtmfEvent,HangupEvent,ecc ecc). >>> Instead with the : >>> >>> managerConnection.sendAction(getAsteriskAction(), new SendActionCallback() { >>> >>> @Override >>> public void onResponse(ManagerResponse response) { >>> log.debug("received message "+response); >>> } >>> }); >>> >>> I'll received only ONE response to my action (probably: action queued >>> successfuly). So this is the cause of the fact that I'm using a >>> listener to the manager in order to catch every event. >>> >>> THanks >>> >>> Best regards >>> >>> 2009/7/21 Martin B. Smith <ma...@mb...>: >>>> What class is action? Is it OriginateAction? >>>> >>>> For OriginateActions, Asterisk-Java has the ability to give you all of >>>> the events associated with the OriginateAction, through the >>>> OriginateResponseEvent. >>>> >>>> In your case, you're asking Asterisk-Java to send an action, wait >>>> 300000000 ms for a resultant event, and then do nothing with it. >>>> >>>> You're also looking at ((AbstractChannelEvent)event).getUniqueId(), >>>> which is the unique name of the channel. It won't contain your actionId. >>>> >>>> Since you do *not* want to wait for the result of the originate (you >>>> want to do more originates), you may want to use the callback version: >>>> >>>> void sendAction(ManagerAction action, SendActionCallback callback) >>>> >>>> "Sends a ManagerAction to the Asterisk server and registers a callback >>>> handler to be called when the corresponding ManagerResponse is received." >>>> >>>> And then ideally, the response should be an OriginateResponse: >>>> void onResponse(ManagerResponse response) >>>> >>>> Finally, have you considered using a proxy so you aren't sending actions >>>> and handling events in the same thread? >>>> http://asterisk-java.org/development/apidocs/org/asteriskjava/manager/ManagerEventListenerProxy.html >>>> >>>> Good luck, >>>> >>>> Martin >>>> >>>> >>>> >>>> Daniele Renda wrote: >>>>> Hi Martin, >>>>> the code is quite structurated but I try to paste the relevant points: >>>>> *CREATE THE ACTION (in a thread. This action then is send to the >>>>> Manager thread that send the action to Asterisk) >>>>> action.setContext(sContext); >>>>> action.setExten(sExten); >>>>> action.setPriority(new Integer(iPriority)); >>>>> action.setTimeout(new Long(iTimeout)); >>>>> action.setActionId(""+telefonata.getId()); >>>>> action.setAsync(true); >>>>> >>>>> *MANAGER (is a thread that send the action to Asterisk and waint ultil >>>>> the HangupEvent is throw or untile timeout) >>>>> ManagerConnectionFactory factory = new >>>>> ManagerConnectionFactory(asteriskHost, asteriskManagerPort, >>>>> asteriskManagerUser, asteriskManagerPsw); >>>>> this.managerConnection = factory.createManagerConnection(); >>>>> log.debug("Creata connessione al server Asterisk " + >>>>> managerConnection.getState()); >>>>> managerConnection.addEventListener(this.managerEventListener); >>>>> managerConnection.sendAction(getAsteriskAction(), 300000000); >>>>> try { >>>>> Thread.sleep(180000); >>>>> } catch (InterruptedException ex) { >>>>> } >>>>> } >>>>> log.debug("Sto effettuato la disconnessione dal Manager di Asterisk >>>>> sull'host " + managerConnection.getHostname()); >>>>> managerConnection.logoff(); >>>>> >>>>> *EVENT LISTENER (the listener to asterisk Event) >>>>> @Override >>>>> public void onManagerEvent(ManagerEvent event) { >>>>> log.debug("Evento "+((AbstractChannelEvent)event).getUniqueId()+" - " + event); >>>>> >>>>> The listener is very long and intercept all the events to asterisk. >>>>> >>>>> *DIALPLAN >>>>> The action that run from Java code is somethig as this: >>>>> Dial(trunk/telephoneNumber), extension s, priority 1, context >>>>> >>>>> [context] >>>>> exten => s,1,Answer() >>>>> ;I play a message >>>>> exten => s,2,Background(custom/message/intro) >>>>> exten => s,3,Hangup() >>>>> >>>>> In few words, this is an automatic call system that calls many users >>>>> and play them a simple vocal message. >>>>> My problem is that in the events that asterisk send to me (througt >>>>> Asterisk Java) there isn't something that tell to me which call the >>>>> refers. Infact all calls go to [context] and all make same things. >>>>> >>>>> Thanks >>>>> >>>>> Best regards >>>>> >>>>> >>>>> >>>>> 2009/7/21 Martin B. Smith <ma...@mb...>: >>>>>> Hi Daniel, >>>>>> >>>>>> That snippet doesn't help much; you don't even provide the declaration >>>>>> of the action variable or how you send it. Any number of things could be >>>>>> going on here, and we don't really have enough information to diagnose >>>>>> the problem. >>>>>> >>>>>> Furthermore, depending on how your dialplan is setup, your ability to >>>>>> determine which events correspond to which calls could be impaired. >>>>>> >>>>>> We'd really need a complete example of how you create and send the >>>>>> action, and how you handle the response; we'd also need to see any >>>>>> relevant dialplan contexts that the call may go into. >>>>>> >>>>>> Good luck, >>>>>> >>>>>> Martin >>>>>> >>>>>> >>>>>> >>>>>> Daniele Renda wrote: >>>>>>> Hi, >>>>>>> I'm using Asterisk Java with my Asterisk 1.6 and all works fine. I've only a >>>>>>> small problem with ManagerEventListener. I'm using the listener to >>>>>>> catch the event about a call that I've scheduled from Java. I create a >>>>>>> automatic call in this mode: >>>>>>> >>>>>>> >>>>>>> action.setContext(sContext); >>>>>>> action.setExten(sExten); >>>>>>> action.setPriority(new Integer(iPriority)); >>>>>>> action.setTimeout(new Long(iTimeout)); >>>>>>> action.setActionId(""+telefonata.getId()); >>>>>>> action.setAsync(true); >>>>>>> >>>>>>> All works fine if I make only ONE call at same time, but if I try to make >>>>>>> two or more calls I am not be able to detect wich events are of the >>>>>>> first call and which are of the second call. >>>>>>> The unique id of the events are not linked to the action that I've >>>>>>> submitted and the actionId that I can set is not included in the >>>>>>> response event. So how I can detect exactly the events of each call >>>>>>> separatly? >>>>>>> >>>>>>> >>>>>>> Thanks very much for your help! >>>>>>> Best regards >>>>>> ------------------------------------------------------------------------------ >>>>>> _______________________________________________ >>>>>> Asterisk-java-users mailing list >>>>>> Ast...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>>>> >>>>> >>>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> Asterisk-java-users mailing list >>>> Ast...@li... >>>> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >>>> >>> >>> >>> >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> Asterisk-java-users mailing list >> Ast...@li... >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >> > > > > -- > Daniele Renda > -- Daniele Renda |
From: Stefan R. <ste...@re...> - 2009-07-23 17:01:28
Attachments:
signature.asc
|
Daniele Renda wrote: > Hi Stefan, > yes, in my opinion, are missing these events: > > -Hangup Event (very important for me) Hangup is already available. Just register a PropertyChangeListener and watch for changes to the state property. Hangup is indicated by ChannelState.HUNGUP. > -Dtmf events (also this one is very important) This is in progress. You can watch https://secure.reucon.net/issues/browse/AJ-150 to be notified by Jira when it's fixed. =Stefan |
From: Daniele R. <dan...@gm...> - 2009-07-24 10:41:54
|
Hi Stefan, thanks very much for usefull information. We now with the dtmf events patch can be able to detect press of digits. We have a small problem on calls that are no asnwer, infact is throw an exception: vento new propertyChange java.beans.PropertyChangeEvent[source=AsteriskChannel[id='1248431463.961',name='SIP/101-00b7b1a8',callerId='<3470841943>',state='UP',account='null',dateOfCreation=Fri Jul 24 12:31:03 CEST 2009,dialedChannel=null,dialingChannel=null,linkedChannel=null]] 0 Evento new propertyChange java.beans.PropertyChangeEvent[source=AsteriskChannel[id='1248431463.961',name='SIP/101-00b7b1a8',callerId='<3470841943>',state='HUNGUP',account='null',dateOfCreation=Fri Jul 24 12:31:03 CEST 2009,dialedChannel=null,dialingChannel=null,linkedChannel=null]] 0 Evento new propertyChange java.beans.PropertyChangeEvent[source=AsteriskChannel[id='1248431463.962',name='SIP/ehiweb-00b7e7e8',callerId='<3400917567>',state='HUNGUP',account='null',dateOfCreation=Fri Jul 24 12:31:03 CEST 2009,dialedChannel=null,dialingChannel=null,linkedChannel=null]] 1 Server org.asteriskjava.live.internal.AsteriskServerImpl@18385e3 name null id 1248431495.963 date creation Fri Jul 24 12:31:35 CEST 2009 24/07/2009 12:31:35 DEBUG AsteriskManager2:195 - No answer 1 Exception in thread "Asterisk-Java DaemonPool-1-thread-1" java.lang.IllegalArgumentException: Parameters passed to AsteriskChannelImpl() must not be null. at org.asteriskjava.live.internal.AsteriskChannelImpl.<init>(AsteriskChannelImpl.java:142) at org.asteriskjava.live.internal.ChannelManager.addNewChannel(ChannelManager.java:129) at org.asteriskjava.live.internal.ChannelManager.handleNewChannelEvent(ChannelManager.java:332) at org.asteriskjava.live.internal.AsteriskServerImpl.onManagerEvent(AsteriskServerImpl.java:742) at org.asteriskjava.manager.ManagerEventListenerProxy$1.run(ManagerEventListenerProxy.java:77) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) We have printed the values of the channel and as you can see and the name is NULL. So is throw the exception. We have used the OriginateCallback in order to detect events in this mode: static class MyOriginateCallback implements OriginateCallback{ private final int i; private MyOriginateCallback(int i) { this.i = i; } @Override public void onDialing(AsteriskChannel channel) { channel.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { System.out.println("Evento new propertyChange " + evt + " " + i); } }); channel.addDTMFListener(new DTMFListener() { @Override public void onDtmfStart(DTMF dtmf) { log.debug("Dtmf start "+dtmf); } @Override public void onDtmfEnd(DTMF dtmf) { log.debug("Dtmf end "+dtmf); } }); log.debug("Dialing " + i); } @Override public void onSuccess(AsteriskChannel channel) { log.debug("Success " + i); } @Override public void onNoAnswer(AsteriskChannel channel) { log.debug("No answer " + i); } @Override public void onBusy(AsteriskChannel channel) { log.debug("Busy " + i); } @Override public void onFailure(LiveException cause) { log.debug("Failure" + i); } } .... .... asteriskServer.originateAsync(action, new MyOriginateCallback(i)); It's correct the use of the Callback? Is a small bug the problem or I've make a mistake? Thanks very much Best regards Daniele 2009/7/23 Stefan Reuter <ste...@re...>: > Daniele Renda wrote: >> Hi Stefan, >> yes, in my opinion, are missing these events: >> >> -Hangup Event (very important for me) > > Hangup is already available. Just register a PropertyChangeListener and > watch for changes to the state property. Hangup is indicated by > ChannelState.HUNGUP. > >> -Dtmf events (also this one is very important) > > This is in progress. You can watch > https://secure.reucon.net/issues/browse/AJ-150 to be notified by Jira > when it's fixed. > > =Stefan > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > -- Daniele Renda |