EventHandler

EventHandler EventHandler ( ) (professional and enterprise editions only)

Description

Creates an EventHandler callback object which will be called when the event triggers

Change Log

Version Description
6.0.55a Introduced for pro and enterprise editions.

Examples

Define a handler for the session.addEventCallback to use.

    // 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, AbstractEventData 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;
        }
    };