Re: [Asterisk-java-users] get queue Hold Time
Brought to you by:
srt
From: Yves A. <yv...@gm...> - 2014-03-16 12:16:18
|
Hi, the events you receive contain information about the queue, so you can crosscheck if the holdtime you get belongs to the query you sent... or you use an unique actionid and check against this to determine, if the event belongs to your request... I´ve given you a working example below. "can i call function through manager api and get the variables on that channel"..? answer: you can retrieve channelvariables, but the function you have to call first to retrieve the queueparametes (QUEUE_VARIABLES) which in turn sets the variables needs a channel... so no chance to use this without agi (where you always have a channel) without huge workarounds. The easiest way is to go the way you already started or to use a special context in your dialplan... but the example below works without modifications of your dialplan. yves import org.asteriskjava.manager.ManagerConnection; import org.asteriskjava.manager.ManagerConnectionFactory; import org.asteriskjava.manager.ManagerEventListener; import org.asteriskjava.manager.action.QueueStatusAction; import org.asteriskjava.manager.event.ManagerEvent; import org.asteriskjava.manager.event.QueueParamsEvent; import org.asteriskjava.manager.event.QueueStatusCompleteEvent; import org.asteriskjava.manager.response.ManagerResponse; public class GetQueueParameters implements ManagerEventListener { String actionID = "QSA_"+System.currentTimeMillis(); boolean waitForCompleteEvent=false; public GetQueueParameters(String queueName,String host, String user, String pass){ ManagerConnectionFactory factory = new ManagerConnectionFactory(host, user, pass); ManagerConnection managerConnection = factory.createManagerConnection(); QueueStatusAction queueStatus = new QueueStatusAction(); queueStatus.setQueue(queueName); queueStatus.setActionId(actionID); managerConnection.addEventListener(this); try{ managerConnection.login(); ManagerResponse mResponse = managerConnection.sendAction(queueStatus); waitForCompleteEvent = mResponse.getResponse().equals("Success"); long timeOutforCompletion=2000; // wait max. 2 Sec. then stop long sleepTime=500; while (waitForCompleteEvent && timeOutforCompletion>0) { Thread.sleep(sleepTime); timeOutforCompletion -= sleepTime; } managerConnection.removeEventListener(this); managerConnection.logoff(); } catch (Exception e){ e.printStackTrace(System.out); } } public void onManagerEvent(ManagerEvent me){ if (me instanceof QueueStatusCompleteEvent){ QueueStatusCompleteEvent qsce = (QueueStatusCompleteEvent) me; if (qsce.getActionId().equals(actionID)) waitForCompleteEvent=false; // we have all we need... so finish execution } if (me instanceof QueueParamsEvent){ QueueParamsEvent qpe = (QueueParamsEvent) me; if (qpe.getActionId().equals(actionID)){ int holdtime = qpe.getHoldTime(); String queueName = qpe.getQueue(); System.out.println("HoldTime for Queue "+queueName+" = " + holdtime); } } } public static void main(String[] args) throws Exception{ new GetQueueParameters("queue to query","yourserver","youruser","yourpass"); } } Am 16.03.2014 08:01, schrieb MT: > Hi yves, > > thanks for reply, > if I use event listener in the multi access system it could be another > QueueParams from another request. > how can I manage that? > about EventGeneratingAction I don't how to use it :( is there any > samples that use EventGeneratingAction? > > I found an asterisk funtion QUEUE_VARIABLES that gives queue name and > it set some variables that contains queue information like hold time > that I need, I can get hold time by AGI but I want to get it from > another server that have AMI access to it. > Can I call function through Manager API and get the variables on that > channel? > > > thanks yves, you are great :) > > Mohsen > > > On Sat, Mar 15, 2014 at 11:33 PM, Yves A. <yv...@gm... > <mailto:yv...@gm...>> wrote: > > Hi, > > the QueueStatusAction class is a so called > "EventGeneratingAction"... that means that asterisk-java will fire > the appropriate events which contain > further information after you sent the action... you have to > implement a listener for these events, catch them (in your case > the QueueParamsEvent) and read their information... > "success" after you snet the action means that your action was > properly sent... but before sending the action, you should have > set up your listeners... > because this is an asynchronous process, you should work with a > thread... (that can terminate after receiving the > (QueueStatusCompleteEvent).. > > regards, > yves > > Am 15.03.2014 17:25, schrieb MT: >> Hi everyone, >> >> I want to get Hold Time of specified Queue. >> >> I search everywhere to get it through AGI but there is no such a >> thing in AGI to get you hold time of given queue. >> So I decide to use Manager API and call QueueStatus to get >> HoldTime on the QueueParams section: >> >> this is my Manager Class: >> >> import java.io.IOException; >> >> import org.asteriskjava.manager.AuthenticationFailedException; >> import org.asteriskjava.manager.ManagerConnection; >> import org.asteriskjava.manager.ManagerConnectionFactory; >> import org.asteriskjava.manager.TimeoutException; >> import org.asteriskjava.manager.action.QueueStatusAction; >> import org.asteriskjava.manager.event.QueueParamsEvent; >> import org.asteriskjava.manager.response.ManagerResponse; >> >> public class Manager { >> >> private ManagerConnection managerConnection; >> >> public Manager(String host, String user, String pass) throws >> IOException { >> >> ManagerConnectionFactory factory = new >> ManagerConnectionFactory(host, user, pass); >> this.managerConnection = factory.createManagerConnection(); >> >> } >> >> public void getHoldTime(String queue) throws IOException, >> AuthenticationFailedException, TimeoutException, >> InterruptedException { >> >> QueueStatusAction queueStatus = new QueueStatusAction(); >> >> ManagerResponse statusResponse; >> >> queueStatus.setQueue(queue); >> >> >> // connect to Asterisk and log in >> managerConnection.login(); >> >> // send the originate action and wait for a maximum of 30 >> seconds for Asterisk >> // to send a reply >> statusResponse = >> managerConnection.sendAction(queueStatus, 2000); >> >> // print out whether the originate succeeded or not >> System.out.println("Response Result:" + >> statusResponse.toString()); >> >> // and finally log off and disconnect >> managerConnection.logoff(); >> } >> } >> >> >> I call getHoldTime from AGI: >> >> Manager m = new Manager(ip,user,pass); >> m.getHoldTime(queue); >> >> >> but it doesn't contain queue param section it just say successful >> for this action. >> >> please help me how to get hold time of specific queue with >> asterisk java. >> >> Mohsen >> >> >> ------------------------------------------------------------------------------ >> Learn Graph Databases - Download FREE O'Reilly Book >> "Graph Databases" is the definitive new guide to graph databases and their >> applications. Written by three acclaimed leaders in the field, >> this first edition is now available. Download your free book today! >> http://p.sf.net/sfu/13534_NeoTech >> >> >> _______________________________________________ >> Asterisk-java-users mailing list >> Ast...@li... <mailto:Ast...@li...> >> https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases > and their > applications. Written by three acclaimed leaders in the field, > this first edition is now available. Download your free book today! > http://p.sf.net/sfu/13534_NeoTech > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > <mailto:Ast...@li...> > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users > > > > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and their > applications. Written by three acclaimed leaders in the field, > this first edition is now available. Download your free book today! > http://p.sf.net/sfu/13534_NeoTech > > > _______________________________________________ > Asterisk-java-users mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-users |