001package arez.spy; 002 003import arez.ObserverError; 004import java.util.Map; 005import java.util.Objects; 006import javax.annotation.Nonnull; 007import javax.annotation.Nullable; 008 009/** 010 * Notification when Observer produces an error. 011 */ 012public final class ObserverErrorEvent 013 implements SerializableEvent 014{ 015 @Nonnull 016 private final ObserverInfo _observer; 017 @Nonnull 018 private final ObserverError _error; 019 @Nullable 020 private final Throwable _throwable; 021 022 public ObserverErrorEvent( @Nonnull final ObserverInfo observer, 023 @Nonnull final ObserverError error, 024 @Nullable final Throwable throwable ) 025 { 026 _observer = Objects.requireNonNull( observer ); 027 _error = Objects.requireNonNull( error ); 028 _throwable = throwable; 029 } 030 031 @Nonnull 032 public ObserverInfo getObserver() 033 { 034 return _observer; 035 } 036 037 @Nonnull 038 public ObserverError getError() 039 { 040 return _error; 041 } 042 043 @Nullable 044 public Throwable getThrowable() 045 { 046 return _throwable; 047 } 048 049 @Override 050 public void toMap( @Nonnull final Map<String, Object> map ) 051 { 052 map.put( "type", "ObserverError" ); 053 map.put( "name", getObserver().getName() ); 054 map.put( "errorType", getError().name() ); 055 final Throwable throwable = getThrowable(); 056 final String message = 057 null == throwable ? null : null == throwable.getMessage() ? throwable.toString() : throwable.getMessage(); 058 map.put( "message", message ); 059 } 060}