[Asterisk-java-users] SendAction not work after reconnection
Brought to you by:
srt
From: King H. <kin...@ne...> - 2006-03-05 08:26:54
|
Hi, =20 I was test the robustness of Asterisk-Java with an un-stable Asterisk = server. That is, to see if there is any problem in Asterisk-Java = handling of server disconnects and reconnects. Below is the example = HelloEvents.java program with some minor modification so that the run() = methed will not exit: =20 public class HelloEvents implements ManagerEventHandler { private ManagerConnection managerConnection; =20 public HelloEvents() throws IOException { ManagerConnectionFactory factory =3D new = ManagerConnectionFactory("localhost", 5038, "username", "password"); this.managerConnection =3D factory.createManagerConnection(); } =20 public void run() throws IOException, AuthenticationFailedException, TimeoutException, InterruptedException { // register for events managerConnection.addEventHandler(this); =20 // connect to Asterisk and log in managerConnection.login(); =20 // request channel state managerConnection.sendAction(new StatusAction()); =20 while (true) { Thread.sleep(10000); }=20 =20 // and finally log off and disconnect //managerConnection.logoff(); } =20 public void handleEvent(ManagerEvent event) { // just print received events System.out.println(event); } =20 public static void main(String[] args) throws Exception { HelloEvents helloEvents; =20 helloEvents =3D new HelloEvents(); helloEvents.run(); } } =20 =20 =20 After stating the program I got the following from the console: =20 2006/3/5 =E4=B8=8B=E5=8D=88 04:12:04 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Connecting to 192.168.1.109 port 5038 org.asteriskjava.manager.event.ConnectEvent[dateReceived=3DSun Mar 05 = 16:12:05 GMT+08:00 2006,protocolidentifier=3D'Asterisk Call = Manager/1.0',systemHashcode=3D22507120] 2006/3/5 =E4=B8=8B=E5=8D=88 04:12:05 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Connected via Asterisk Call Manager/1.0 2006/3/5 =E4=B8=8B=E5=8D=88 04:12:05 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Successfully logged in org.asteriskjava.manager.event.StatusCompleteEvent[dateReceived=3DSun = Mar 05 16:12:05 GMT+08:00 = 2006,internalactionid=3D'8949356_3',actionid=3D'null',systemHashcode=3D19= 647819] 2006/3/5 =E4=B8=8B=E5=8D=88 04:12:05 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Determined Asterisk version: Asterisk 1.2 org.asteriskjava.manager.event.ShutdownEvent[dateReceived=3DSun Mar 05 = 16:12:14 GMT+08:00 = 2006,privilege=3D'system,all',restart=3D'false',shutdown=3D'Cleanly',syst= emHashcode=3D849515] org.asteriskjava.manager.event.DisconnectEvent[dateReceived=3DSun Mar 05 = 16:12:14 GMT+08:00 2006,systemHashcode=3D17171576] =20 =20 =20 This is all normal. Now, I do a =E2=80=9Crestart now=E2=80=9D on the = asterisk server and I got the following: =20 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Closing socket. org.asteriskjava.manager.event.ConnectEvent[dateReceived=3DSun Mar 05 = 16:21:16 GMT+08:00 2006,protocolidentifier=3D'Asterisk Call = Manager/1.0',systemHashcode=3D14372770] 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Connecting to 192.168.1.109 port 5038 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Connected via Asterisk Call Manager/1.0 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Successfully logged in 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Determined Asterisk version: Asterisk 1.0 2006/3/5 =E4=B8=8B=E5=8D=88 04:21:16 = org.asteriskjava.util.impl.JavaLoggingLog info =E8=B3=87=E8=A8=8A: Successfully reconnected. org.asteriskjava.manager.event.RegistryEvent[dateReceived=3DSun Mar 05 = 16:21:18 GMT+08:00 = 2006,privilege=3D'system,all',domain=3D'152.104.231.22',username=3D'null'= ,cause=3D'null',status=3D'Registered',channel=3D'SIP',systemHashcode=3D20= 415955] =20 =20 =20 Notice the line which display the Asterisk version. It now says that it = is=20 =E2=80=9CAsterisk 1.0=E2=80=9D. I think this is caused by Asterisk-Java = having problem sending An action to determine the version of asterisk. =20 The connection seems to work fine for receiving events, it just have = problem sending Actions. =20 This test was done with Asterisk-Java 0.3, but I think the problem also = exists in 0.2. =20 =20 =20 Thanks. =20 King |