Package com.brightcove.player.event
Class EventEmitterImpl
- java.lang.Object
-
- com.brightcove.player.event.EventEmitterImpl
-
- All Implemented Interfaces:
EventEmitter
public class EventEmitterImpl extends java.lang.Object implements EventEmitter
The 'Main' implementation of EventEmitter. Most Components should use this, as should RegisteringEventEmitter.
-
-
Field Summary
Fields Modifier and Type Field Description protected android.os.Handler
handler
-
Constructor Summary
Constructors Constructor Description EventEmitterImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disable()
Disables listener registration and event emitting.void
emit(java.lang.String eventType)
Emits an event.void
emit(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties)
Emits an event, passing along the properties mapvoid
emitNow(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties)
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(java.util.List<com.brightcove.player.event.InvocationContainer> invocations, int token)
Returns the InvocationContainer in a list of Containers which matches the tokenprotected int
getInvocationContainerPositionByToken(java.util.List<com.brightcove.player.event.InvocationContainer> invocations, int token)
Returns the position of an invocationContainervoid
off()
Removes all listeners.void
off(java.lang.String eventType, int token)
Removes a listener from an event queue, using the token as a referenceint
on(java.lang.String eventType, EventListener listener)
Adds the listener to the event queue, returns a token that the caller can use to off itself.int
once(java.lang.String eventType, EventListener listener)
Similar to on, except that the listener is removed after processing one event.void
request(java.lang.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
request(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties, EventListener listener)
Similar to above, except the properties map is passed alongvoid
respond(Event event)
Convenience method to save the user from typing event.properties when respondingvoid
respond(java.util.Map<java.lang.String,java.lang.Object> properties)
Meant to respond to a request event.
-
-
-
Method Detail
-
on
public int on(java.lang.String eventType, EventListener listener)
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:
EventListener
,EventEmitter.on(String, com.brightcove.player.event.EventListener)
-
once
public int once(java.lang.String eventType, EventListener listener)
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:
EventListener
,EventEmitter.once(String, com.brightcove.player.event.EventListener)
-
off
public void off()
Removes all listeners.- Specified by:
off
in interfaceEventEmitter
-
off
public void off(java.lang.String eventType, int token)
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:
EventEmitter.off(String, int)
-
emit
public void emit(java.lang.String eventType)
Emits an event. All listeners attached to this event will be processed- Specified by:
emit
in interfaceEventEmitter
- Parameters:
eventType
-- See Also:
EventEmitter.emit(String)
-
emit
public void emit(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties)
Emits an event, passing along the properties map- Specified by:
emit
in interfaceEventEmitter
- Parameters:
eventType
-properties
-- See Also:
EventEmitter.emit(String, java.util.Map)
-
emitNow
@RestrictTo(LIBRARY) @MainThread public void emitNow(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.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
public void request(java.lang.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.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:
EventEmitter.request(String, com.brightcove.player.event.EventListener)
,EventListener
-
request
public void request(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties, EventListener listener)
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:
EventEmitter.request(String, java.util.Map, com.brightcove.player.event.EventListener)
,EventListener
-
respond
public void respond(java.util.Map<java.lang.String,java.lang.Object> properties)
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
public void respond(Event event)
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:
Event
-
getInvocationContainerPositionByToken
protected int getInvocationContainerPositionByToken(java.util.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(java.util.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
-
-