001package com.identityworksllc.iiq.common;
002
003import sailpoint.tools.GeneralException;
004
005import java.io.Serializable;
006
007/**
008 * A generic task callback that can be used in various contexts. A subclass
009 * can provide hooks for any part of the task process.
010 *
011 * @param <T> The type of the task object
012 * @param <O> The type of the output object
013 */
014public abstract class TaskCallback<T, O> implements Serializable {
015    /**
016     * Invoked in a 'finally' after the task completes, but before it returns
017     * to the orchestrator
018     *
019     * @param task The task object
020     */
021    public void afterFinish(T task) {
022        /* Nothing by default */
023    }
024
025    /**
026     * Invoked prior to the start of the task
027     * @param task The task that is about to start
028     * @throws GeneralException on failures; aborts the task
029     */
030    public void beforeStart(T task) throws GeneralException {
031        /* Nothing by default */
032    }
033
034    /**
035     * Invoked after the task has failed
036     *
037     * @param task The task that has failed
038     * @param failureMessage A failure message (possibly null)
039     * @param exception The exception that caused the failure
040     */
041    public void onFailure(T task, String failureMessage, Exception exception) {
042        /* Nothing by default */
043    }
044
045    /**
046     * Invoked after the task has completed
047     *
048     * @param task The task
049     * @param output The output
050     */
051    public void onSuccess(T task, O output) {
052        /* Nothing by default */
053    }
054}