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