Home | History | Annotate | Download | only in eventbus
      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 
     17 package com.google.common.eventbus;
     18 
     19 import com.google.common.annotations.Beta;
     20 
     21 /**
     22  * Wraps an event that was posted, but which had no subscribers and thus could
     23  * not be delivered.
     24  *
     25  * <p>Subscribing a DeadEvent handler is useful for debugging or logging, as it
     26  * can detect misconfigurations in a system's event distribution.
     27  *
     28  * @author Cliff Biffle
     29  * @since 10.0
     30  */
     31 @Beta
     32 public class DeadEvent {
     33 
     34   private final Object source;
     35   private final Object event;
     36 
     37   /**
     38    * Creates a new DeadEvent.
     39    *
     40    * @param source  object broadcasting the DeadEvent (generally the
     41    *                {@link EventBus}).
     42    * @param event   the event that could not be delivered.
     43    */
     44   public DeadEvent(Object source, Object event) {
     45     this.source = source;
     46     this.event = event;
     47   }
     48 
     49   /**
     50    * Returns the object that originated this event (<em>not</em> the object that
     51    * originated the wrapped event).  This is generally an {@link EventBus}.
     52    *
     53    * @return the source of this event.
     54    */
     55   public Object getSource() {
     56     return source;
     57   }
     58 
     59   /**
     60    * Returns the wrapped, 'dead' event, which the system was unable to deliver
     61    * to any registered handler.
     62    *
     63    * @return the 'dead' event that could not be delivered.
     64    */
     65   public Object getEvent() {
     66     return event;
     67   }
     68 
     69 }
     70