Sl4aEventDispatcher

public class Sl4aEventDispatcher
extends Thread

java.lang.Object
   ↳ java.lang.Thread
     ↳ com.android.tradefed.util.sl4a.Sl4aEventDispatcher


Event dispatcher polls for event and queue them by name to be queried. TODO: add support for event handlers.

Summary

Nested classes

class Sl4aEventDispatcher.EventSl4aObject

Object returned by the event poller. 

Constants

String SHUTDOWN_EVENT

Public constructors

Sl4aEventDispatcher(Sl4aClient client, long timeout)

Public methods

void cancel()

Stop the thread execution and clean up all the events.

void clearAllEvents()

clear all the events

void clearEvents(String name)

Clear all the events for one event name.

List<Sl4aEventDispatcher.EventSl4aObject> popAllEvents(String name)

Return all the events of one type, or empty list if no event.

Sl4aEventDispatcher.EventSl4aObject popEvent(String name, long timeout)

Poll for one event by name

void run()
Sl4aEventDispatcher.EventSl4aObject waitForEvent(String name, Predicate<Sl4aEventDispatcher.EventSl4aObject> predicate, long timeout)

Poll for a particular event that match the name and predicate.

Protected methods

boolean internalPolling()

Internal polling of events, should not be called.

Constants

SHUTDOWN_EVENT

String SHUTDOWN_EVENT

Constant Value: "EventDispatcherShutdown"

Public constructors

Sl4aEventDispatcher

Sl4aEventDispatcher (Sl4aClient client, 
                long timeout)

Parameters
client Sl4aClient
timeout long

Public methods

cancel

void cancel ()

Stop the thread execution and clean up all the events.

clearAllEvents

void clearAllEvents ()

clear all the events

clearEvents

void clearEvents (String name)

Clear all the events for one event name.

Parameters
name String

popAllEvents

List<Sl4aEventDispatcher.EventSl4aObject> popAllEvents (String name)

Return all the events of one type, or empty list if no event.

Parameters
name String
Returns
List<Sl4aEventDispatcher.EventSl4aObject>

popEvent

Sl4aEventDispatcher.EventSl4aObject popEvent (String name, 
                long timeout)

Poll for one event by name

Parameters
name String: the name of the event.
timeout long: the timeout in millisecond for the pop event to return.
Returns
Sl4aEventDispatcher.EventSl4aObject the Sl4aEventDispatcher.EventSl4aObject or null if no event found.

run

void run ()

waitForEvent

Sl4aEventDispatcher.EventSl4aObject waitForEvent (String name, 
                Predicate<Sl4aEventDispatcher.EventSl4aObject> predicate, 
                long timeout)

Poll for a particular event that match the name and predicate.

Parameters
name String: the name of the event.
predicate Predicate: the predicate the event needs to pass.
timeout long: timeout the timeout in millisecond for the pop event to return.
Returns
Sl4aEventDispatcher.EventSl4aObject the Sl4aEventDispatcher.EventSl4aObject or null if no event found.

Protected methods

internalPolling

boolean internalPolling ()

Internal polling of events, should not be called. Exposed for testing.

Returns
boolean