11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors 31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License"); 51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License. 61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at 71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0 91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software 111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS, 121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and 141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License. 151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.eventbus; 181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.annotations.Beta; 201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/** 221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Wraps an event that was posted, but which had no subscribers and thus could 231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * not be delivered. 241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Subscribing a DeadEvent handler is useful for debugging or logging, as it 261d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * can detect misconfigurations in a system's event distribution. 271d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 281d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Cliff Biffle 291d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 10.0 301d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 311d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@Beta 321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic class DeadEvent { 331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert private final Object source; 351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert private final Object event; 361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Creates a new DeadEvent. 391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param source object broadcasting the DeadEvent (generally the 411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@link EventBus}). 421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @param event the event that could not be delivered. 431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public DeadEvent(Object source, Object event) { 451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert this.source = source; 461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert this.event = event; 471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the object that originated this event (<em>not</em> the object that 511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * originated the wrapped event). This is generally an {@link EventBus}. 521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the source of this event. 541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public Object getSource() { 561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return source; 571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Returns the wrapped, 'dead' event, which the system was unable to deliver 611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * to any registered handler. 621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 631d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @return the 'dead' event that could not be delivered. 641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert public Object getEvent() { 661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return event; 671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert} 70