Re: [Asterisk-java-users] Execute Action after connect or reconnect
Brought to you by:
srt
From: Martin S. <ma...@be...> - 2007-09-05 16:59:02
|
Henrik, I think you may have spotted a bug. We synchronize access to the list of event listeners from other threads, but since you are adding an event listener in the same thread as the event firing for connection, the list isn't protected by the synchronized keyword. Unfortunately, I can see that fully protecting the list could cause deadlock when you want to edit the list while iterating through it. We probably need to work on this some to get it right. What do you think, Stefan? As a workaround, can you try something like: public void writeGlobalAsteriskVars(){ final AsteriskServer a2 =3D asteriskserver; =09 Runnable r =3D new Runnable() { public void run() { try { a2.setGlobalVariable("EXT", "foobar"); } catch (ManagerCommunicationException e) { =09 System.err.println(e.toString()); }=20 } }; new Thread(r).start(); } Martin Smith, Systems Developer ma...@be... Bureau of Economic and Business Research University of Florida (352) 392-0171 Ext. 221=20 =20 > -----Original Message----- > From: ast...@li...=20 > [mailto:ast...@li...] On=20 > Behalf Of Henrik Buchholz > Sent: Wednesday, September 05, 2007 3:43 AM > To: ast...@li... > Subject: Re: [Asterisk-java-users] Execute Action after=20 > connect or reconnect >=20 > Am Dienstag, den 04.09.2007, 12:19 -0400 schrieb Martin Smith: > > Hello Henrik, > >=20 > > Could you show the list what code you are using to add the=20 > ConnectEvent > > listener, and what you try to do when you receive a new=20 > ConnectEvent? >=20 > sure. thats the connect to the server and the adding of the listener: >=20 > ManagerConnectionFactory factory =3D new > ManagerConnectionFactory(astserver, asteriskuser, asteriskpasswd); > =09 > this.managerConnection =3D factory.createManagerConnection(); >=20 > managerConnection.login(); >=20 > this.asteriskserver =3D new=20 > DefaultAsteriskServer(this.managerConnection); >=20 > managerConnection.addEventListener(new > ConnectEventListener(asteriskserver)); >=20 >=20 > and this is the listener class: >=20 > public class ConnectEventListener implements ManagerEventListener { >=20 > private AsteriskServer asteriskserver; > =09 > public ConnectEventListener(AsteriskServer conn){ > this.asteriskserver =3D conn; > } >=20 > public void onManagerEvent(ManagerEvent event) { > =09 > String eventname =3D event.getClass().getName(); > if=20 > (eventname.equals("org.asteriskjava.manager.event.ConnectEvent")){ > ConnectEvent connevent =3D (ConnectEvent) event; > writeGlobalAsteriskVars(); > } > =09 > } >=20 > public void writeGlobalAsteriskVars(){ > try { > asteriskserver.setGlobalVariable("EXT",=20 > "foobar"); > } catch (ManagerCommunicationException e) { > System.err.println(e.toString()); > }=20 > } > } >=20 >=20 > > Are you modifying the AJ source directly? >=20 > uhh, no wouldn't do that... >=20 > I just commented all other code, so nothing else should try to access > the server via AJ and create a conflict. Interestingly the=20 > asterisk CLI > tells me that the variable was set, although the error occurs in AJ. >=20 > thanks for your help >=20 > Henrik >=20 > >=20 > > > -----Original Message----- > > > From: ast...@li...=20 > > > [mailto:ast...@li...] On=20 > > > Behalf Of Henrik Buchholz > > > Sent: Tuesday, September 04, 2007 11:20 AM > > > To: ast...@li... > > > Subject: [Asterisk-java-users] Execute Action after connect=20 > > > or reconnect > > >=20 > > > Hi, > > >=20 > > > is there a way to execute code after asterisk-java has=20 > > > reconnected to an > > > asterisk server, e.g. set global variables via > > > asteriskserver.setGlobalVariable()? > > >=20 > > > If I execute this after the initial login it works. I=20 > then tried to > > > create an event handler for ConnectEvents to find out when=20 > > > asterisk-java > > > has reconnected. When executing setGlobalVariable=20 > afterwards I always > > > get: > > >=20 > > > Exception in thread "Asterisk-Java=20 > ManagerConnection-0-Reconnect-0" > > > java.util.ConcurrentModificationException=20 > > > at java.util.AbstractList > > > Itr.checkForComodification(AbstractList.java:449) > > > at java.util.AbstractList$Itr.next(AbstractList.java:420) > > > at > > > org.asteriskjava.manager.internal.ManagerConnectionImpl.fireEv > > > ent(ManagerConnectionImpl.java:1204) > > > at > > > org.asteriskjava.manager.internal.ManagerConnectionImpl.doLogi > > > n(ManagerConnectionImpl.java:590) > > > at > > > org.asteriskjava.manager.internal.ManagerConnectionImpl.reconn > > > ect(ManagerConnectionImpl.java:1290) > > > at > > > org.asteriskjava.manager.internal.ManagerConnectionImpl.access > > > $100(ManagerConnectionImpl.java:84) > > > at org.asteriskjava.manager.internal.ManagerConnectionImpl > > > $1.run(ManagerConnectionImpl.java:1160) > > > at java.lang.Thread.run(Thread.java:595) > > >=20 > > > any ideas? > > >=20 > > > Henrik > > >=20 > > >=20 > > >=20 > > > -------------------------------------------------------------- > > > ----------- > > > This SF.net email is sponsored by: Splunk Inc. > > > Still grepping through log files to find problems? Stop. > > > Now Search log events and configuration files using AJAX and=20 > > > a browser. > > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > _______________________________________________ > > > Asterisk-java-users mailing list > > > Ast...@li... > > > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > >=20 > >=20 > >=20 > -------------------------------------------------------------- > ----------- > > This SF.net email is sponsored by: Splunk Inc. > > Still grepping through log files to find problems? Stop. > > Now Search log events and configuration files using AJAX=20 > and a browser. > > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > _______________________________________________ > > Asterisk-java-users mailing list > > Ast...@li... > > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >=20 >=20 > -------------------------------------------------------------- > ----------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and=20 > a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users >=20 |