From: ggh1933.go Date: Tue, 15 Mar 2016 05:46:26 +0000 (+0900) Subject: [SRADA-202]Make Connect Port Forward & UnFoward each Thread. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=abdb1a75a2aa292e024a1b62272cf7aec8e2dd76;p=sdk%2Ftools%2Fdynamic-analyzer.git [SRADA-202]Make Connect Port Forward & UnFoward each Thread. - 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 --- diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java old mode 100644 new mode 100755 index 4311a04..6bd62b5 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/BaseCommunicator.java @@ -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()) { diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java index 4128a6a..99b4a93 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/communicator/CommunicatorUtils.java @@ -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);