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