Home | History | Annotate | Download | only in events

Lines Matching defs:Event

46  * Represents a subscriber, which implements various event bus handler methods.
70 * Represents an event handler with a priority.
90 * Represents the low level method handling a particular event.
94 Class<? extends EventBus.Event> eventType;
96 EventHandlerMethod(Method method, Class<? extends EventBus.Event> eventType) {
102 public void invoke(Object target, EventBus.Event event)
104 mMethod.invoke(target, event);
114 * A simple in-process event bus. It is simple because we can make assumptions about the state of
118 * Currently, there is a single EventBus that handles {@link EventBus.Event}s for each subscriber
120 * of that event, or post() events to be processed in the next run of the {@link Looper}. In
131 * Event method signature:<ul>
135 * <li>Methods must take one parameter, of class type deriving from {@link EventBus.Event}
139 * Interprocess-Event method signature:<ul>
162 * <li>Because the event handlers are called back using reflection, the EventBus is not intended
165 * <li>Because the event handlers are called back using reflection, there will often be no
180 * <li>Each event should be sent once. Events may hold internal information about the current
182 * so it may be unsafe to edit, change, or re-send the event again.
184 * initialized by the constructor and read by each subscriber of that event. Subscribers should
194 * <li>setSubscriberEventHandlerPriority(subscriber, Class<Event>, priority)
200 * <li>sendForResult&lt;ReturnType&gt;(Event) to send and get a result, but who will send the
210 * An event super class that allows us to track internal event state across subscriber
215 public static class Event implements Cloneable {
216 // Indicates that this event's dispatch should be traced and logged to logcat
218 // Indicates that this event must be posted on the EventBus's looper thread before invocation
220 // Not currently exposed, allows a subscriber to cancel further dispatch of this event
224 protected Event() {}
227 * Called by the EventBus prior to dispatching this event to any subscriber of this event.
234 * Called by the EventBus after dispatching this event to every subscriber of this event.
242 Event evt = (Event) super.clone();
243 // When cloning an event, reset the cancelled-dispatch state
250 * An event that represents an animated state change, which allows subscribers to coordinate
254 * after the event is dispatched.
256 public static class AnimatedEvent extends Event {
264 * Returns the reference counted trigger that coordinates the animations for this event.
295 * An event that can be reusable, only used for situations where we want to reduce memory
298 public static class ReusableEvent extends Event {
317 * An inter-process event super class that allows us to track user state across subscriber
320 public static class InterprocessEvent extends Event {
323 // The user which this event originated from
332 * Called from the event bus
359 // Used for passing event data across process boundaries
391 * Map from event class -> event handler list. Keeps track of the actual mapping from event
394 private HashMap<Class<? extends Event>, ArrayList<EventHandler>> mEventTypeMap = new HashMap<>();
397 * Map from subscriber class -> event handler method lists. Used to determine upon registration
399 * reflection or whether we can just add the subscriber to the event type map.
404 * Map from interprocess event name -> interprocess event class. Used for mapping the event
405 * name after receiving the broadcast, to the event type. After which a new instance is created
420 * Private constructor to create an event bus for a given looper.
427 * @return the default event bus for the application's main thread.
447 * be scanned for appropriate event handler methods.
458 * be scanned for appropriate event handler methods.
471 * be scanned for appropriate event handler methods.
482 * be scanned for appropriate event handler methods.
505 * mapping of subscriber type to event handler method, in case new instances of this subscriber
527 // For each of the event handlers the subscriber handles, remove all references of that
541 * Explicit unregistration for interprocess event subscribers. This actually behaves exactly
553 * Sends an event to the subscribers of the given event type immediately. This can only be
557 public void send(Event event) {
565 logWithPid("send(" + event.getClass().getSimpleName() + ")");
568 // Reset the event's cancelled state
569 event.requiresPost = false;
570 event.cancelled = false;
571 queueEvent(event);
575 * Post a message to the subscribers of the given event type. The messages will be posted on
578 public void post(Event event) {
580 logWithPid("post(" + event.getClass().getSimpleName() + ")");
583 // Reset the event's cancelled state
584 event.requiresPost = true;
585 event.cancelled = false;
586 queueEvent(event);
593 public void sendOntoMainThread(Event event) {
596 post(event);
598 send(event);
604 public void post(InterprocessEvent event) {
610 public void send(InterprocessEvent event) {
615 * Posts an interprocess event.
617 public void postInterprocess(Context context, final InterprocessEvent event) {
619 logWithPid("postInterprocess(" + event.getClass().getSimpleName() + ")");
621 String eventType = event.getClass().getName();
622 Bundle eventBundle = event.toBundle();
644 send((Event) ctor.newInstance(eventBundle));
681 output.append("Event map:");
761 // Find all the valid event bus handler methods of the subscriber
768 Class<? extends Event> eventType = (Class<? extends Event>) parameterTypes[0];
776 // Enforce that the event must have a Bundle constructor
796 " event: " + parameterTypes[0].getSimpleName() +
810 private void queueEvent(final Event event) {
811 ArrayList<EventHandler> eventHandlers = mEventTypeMap.get(event.getClass());
816 event.onPreDispatch();
817 event.onPostDispatch();
821 // Prepare this event
823 event.onPreDispatch();
832 if (event.requiresPost) {
836 processEvent(eventHandler, event);
841 processEvent(eventHandler, event);
846 // Clean up after this event, deferring until all subscribers have been called
851 event.onPostDispatch();
855 event.onPostDispatch();
860 * Processes and dispatches the given event to the given event handler, on the thread of whoever
863 private void processEvent(final EventHandler eventHandler, final Event event) {
864 // Skip if the event was already cancelled
865 if (event.cancelled) {
866 if (event.trace || DEBUG_TRACE_ALL) {
867 logWithPid("Event dispatch cancelled");
873 if (event.trace || DEBUG_TRACE_ALL) {
882 eventHandler.method.invoke(sub, event);
891 Log.e(TAG, "Failed to deliver event to null subscriber");
941 * @return whether {@param method} is a valid (normal or interprocess) event bus handler method
954 } else if (EventBus.Event.class.isAssignableFrom(parameterTypes[0]) &&
960 if (!EventBus.Event.class.isAssignableFrom(parameterTypes[0])) {
961 logWithPid(" Expected method take an Event-based parameter: " + method.getName());
983 * Sorts the event handlers by priority and registration time.