concept application event in category griffon

appears as: pplication events, n application event, Application events
Griffon in Action

This is an excerpt from Manning's book Griffon in Action.

Appenders specify where messages are sent or displayed and how they’re formatted. The default configuration specifies a pattern to be used with the console appender. This appender prints to the standard output any message that is logged. You can choose two additional appender presets: file and event. The former saves all messages into a particular file that may grow indefinitely, and the latter pushes application events for every matching logging call. (We cover application events in chapter 8.)

In this chapter you’ll see how to use build events to change and/or extend the build process. Next, you’ll take the information you learned about using events during build time and see how the same idea applies to runtime using application events. Finally, you’ll learn how easy it is to add event publishing to any class using the @EventPublisher annotation.

8.2.3. Firing application events

Recall from earlier in this chapter that you fire a build event by calling event(event-Name, args) on your script. Well, firing an application event is done pretty much the same way; the only difference is that you have to qualify the call using the app variable. As an added benefit, all Griffon applications let you fire application events that don’t require an argument without needing to specify an empty list. This is because the remaining contract on griffon.core.GriffonApplication defines the following methods:

void event(String eventName);
void event(String eventName, List params);
void eventAsync(String eventName);
void eventAsync(String eventName, List params);
void eventOutsideUI(String eventName);
void eventOutsideUI(String eventName, List params);

The first pair of methods generates an event that will notify listeners in the same thread as the publisher—in other words, the event is handled synchronously to the publisher. This is the default way to publish application events, because all of them should be handled immediately after they’ve been posted. But if a listener chooses to handle the event in a different thread, it can use any of the threading facilities we discussed in chapter 7.