[Asterisk-java-users] query status via manager interface
Brought to you by:
srt
From: sKwee <sk...@it...> - 2005-06-19 01:16:01
|
Hi, i am trying to get some status information using the manager interface. I tried a StatusAction and several CommandActions with commands like "show sip users" etc. All I get are StatusCompleteEvents whith respone =3D "Success" and message =3D "Channel status will follow". I did setup a responseHandler and an eventHandler but what i cannot find anywhere is the status itself, i.e. a list of connected users. Did i miss something or is this kind of function not yet implemented ? regards and thanks for any hints =A0=A0=A0=A0=A0=A0Steve package default; import java.io.IOException; import net.sf.asterisk.manager.AuthenticationFailedException; import net.sf.asterisk.manager.ManagerConnection; import net.sf.asterisk.manager.ManagerConnectionFactory; import net.sf.asterisk.manager.ManagerEventHandler; import net.sf.asterisk.manager.ManagerResponseHandler; import net.sf.asterisk.manager.TimeoutException; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ManagerEvent; import net.sf.asterisk.manager.event.PeerStatusEvent; import net.sf.asterisk.manager.event.StatusCompleteEvent; import net.sf.asterisk.manager.response.ManagerResponse; public class HelloManager implements ManagerEventHandler, ManagerResponseHandler { =A0=A0=A0private ManagerConnection managerConnection; =A0=A0=A0public HelloManager() throws IOException =A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0ManagerConnectionFactory factory =3D new ManagerConnectionFactory(); =A0=A0=A0=A0=A0=A0=A0this.managerConnection =3D factory.getManagerConnection("localhost", =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0"admin", "xxx"); =A0=A0=A0} =A0=A0=A0/** =A0=A0=A0=A0* @see net.sf.asterisk.manager.ManagerResponseHandler#handleResponse(net.sf.asteri= sk.manager.response.ManagerResponse) =A0=A0=A0=A0*/ =A0=A0=A0public void handleResponse(ManagerResponse response) =A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0System.out.println ("# response : " + response); =A0=A0=A0=A0=A0=A0=A0System.out.println ("# response : " + response.getAttr= ibutes()); =A0=A0=A0} =A0=A0=A0 =A0=A0=A0public void handleEvent(ManagerEvent event) =A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0System.out.println ("# event : " + event); =A0=A0=A0=A0=A0=A0=A0if (event instanceof PeerStatusEvent) =A0=A0=A0=A0=A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0PeerStatusEvent pevent =3D (PeerStatusEven= t)event; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0System.out.println ("cause=A0 : " + pevent= .getCause()); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0System.out.println ("peer=A0=A0 : " + peve= nt.getPeer()); =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0System.out.println ("status : " + pevent.g= etPeerStatus()); =A0=A0=A0=A0=A0=A0=A0} =A0=A0=A0=A0=A0=A0=A0else if (event instanceof StatusCompleteEvent) =A0=A0=A0=A0=A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0StatusCompleteEvent sevent =3D (StatusComp= leteEvent)event; =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0System.out.println ("source : " + sevent.g= etSource()); =A0=A0=A0=A0=A0=A0=A0} =A0=A0=A0=A0=A0=A0=A0else =A0=A0=A0=A0=A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0// just print received events =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0System.out.println("# Event: " + event); =A0=A0=A0=A0=A0=A0=A0} =A0=A0=A0} =A0=A0=A0 =A0=A0=A0public void run() throws IOException, AuthenticationFailedExceptio= n, =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0TimeoutException, InterruptedException =A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0// register for events =A0=A0=A0=A0=A0=A0=A0managerConnection.addEventHandler(this); =A0=A0=A0=A0=A0=A0=A0// connect to Asterisk and log in =A0=A0=A0=A0=A0=A0=A0System.out.println ("# login"); =A0=A0=A0=A0=A0=A0=A0managerConnection.login(); =A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0System.out.println ("# send command"); =A0=A0=A0=A0=A0=A0=A0managerConnection.sendAction(new StatusAction(), this)= ; =A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0for (int i=3D0; i<10000; i++) =A0=A0=A0=A0=A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0Thread.sleep(20000); =A0=A0=A0=A0=A0=A0=A0} =A0=A0=A0=A0=A0=A0=A0// and finally log off and disconnect =A0=A0=A0=A0=A0=A0=A0managerConnection.logoff(); =A0=A0=A0} =A0=A0=A0public static void main(String[] args) throws Exception =A0=A0=A0{ =A0=A0=A0=A0=A0=A0=A0HelloManager helloManager; =A0=A0=A0=A0=A0=A0=A0helloManager =3D new HelloManager(); =A0=A0=A0=A0=A0=A0=A0helloManager.run(); =A0=A0=A0} } |