General Use

// Import the general event handler classes
import com.screenscraper.events.*;

// Import the classes dealing with the events times you want to use
import com.screenscraper.events.session.*;
import com.screenscraper.events.scrapeablefile.*;
import com.screenscraper.events.script.*;
import com.screenscraper.events.extractor.*;
// Misc is random stuff that can be called from multiple locations
// and therefore didn't fit elsewhere
import com.screenscraper.events.misc.*;

// Create an EventHandler object which will be called when the event triggers
EventHandler handler = new EventHandler()
{
    /**
     * Returns the name of the handler.  This method doens't need to be implemented
     * but helps with debugging (on error executing the callback it will output this)
     */

    public String getHandlerName()
    {
        return "A test event handler";
    }

    /**
     * Processes the event, and potentially returns a useful value modifying something
     * in the internal code
     *
     * @param fireTime The fire time of the event. This helps when using the same handler
     * for multiple event times, to determine which was called
     * @param data The actual data from the event. Based on the event time this
     * will be a different type. It could be SessionEventData, ScrapeableFileEventData,
     * ScriptEventData, StringEventData, etc...  It will match the fire time class name
     *
     * @return A value indicating how to proceed (or sometimes the value is ignored)
     */

    public Object handleEvent(EventFireTime fireTime, SessionEventData data)
    {
        // While you can specifically grab any data from the data object,
        // if this is a method that has a return value that matters,
        // it's best to get it as the last return value, so that multiple
        // events can be chained together.  The input data object
        // will always have the original values for all the other getters
        Object returnValue = data.getLastReturnValue();

        // Do stuff...

        // The EventFireTime values describe in the documentation what the return
        // value will do, or says nothing about it if the value is ignored
        // If you don't intend to modify the return, always return data.getLastReturnValue();
        return returnValue;
    }
};

// Set the event to be fired at a specific time
session.addEventCallback(SessionEventFireTime.AfterEndScripts, handler);