[Asterisk-java-users] Re:help using PeerStatusEvent
Brought to you by:
srt
From: Aparna R. <apa...@ya...> - 2005-11-25 15:32:50
|
Hi Stefan, Thnx for ur reply.The PeerStatusEvent now works. but before i get the name of the peer that just registered, i get a 'java.lang.InterruptedException : sleep interrupted'. But.. if i wait for long, the name of the peer that registered is displayed. Also the Connection doesn't logoff.! This is my Code: 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.TimeoutException; import net.sf.asterisk.manager.action.StatusAction; import net.sf.asterisk.manager.event.ManagerEvent; public class HelloEvents implements ManagerEventHandler { private ManagerConnection managerConnection; public HelloEvents() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "manager", "pa55w0rd"); } public void run() throws IOException, AuthenticationFailedException, TimeoutException, InterruptedException { // register for events managerConnection.addEventHandler(this); // connect to Asterisk and log in managerConnection.login(); // request channel state managerConnection.sendAction(new StatusAction()); // wait 10 seconds for events to come in Thread.sleep(10000); // and finally log off and disconnect managerConnection.logoff(); } public void handleEvent(ManagerEvent event) { if (event instanceof PeerStatusEvent) { String peerName= ((PeerStatusEvent) event).getPeer(); System.out.println(peerName+ " has just now registered!"); } } public static void main(String[] args) throws Exception { HelloEvents helloEvents; helloEvents = new HelloEvents(); helloEvents.run(); } } kindly tel me if I'm going wrong somewhere. Thanks n regards Aparna -------------------------------------------- Hi all, I'm completely new to Java and need help n guidance in using asterisk-java. I would like to get the name of the Peer from asterisk , when it registers. how shouild i go abt implementing this? i know i shd luk into PeerStatusEvent. but being new to Java, i would like some sample code to help me with. kindly guide. thanks n regards aparna --------------------------------- Yahoo! DSL Something to write home about. Just $16.99/mo. or less |