Revision: 86
Author:   [email protected]
Date:     Mon Feb 18 00:17:33 2013
Log: updateThread start/stop is rewritten not to throw IllegalStateException
http://code.google.com/p/red5phone/source/detail?r=86

Modified:
 /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java

=======================================
--- /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java Sun Feb 17 20:52:20 2013 +++ /branches/red5sip/src/java/org/red5/sip/app/RTMPRoomClient.java Mon Feb 18 00:17:33 2013
@@ -56,7 +56,7 @@
     private String sipNumber = null;
     private ISipNumberListener sipNumberListener = null;
     private long lastSendActivityMS = 0L;
-    private Thread updateThread = new Thread(new Runnable() {
+    private final Runnable updateTask = new Runnable() {
         public void run() {
             while(true) {
                 try {
@@ -68,7 +68,8 @@
                 }
             }
         }
-    });
+    };
+    private Thread updateThread = null;

     protected enum ServiceMethod {
         connect,
@@ -111,7 +112,7 @@
         } catch (NoSuchFieldException e) {
                log.error("NoSuchFieldException", e);
         } catch (IllegalAccessException e) {
-               log.error("NoSuchFieldException", e);
+               log.error("IllegalAccessException", e);
         }
     }

@@ -223,6 +224,13 @@
         retryNumber = 0;
     }

+    private void shutdownUpdateThread() {
+        if(updateThread != null && updateThread.isAlive()) {
+            updateThread.interrupt();
+        }
+        updateThread = null;
+    }
+
     @Override
     public void connectionClosed( RTMPConnection conn, RTMP state ) {
         log.debug( "RTMP Connection closed" );
@@ -236,9 +244,7 @@
             log.debug( "Try reconnect..." );
             this.start();
         } else {
-            if(updateThread.isAlive()) {
-                updateThread.interrupt();
-            }
+               shutdownUpdateThread();
         }
     }

@@ -292,9 +298,7 @@
                 }
                 this.start();
             } else {
-                if(updateThread.isAlive()) {
-                    updateThread.interrupt();
-                }
+               shutdownUpdateThread();
             }
         }

@@ -400,6 +404,7 @@
                 break;
             case setSipTransport:
                 log.info("setSipTransport");
+                updateThread = new Thread(updateTask);
                 updateThread.start();
                 break;
             case updateSipTransport:

Reply via email to