第14章4节《MonkeyRunner源码剖析》 HierarchyViewer实现原理-装备ViewServer-端口转发 2
2016-01-11 16:30
375 查看
从以上代码中我们可以看到该方法去装备ViewServer主要做的事情有如下几点:40行:设置本地端口到目标机器端ViewServer监听端口的端口转发
41-54行:确定ViewServer线程是否已经启动,没有的话就启动它。
55行:获取ViewServer的版本以及其支持的协议版本
本小节我们先描述第一点,看HierarchyViewer是如何设置本地端口到目标机器端ViewServer监听端口的端口转发的。在第13章第2小节我们也手动做过这个事情,当时发送的命令是:adb forward tcp:4939 tcp:4939那么HierarchyViewer是不是也是通过代码做相同的事情呢?那么我们带着这个疑问来进入深入的代码分析。我们进入setupDeviceForward这个方法:110 /** 111 * Sets up a just-connected device to work with the view server. 112 * <p/> 113 * This starts a port forwarding between a local port and a port on the 114 * device. 115 * 116 * @param device 117 */ 118 public static void setupDeviceForward(IDevice device) { 119 synchronized (sDevicePortMap) { 120 if (device.getState() == IDevice.DeviceState.ONLINE) { 121 int localPort = sNextLocalPort++; 122 try { 123 device.createForward(localPort, DEFAULT_SERVER_PORT); 124 sDevicePortMap.put(device, localPort); 125 } catch (TimeoutException e) { 126 Log.e(TAG, "Timeout setting up port forwarding for " + device); 127 } catch (AdbCommandRejectedException e) { 128 Log.e(TAG, String.format("Adb rejected forward command for device %1$s: %2$s", 129 device, e.getMessage())); 130 } catch (IOException e) { 131 Log.e(TAG, String.format("Failed to create forward for device %1$s: %2$s", 132 device, e.getMessage())); 133 } 134 } 135 } 136 } 代码14-4-2 DeviceBridge - setupDeviceForward
41-54行:确定ViewServer线程是否已经启动,没有的话就启动它。
55行:获取ViewServer的版本以及其支持的协议版本
本小节我们先描述第一点,看HierarchyViewer是如何设置本地端口到目标机器端ViewServer监听端口的端口转发的。在第13章第2小节我们也手动做过这个事情,当时发送的命令是:adb forward tcp:4939 tcp:4939那么HierarchyViewer是不是也是通过代码做相同的事情呢?那么我们带着这个疑问来进入深入的代码分析。我们进入setupDeviceForward这个方法:110 /** 111 * Sets up a just-connected device to work with the view server. 112 * <p/> 113 * This starts a port forwarding between a local port and a port on the 114 * device. 115 * 116 * @param device 117 */ 118 public static void setupDeviceForward(IDevice device) { 119 synchronized (sDevicePortMap) { 120 if (device.getState() == IDevice.DeviceState.ONLINE) { 121 int localPort = sNextLocalPort++; 122 try { 123 device.createForward(localPort, DEFAULT_SERVER_PORT); 124 sDevicePortMap.put(device, localPort); 125 } catch (TimeoutException e) { 126 Log.e(TAG, "Timeout setting up port forwarding for " + device); 127 } catch (AdbCommandRejectedException e) { 128 Log.e(TAG, String.format("Adb rejected forward command for device %1$s: %2$s", 129 device, e.getMessage())); 130 } catch (IOException e) { 131 Log.e(TAG, String.format("Failed to create forward for device %1$s: %2$s", 132 device, e.getMessage())); 133 } 134 } 135 } 136 } 代码14-4-2 DeviceBridge - setupDeviceForward
相关文章推荐
- 老李性能测试分享
- 你想不到:咖啡馆里上工具课
- 移动端自动化测试开课了
- 老李分享:什么是好战略
- 性能调优案例分享:Mysql的cpu过高
- 性能测试分享:性能测试工具开发的案例分享(上)
- 性能测试分享:性能测试工具开发的案例分享(下)
- 性能测试培训:批量执行Jmeter脚本之ant调用 2
- 性能测试培训:分布式测试之jmeter1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程2
- 老李案例分享:定位JAVA内存溢出 1
- 老李案例分享:定位JAVA内存溢出 2
- 性能测试培训: 建立压力模型
- 老李分享:你知道有哪些持续集成工具
- 老李分享知识:性能测试之TPS和吞吐率
- 老李分享知识:性能测试之吞吐量
- 性能测试培训:分析内训泄露的案例
- 自动化测试培训:qtp脚本获取获取汇率数据
- 性能测试培训:sql server性能测试分析局部变量的性能影响1