Package com.brightcove.player.event
Class EventEmitterImpl
java.lang.Object
com.brightcove.player.event.EventEmitterImpl
- All Implemented Interfaces:
EventEmitter
The 'Main' implementation of EventEmitter. Most Components should
use this, as should RegisteringEventEmitter.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddisable()Disables listener registration and event emitting.voidEmits an event.voidEmits an event, passing along the properties mapvoidEmits an event immediately instead of waiting for the handler.voidenable()Enables listener registration and event emitting.protected com.brightcove.player.event.InvocationContainergetInvocationContainerByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token) Returns the InvocationContainer in a list of Containers which matches the tokenprotected intgetInvocationContainerPositionByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token) Returns the position of an invocationContainervoidoff()Removes all listeners.voidRemoves a listener from an event queue, using the token as a referenceinton(String eventType, EventListener listener) Adds the listener to the event queue, returns a token that the caller can use to off itself.intonce(String eventType, EventListener listener) Similar to on, except that the listener is removed after processing one event.voidrequest(String eventType, EventListener listener) Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener set to 'respond' to the listener specified in the request.voidSimilar to above, except the properties map is passed alongvoidConvenience method to save the user from typing event.properties when respondingvoidMeant to respond to a request event.
-
Field Details
-
handler
protected android.os.Handler handler
-
-
Constructor Details
-
EventEmitterImpl
public EventEmitterImpl()
-
-
Method Details
-
on
Adds the listener to the event queue, returns a token that the caller can use to off itself. Calls to on are stored in the order they arrive, which means that during event propagation, the listeners will be executed in the order they were added.- Specified by:
onin interfaceEventEmitter- Parameters:
eventType- A String representing the Event to be listened forlistener- An abstract class of EventListener, that contains a method to process during an Event's firing- Returns:
- token An integer representing the id token of the listener. Objects that invoke this method should cache the token, which is used as a reference to remove a Listener
- See Also:
-
once
Similar to on, except that the listener is removed after processing one event.- Specified by:
oncein interfaceEventEmitter- Parameters:
eventType- Same as for 'on'; a string representing the event to be listened forlistener- Subclass of EventListener- Returns:
- token
- See Also:
-
off
public void off()Removes all listeners.- Specified by:
offin interfaceEventEmitter
-
off
Removes a listener from an event queue, using the token as a reference- Specified by:
offin interfaceEventEmitter- Parameters:
eventType- A string representing the Event typetoken- Integer-valued token that was created during 'on'- See Also:
-
emit
Emits an event. All listeners attached to this event will be processed- Specified by:
emitin interfaceEventEmitter- Parameters:
eventType-- See Also:
-
emit
Emits an event, passing along the properties map- Specified by:
emitin interfaceEventEmitter- Parameters:
eventType-properties-- See Also:
-
emitNow
@RestrictTo(LIBRARY) @MainThread public void emitNow(String eventType, Map<String, Object> properties) Description copied from interface:EventEmitterEmits an event immediately instead of waiting for the handler.- Specified by:
emitNowin interfaceEventEmitter- Parameters:
eventType- The event type.properties- The properties to send when processing the event.
-
request
Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener set to 'respond' to the listener specified in the request.The flow looks something like:
request ->emit eventType -> eventType listener picks up event -> respond -> listener passed into request is called
After the listener is executed, it is removed
- Specified by:
requestin interfaceEventEmitter- Parameters:
eventType- The type of Event to emit and expect a response fromlistener- A listener to process the response. After processing, the response should be removed- See Also:
-
request
Similar to above, except the properties map is passed along- Specified by:
requestin interfaceEventEmitter- Parameters:
eventType- The type of Event to emit and expect a response fromproperties- A Map of properties to pass along the event chainlistener- A listener to process the response. After processing, the response should be removed- See Also:
-
respond
Meant to respond to a request event. By way of using Event.REQUEST_TOKEN to identify the listener created during the request, the respond fires an event 'directly' at said listener. Note that if the properties map does not contain Event.REQUEST_TOKEN, this method is a no-op. The intent for this behavior is that if an EventListener contains a call to respond, but there was no actual request, nothing should break (e.g. several 'play' event listeners, but only one is intended to respond to requests.- Specified by:
respondin interfaceEventEmitter- Parameters:
properties-
-
respond
Convenience method to save the user from typing event.properties when responding- Specified by:
respondin interfaceEventEmitter- Parameters:
event- An Event containing properties to pass on to the Request listener- See Also:
-
getInvocationContainerPositionByToken
protected int getInvocationContainerPositionByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token) Returns the position of an invocationContainer- Parameters:
token-- Returns:
- The position in the queue of the invocation container associated with the token.
- See Also:
-
InvocationContainer
-
getInvocationContainerByToken
protected com.brightcove.player.event.InvocationContainer getInvocationContainerByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token) Returns the InvocationContainer in a list of Containers which matches the token- Parameters:
invocations-token-- Returns:
- The invocation container associated with the token.
- See Also:
-
InvocationContainer
-
enable
public void enable()Enables listener registration and event emitting.- Specified by:
enablein interfaceEventEmitter
-
disable
public void disable()Disables listener registration and event emitting.- Specified by:
disablein interfaceEventEmitter
-