[SRADA-202]Make Connect Port Forward & UnFoward each Thread.
authorggh1933.go <ggh1933.go@samsung.com>
Tue, 15 Mar 2016 05:46:26 +0000 (14:46 +0900)
committerdongkyu6 lee <dongkyu6.lee@samsung.com>
Wed, 16 Mar 2016 01:54:31 +0000 (10:54 +0900)
 - Port Forward & UnForward take time about 2 secs.
 - delete sleep(1 sec it's too long) time and when createSocket failed, retry after sleep(defenseCode).
 - Make Unforward thread. so, don't need wait 1 sec.

Change-Id: I7b8093c13c800d67492038f184c5ed43de7569c3

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java [changed mode: 0644->0755]
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java

old mode 100644 (file)
new mode 100755 (executable)
index 4311a04..6bd62b5
@@ -71,7 +71,7 @@ public class BaseCommunicator {
        private int localPort = -1;
        private int remotePort = -1;
        private Socket controlSocket = null;
-
+       
        public BaseCommunicator(DeviceInfo device) {
                this.device = device;
        }
@@ -126,21 +126,43 @@ public class BaseCommunicator {
                                // port foward
                                localPort = CommunicatorUtils.getFreePort();
                                result = CommunicatorUtils.forward(device.getIDevice(), localPort, remotePort);
-                               if (!result.isSuccess()) {
-                                       Logger.warning("Failed to port fowarding, remove this device : "
-                                                       + device.getIDevice().getSerialNumber());
-                                       return result;
-                               }
+                                       if (!result.isSuccess()) {
+                                               Logger.warning("Failed to port fowarding, remove this device : "
+                                                               + device.getIDevice().getSerialNumber());
+                                               return result;
+                                       }
+                       }
+
+                       try {
+                               Thread.sleep(100);
+                       } catch (InterruptedException e) {
+                               e.printStackTrace();
                        }
 
                        // connect control socket
+
                        result = createControlSocket();
+
                        if (!result.isSuccess()) {
-                               Logger.warning(result.toString());
-                               result = new DAResult(ErrorCode.ERR_CONTROL_SOCKET_CREATION_FAIL);
-                               return result;
+                               // if connect Failed retry 'createControlSocket'
+                               try {
+                                       Thread.sleep(1000);
+                               } catch (InterruptedException e) {
+                               // TODO Auto-generated catch block
+                                       e.printStackTrace();
+                               }
+
+                               result = createControlSocket();
+                                       
+                               if (!result.isSuccess()) {
+                                       Logger.warning(result.toString());
+                                       result = new DAResult(ErrorCode.ERR_CONTROL_SOCKET_CREATION_FAIL);
+                                       return result;
+                               }
+
                        }
 
+
                        // get protocol version
                        protocolVersion = checkVersion();
                        if (protocolVersion == null || protocolVersion.isEmpty()) {
@@ -164,7 +186,14 @@ public class BaseCommunicator {
                } finally {
                        // unforward port (forwarded port is not necessary anymore)
                        if (localPort > 0 && remotePort > 0) {
-                               CommunicatorUtils.unforward(device.getIDevice(), localPort, remotePort);
+
+                               Thread UnforwardThread = new Thread(new Runnable() {
+                                       public void run() {
+                                               CommunicatorUtils.unforward(device.getIDevice(), localPort, remotePort);
+                                       }
+                               });
+
+                               UnforwardThread.start();
                        }
 
                        if (!result.isSuccess()) {
index 4128a6a..99b4a93 100755 (executable)
@@ -170,7 +170,6 @@ public class CommunicatorUtils {
                if (null != device && isOnline(device)) {
                        try {
                                device.createForward(local, remote);
-                               Thread.sleep(AnalyzerConstants.SOCKET_FORWARD_INTERVAL);
                        } catch (TimeoutException e) {
                                Logger.exception(e);
                                result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
@@ -183,10 +182,6 @@ public class CommunicatorUtils {
                                Logger.exception(e);
                                result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
                                result.setDetailMessage(e.getMessage());
-                       } catch (InterruptedException e) {
-                               Logger.exception(e);
-                               result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);
-                               result.setDetailMessage(e.getMessage());
                        } catch (NullPointerException e) {
                                Logger.exception(e);
                                result = new DAResult(ErrorCode.ERR_EXCEPTION_OCCURRED);