6th Chapter 6 "Monkeyrunner Source Analysis" Monkey principle-Event Source-Event Source Overview-command queue

Source: Internet
Author: User


After the event source obtains the string command and translates it into the corresponding Monkeyevent event, these events are queued into a queue maintained by the event source. Then other places such as the Monkey Class of the Runmonkeycycles method can go to the queue of events to be taken out for further processing. So here we first look at the class diagram of the command queue that belongs to the monkeysourcenetwork inner class:

Figure 6-6-1 Command Queue class diagram

The entire inheritance is clear and concise, and the Commandqueue interface defines a enqueueevent method to append events to the queue. Implementation class Commandqueueimpl implements this method and provides an additional getnextevent method to get events from the event queue queuedevents that it maintains.

Because the internal interface and the internal class of code is not much, so we will analyze the following:

481 public static interface Commandqueue {482/**483 * Enqueue A event to be returned later.  This allows a484 * command to return multiple events. Commands using the485 * command queue still has to return a valid event from their486 * Translatecomman  D method.  The returned command would be487 * executed before anything put into the queue.488 *489 * @param E The event to being enqueued.490 */491 public void enqueueevent (Monkeyevent e); 492};493 494//Qu  Eue of Events to be processed. This allows commands to push495//multiple events into the queue to be processed.496 private static class Command Queueimpl implements commandqueue{497 private final queue<monkeyevent> queuedevents = new Linkedlist<monk Eyevent> (); 498 499 public void Enqueueevent (Monkeyevent e) {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 };
code 6-6-1 commandqueue and Commandqueueimpl

    • 497 rows: Instantiates an event queue composed of Monkeyevent queuedevents
    • 499-501: Call the queue's offer method to add an event to the event queue
    • 508-510: Call Queue Poll method to take out an event in a queue and return

Note: More articles please pay attention to the public number: Techgogogo or personal blog http://techgogogo.com. Of course, you are also very welcome to pick up directly (ZHUBAITIAN1). This article by Heaven Zhuhai Branch Rudder original. Reproduced please consciously, whether the complaint rights to look at the mood.


6th Chapter 6 "Monkeyrunner Source anatomy" Monkey Principle Analysis-Event Source-Event Source Overview-command queue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.