日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

老李推荐:第6章6节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令队列...

發布時間:2023/12/19 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 老李推荐:第6章6节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令队列... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

老李推薦:第6章6節《MonkeyRunner源碼剖析》Monkey原理分析-事件源-事件源概覽-命令隊列

事件源在獲得字串命令并把它翻譯成對應的MonkeyEvent事件后,會把這些事件排隊放入一個由事件源維護的隊列,然后其他地方如Monkey類的runMonkeyCycles方法就可以去把隊列里面的事件取出來進一步進行處理了。那么這里我們先看下屬于MonkeySourceNetwork內部類的命令隊列的類圖:

圖6-6-1 命令隊列類圖

整個繼承關系非常清晰簡潔,CommandQueue接口定義了一個enqueueEvent方法來往對隊列里面追加事件;實現類CommandQueueImpl實現了該方法并且額外提供了一個getNextEvent方法來從其維護的事件隊列queuedEvents中獲取事件。

因為這個內部接口和內部類的代碼量并不多,所以我們以下列出來一并分析:

481???? public static interface CommandQueue {

482???????? /**

483????????? * Enqueue an event to be returned later.? This allows a

484????????? * command to return multiple events.? Commands using the

485????????? * command queue still have to return a valid event from their

486????????? * translateCommand method.? The returned command will be

487????????? * executed before anything put into the queue.

488????????? *

489????????? * @param e the event to be enqueued.

490????????? */

491???????? public void enqueueEvent(MonkeyEvent e);

492???? };

493

494???? // Queue of Events to be processed.? This allows commands to push

495???? // multiple events into the queue to be processed.

496???? private static class CommandQueueImpl implements CommandQueue{

497???????? private final Queue<MonkeyEvent> queuedEvents = new LinkedList<MonkeyEvent>();

498

499???????? public void enqueueEvent(MonkeyEvent e) {

500???????????? queuedEvents.offer(e);

501???????? }

502

503???????? /**

504????????? * Get the next queued event to excecute.

505????????? *

506????????? * @return the next event, or null if there aren't any more.

507????????? */

508???????? public MonkeyEvent getNextQueuedEvent() {

509???????????? return queuedEvents.poll();

510???????? }

511???? };

代碼6-6-1 CommandQueue和CommandQueueImpl

?

  • 497行: 實例化了一個由MonkeyEvent組成的事件隊列queuedEvents

  • 499-501: 調用隊列Queue的offer方法往事件隊列增加一個事件

  • 508-510: 調用隊列Queue的poll方法從事件隊列中取出一個事件并返回


轉載于:https://blog.51cto.com/10988776/1731426

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的老李推荐:第6章6节《MonkeyRunner源码剖析》Monkey原理分析-事件源-事件源概览-命令队列...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。