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 Transaction completes. 010 */ 011public final class TransactionCompleteEvent 012 implements SerializableEvent 013{ 014 @Nonnull 015 private final String _name; 016 private final boolean _mutation; 017 @Nullable 018 private final ObserverInfo _tracker; 019 private final int _duration; 020 021 public TransactionCompleteEvent( @Nonnull final String name, 022 final boolean mutation, 023 @Nullable final ObserverInfo tracker, 024 final int duration ) 025 { 026 assert duration >= 0; 027 _name = Objects.requireNonNull( name ); 028 _mutation = mutation; 029 _tracker = tracker; 030 _duration = duration; 031 } 032 033 @Nonnull 034 public String getName() 035 { 036 return _name; 037 } 038 039 public boolean isMutation() 040 { 041 return _mutation; 042 } 043 044 @Nullable 045 public ObserverInfo getTracker() 046 { 047 return _tracker; 048 } 049 050 public int getDuration() 051 { 052 return _duration; 053 } 054 055 @Override 056 public void toMap( @Nonnull final Map<String, Object> map ) 057 { 058 map.put( "type", "TransactionComplete" ); 059 map.put( "name", getName() ); 060 map.put( "mutation", isMutation() ); 061 final ObserverInfo tracker = getTracker(); 062 map.put( "tracker", null == tracker ? null : tracker.getName() ); 063 map.put( "duration", getDuration() ); 064 } 065}