Re: [Asterisk-java-users] Concurrent access toManagerConnectioninstance
Brought to you by:
srt
From: Maciek T. <mlo...@gm...> - 2008-04-18 18:11:36
|
Hi, Examples of code: Main class: //////////// public class LiveMonitoring ManagerEventListener { (.) ManagerConnection connection; (.) Public void LiveMonitoring() { ManagerConnectionFactory manConnFact = new ManagerConnectionFactory("dialer.telebot.pl", "dialer", "dialer"); this.connection = manConnFact.createManagerConnection(); this.connection.addEventListener(this); try { this.connection.login(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Connection error.. exiting"); System.exit(0); } } Public void event() { ///this event can be called several times SateliteClass SClass= new SateliteClass(this.connection); } } ////////Satelite class public class SateliteClass implements Runable { ManagerConnection connection; Public void SateliteClass(ManagerConnection) { This.run(); this.connection=connection; } Public synchronized void someMethod() { AgentsAction agentsAction = new AgentsAction(); try { ResponseEvents events = connection.sendEventGeneratingAction(agentsAction, 5000); /////[1] Collection<ResponseEvent> agents = events.getEvents(); Iterator<ResponseEvent> itr = agents.iterator(); while (itr.hasNext()) { ResponseEvent ev1 = itr.next(); if (ev1 instanceof AgentsEvent) { AgentsEvent ev = (AgentsEvent) ev1; if (ev.getAgent().equals(agentNo)) { //processing agent events } } } } catch (IllegalStateException ex) { ex.printStackTrace(); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } catch (EventTimeoutException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } } I've located reason of hanging up application- it was Timeout while waiting for response for AgenstAction. Does it have any relation with multithread architecture and concurrent access to ManagerConnectio9 object? Maybe I'm doing something wrong. Regards, Maciek _____ From: ast...@li... [mailto:ast...@li...] On Behalf Of Martin Smith Sent: Wednesday, April 16, 2008 7:22 PM To: ast...@li... Subject: Re: [Asterisk-java-users] Concurrent access toManagerConnectioninstance We might need an example of your code to explain why it doesn't work. Also, the Live API does pretty much what you're describing, including the threading problems. Martin Smith, Systems Developer ma...@be... Bureau of Economic and Business Research University of Florida (352) 392-0171 Ext. 221 _____ From: ast...@li... [mailto:ast...@li...] On Behalf Of Maciek Tokarski Sent: Wednesday, April 16, 2008 11:38 AM To: ast...@li... Subject: [Asterisk-java-users] Concurrent access to ManagerConnectioninstance Hey all, I'm trying to build multithread app. Architecture is as follows: -one main Thread, that does creation of ManagerConnection and login stuff -several "satellite" threads that should have access to previously initialized ManagerConnection object (they have to send some events to Asterisk box) ManagerConnection object is passed to "satellite" threads in constructor and reference to it is assigned to satellite-class member. When I'm trying to send event (I'm doing it in synchronized way) by eg. invoking sendEvent method- application totally hangs up (main thread and child threads). What is the reason and what can be solution. Regards, Maciek |