001package arez.spy;
002
003import java.util.Map;
004import javax.annotation.Nonnull;
005import javax.annotation.Nullable;
006
007/**
008 * Notification when a reaction cycle completes.
009 */
010public final class ReactionCycleCompleteEvent
011  implements SerializableEvent
012{
013  @Nullable
014  private final Throwable _throwable;
015  private final int _duration;
016
017  public ReactionCycleCompleteEvent( @Nullable final Throwable throwable, final int duration )
018  {
019    assert duration >= 0;
020    _throwable = throwable;
021    _duration = duration;
022  }
023
024  @Nullable
025  public Throwable getThrowable()
026  {
027    return _throwable;
028  }
029
030  public int getDuration()
031  {
032    return _duration;
033  }
034
035  @Override
036  public void toMap( @Nonnull final Map<String, Object> map )
037  {
038    map.put( "type", "ReactionCycleComplete" );
039    map.put( "duration", getDuration() );
040    final Throwable throwable = getThrowable();
041    final String message =
042      null == throwable ? null : null == throwable.getMessage() ? throwable.toString() : throwable.getMessage();
043    map.put( "errorMessage", message );
044    SpyEventUtil.maybeAddZone( map );
045  }
046}