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