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