I don't like that this returns a SparkListenerEvents object. The user will have to do instanceOf on it, or try to match it with other types. Instead, change the events so that there's only one SparkListenerJobEnded event, and inside, it contains some kind of status, which is either SUCCESS, FAILED or CANCELLED, as well as optional fields for the reasons why it failed.