老李推荐:第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原理分析-事件源-事件源概览-命令队列...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JESD204B的AXI4-Lite时序
- 下一篇: win7中输入文件夹首字母跳到相应的文件