001package arez.spy; 002 003import java.util.Map; 004import java.util.Objects; 005import javax.annotation.Nonnull; 006import javax.annotation.Nullable; 007 008/** 009 * Notification that task has completed execution. 010 */ 011public final class TaskCompleteEvent 012 implements SerializableEvent 013{ 014 @Nonnull 015 private final TaskInfo _task; 016 @Nullable 017 private final Throwable _throwable; 018 private final int _duration; 019 020 public TaskCompleteEvent( @Nonnull final TaskInfo task, 021 @Nullable final Throwable throwable, 022 final int duration ) 023 { 024 assert duration >= 0; 025 _task = Objects.requireNonNull( task ); 026 _throwable = throwable; 027 _duration = duration; 028 } 029 030 @Nonnull 031 public TaskInfo getTask() 032 { 033 return _task; 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", "TaskComplete" ); 051 map.put( "name", getTask().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}