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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
disable()
Disables listener registration and event emitting.void
Emits an event.void
Emits an event, passing along the properties mapvoid
Emits an event immediately instead of waiting for the handler.void
enable()
Enables listener registration and event emitting.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 tokenprotected int
getInvocationContainerPositionByToken
(List<com.brightcove.player.event.InvocationContainer> invocations, int token) Returns the position of an invocationContainervoid
off()
Removes all listeners.void
Removes a listener from an event queue, using the token as a referenceint
on
(String eventType, EventListener listener) Adds the listener to the event queue, returns a token that the caller can use to off itself.int
once
(String eventType, EventListener listener) Similar to on, except that the listener is removed after processing one event.void
request
(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.void
Similar to above, except the properties map is passed alongvoid
Convenience method to save the user from typing event.properties when respondingvoid
Meant 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:
on
in 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:
once
in 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:
off
in interfaceEventEmitter
-
off
Removes a listener from an event queue, using the token as a reference- Specified by:
off
in 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:
emit
in interfaceEventEmitter
- Parameters:
eventType
-- See Also:
-
emit
Emits an event, passing along the properties map- Specified by:
emit
in interfaceEventEmitter
- Parameters:
eventType
-properties
-- See Also:
-
emitNow
@RestrictTo(LIBRARY) @MainThread public void emitNow(String eventType, Map<String, Object> properties) Description copied from interface:EventEmitter
Emits an event immediately instead of waiting for the handler.- Specified by:
emitNow
in 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:
request
in 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:
request
in 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:
respond
in interfaceEventEmitter
- Parameters:
properties
-
-
respond
Convenience method to save the user from typing event.properties when responding- Specified by:
respond
in 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:
enable
in interfaceEventEmitter
-
disable
public void disable()Disables listener registration and event emitting.- Specified by:
disable
in interfaceEventEmitter
-