Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Grid Events
Grid Events
Added by architect, last edited by dozer on Dec 17, 2008  (view change)
Labels: 
(None)


Description

Each grid node stores all events that have happened on this node locally. It is important to understand that when a grid task is executing it may travel the grid and events for this task's execution can be scattered around the grid. GridGain provides an API to query the grid in a distributed fashion for such events.

Local Events

Unlike remote events, local events can be listened to asynchronously by registering a listener via Grid.addLocalEventListener(GridLocalEventListener) Javadoc method. Local events can also be queried using Grid.queryLocalEvents(GridEventFilter) Javadoc method.

Remote Events

To avoid network of constantly exchanging events between nodes, grid stores all grid events locally. Whenever it is needed to find out what events took place on remote nodes, remote events can be queried using Grid.queryEvents(GridEventFilter, Collection<GridNode>, long) Javadoc method. This operation is distributed and hence can fail on communication layer and generally should take longer than local event notifications.

Here is an example of an GridEventFilter Javadoc that can be used to find out how many times task execution was started on remote nodes. Note that this filter will be passed to remote nodes and, hence, needs to be java.io.Serializable.

private static class EventFilter implements GridEventFilter {
    /** Serial version UID. */
    private static final long serialVersionUID = 5982379841291591385L;

    /**
     * @see GridEventFilter#accept(GridEvent)
     */
    public boolean accept(GridEvent evt) {
        // Accept only TASK_STARTED events.
        return evt.getType() == GridEventType.TASK_STARTED;
    }
}
Starting with version 2.1 peer-class-loading is enabled for event filters. You can simply call Grid.queryEvents(GridEventFilter, Collection<GridNode>, long) Javadoc method and your event filter will be automatically loaded and executed on all remote nodes. You no longer need to manually add it to the class path on all remote nodes.

Event Storage SPI

As almost all kernel level functionality in GridGain the functionality of storing and querying events locally is designed as event storage SPI (Service Provider Interface). It consists of the public API and one or more implementations. Event storing happens automatically inside of the GridGain and querying functionality is exposed as user-level API:

Event Storage SPI

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators