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 static com.google.common.base.Preconditions.checkNotNull;
020
021import com.google.common.annotations.Beta;
022
023/**
024 * Wraps an event that was posted, but which had no subscribers and thus could
025 * not be delivered.
026 *
027 * <p>Registering a DeadEvent subscriber is useful for debugging or logging, as
028 * it can detect misconfigurations in a system's event distribution.
029 *
030 * @author Cliff Biffle
031 * @since 10.0
032 */
033@Beta
034public class DeadEvent {
035
036  private final Object source;
037  private final Object event;
038
039  /**
040   * Creates a new DeadEvent.
041   *
042   * @param source  object broadcasting the DeadEvent (generally the
043   *                {@link EventBus}).
044   * @param event   the event that could not be delivered.
045   */
046  public DeadEvent(Object source, Object event) {
047    this.source = checkNotNull(source);
048    this.event = checkNotNull(event);
049  }
050
051  /**
052   * Returns the object that originated this event (<em>not</em> the object that
053   * originated the wrapped event).  This is generally an {@link EventBus}.
054   *
055   * @return the source of this event.
056   */
057  public Object getSource() {
058    return source;
059  }
060
061  /**
062   * Returns the wrapped, 'dead' event, which the system was unable to deliver
063   * to any registered subscriber.
064   *
065   * @return the 'dead' event that could not be delivered.
066   */
067  public Object getEvent() {
068    return event;
069  }
070
071}