[Asterisk-java-users] Events do not get displayed on console
Brought to you by:
srt
From: Aparna R. <apa...@ya...> - 2006-02-24 09:58:45
|
Hello, I have the following programs using ManagerAPI. I want to run another thread, along with the handling of the asterisk events. The code follows and the question below the code. SeamlessMobility.java (main class) ---------------------------------------------------- public class SeamlessMobility implements ManagerEventHandler { public ManagerConnection managerConnection; private SnmpThread snmp; public SeamlessMobility() throws IOException { ManagerConnectionFactory factory = new ManagerConnectionFactory(); this.managerConnection = factory.getManagerConnection("localhost", "manager", "pass"); snmp = new SnmpThread(this); } public void run() { // register for events managerConnection.addEventHandler(this); try { // connect to Asterisk and log in managerConnection.login(); } catch(IOException ioe) { System.out.println("Manager Login-IOException-> "+ioe); } catch(AuthenticationFailedException afe) { System.out.println("Login-Authentication Failed Exc-> "+afe); return; } catch(TimeoutException toe) { System.out.println("Login-TimeOut Exc-> "+toe); return; } try { snmp.start(); Thread.sleep(1000); } catch(InterruptedException ie) { System.out.println("Interrupted Exc-> "+ie); } registerOnStart(); try { // and finally log off and disconnect managerConnection.logoff(); } catch(IOException ioe) { System.out.println("Manager Logoff-IOException-> "+ioe); } catch(TimeoutException toe) { System.out.println("Logoff-TimeOut Exc-> "+toe); } } public void registerOnStart() { // do the work snmp.run(); } public void handleEvent(ManagerEvent event) { if (event instanceof PeerStatusEvent) { String peerName = ((PeerStatusEvent) event).getPeer(); String peerStatus = ((PeerStatusEvent) event).getPeerStatus(); System.out.println("\nPeer '"+peerName+"' is "+peerStatus); } } public static void main(String[] args) { SeamlessMobility sm; try { sm = new SeamlessMobility(); sm.run(); } catch(IOException io) { System.out.println("Main Method - IO Exc "+io); } } } ------------------ SnmpThread.java (another class) which has a run() method. ------------------ To run the SnmpThread thread, I use snmp.start() in the run() method of the main class(SeamlessMobility.java). This also invokes the run() method of the snmp thread. But the Asterisk events do not get recorded in the java output console, unless I explicitly specify snmp.run() in the registerOnStart() method of the main class (shown in bold). But since this is not the right way to go about it, can you plz guide me on how do I make the Asterisk events get displayed on the console? Thanks much in advance Regards, Aparna --------------------------------- Relax. Yahoo! Mail virus scanning helps detect nasty viruses! |