001/* 002 * Copyright (C) 2013 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 com.google.common.eventbus; 016 017import static com.google.common.base.Preconditions.checkNotNull; 018 019import java.lang.reflect.Method; 020 021/** 022 * Context for an exception thrown by a subscriber. 023 * 024 * @since 16.0 025 */ 026public class SubscriberExceptionContext { 027 private final EventBus eventBus; 028 private final Object event; 029 private final Object subscriber; 030 private final Method subscriberMethod; 031 032 /** 033 * @param eventBus The {@link EventBus} that handled the event and the subscriber. Useful for 034 * broadcasting a new event based on the error. 035 * @param event The event object that caused the subscriber to throw. 036 * @param subscriber The source subscriber context. 037 * @param subscriberMethod the subscribed method. 038 */ 039 SubscriberExceptionContext( 040 EventBus eventBus, Object event, Object subscriber, Method subscriberMethod) { 041 this.eventBus = checkNotNull(eventBus); 042 this.event = checkNotNull(event); 043 this.subscriber = checkNotNull(subscriber); 044 this.subscriberMethod = checkNotNull(subscriberMethod); 045 } 046 047 /** 048 * @return The {@link EventBus} that handled the event and the subscriber. Useful for broadcasting 049 * a new event based on the error. 050 */ 051 public EventBus getEventBus() { 052 return eventBus; 053 } 054 055 /** @return The event object that caused the subscriber to throw. */ 056 public Object getEvent() { 057 return event; 058 } 059 060 /** @return The object context that the subscriber was called on. */ 061 public Object getSubscriber() { 062 return subscriber; 063 } 064 065 /** @return The subscribed method that threw the exception. */ 066 public Method getSubscriberMethod() { 067 return subscriberMethod; 068 } 069}