1/*
2 * Copyright (C) 2007 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.eventbus;
18
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import com.google.common.annotations.Beta;
22
23/**
24 * Wraps an event that was posted, but which had no subscribers and thus could
25 * not be delivered.
26 *
27 * <p>Registering a DeadEvent subscriber is useful for debugging or logging, as
28 * it can detect misconfigurations in a system's event distribution.
29 *
30 * @author Cliff Biffle
31 * @since 10.0
32 */
33@Beta
34public class DeadEvent {
35
36  private final Object source;
37  private final Object event;
38
39  /**
40   * Creates a new DeadEvent.
41   *
42   * @param source  object broadcasting the DeadEvent (generally the
43   *                {@link EventBus}).
44   * @param event   the event that could not be delivered.
45   */
46  public DeadEvent(Object source, Object event) {
47    this.source = checkNotNull(source);
48    this.event = checkNotNull(event);
49  }
50
51  /**
52   * Returns the object that originated this event (<em>not</em> the object that
53   * originated the wrapped event).  This is generally an {@link EventBus}.
54   *
55   * @return the source of this event.
56   */
57  public Object getSource() {
58    return source;
59  }
60
61  /**
62   * Returns the wrapped, 'dead' event, which the system was unable to deliver
63   * to any registered subscriber.
64   *
65   * @return the 'dead' event that could not be delivered.
66   */
67  public Object getEvent() {
68    return event;
69  }
70
71}
72