001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.eventbus;
018
019import com.google.common.annotations.Beta;
020
021/**
022 * Wraps an event that was posted, but which had no subscribers and thus could
023 * not be delivered.
024 *
025 * <p>Subscribing a DeadEvent handler is useful for debugging or logging, as it
026 * can detect misconfigurations in a system's event distribution.
027 *
028 * @author Cliff Biffle
029 * @since 10.0
030 */
031@Beta
032public class DeadEvent {
033
034  private final Object source;
035  private final Object event;
036
037  /**
038   * Creates a new DeadEvent.
039   *
040   * @param source  object broadcasting the DeadEvent (generally the
041   *                {@link EventBus}).
042   * @param event   the event that could not be delivered.
043   */
044  public DeadEvent(Object source, Object event) {
045    this.source = source;
046    this.event = event;
047  }
048
049  /**
050   * Returns the object that originated this event (<em>not</em> the object that
051   * originated the wrapped event).  This is generally an {@link EventBus}.
052   *
053   * @return the source of this event.
054   */
055  public Object getSource() {
056    return source;
057  }
058
059  /**
060   * Returns the wrapped, 'dead' event, which the system was unable to deliver
061   * to any registered handler.
062   *
063   * @return the 'dead' event that could not be delivered.
064   */
065  public Object getEvent() {
066    return event;
067  }
068
069}