Skip to main content

Process triggered event when other event finishes

1 reply [Last post]
Joined: 2009-05-27


I've got an event calling a menu (displaying it). This menu, however should not be shown before its items have been generated. This generation of items takes some time because it depends on a database connection. One should be allowed to call the menu before its items have been generated but the actual display of the menu should be done as soon as the items are ready.
The problems with trying to display the menu right away only happens during launch time. Once the items have been generated they will remain available.

What would be a good approach to handle this situation? How could one prevent the triggered even from being processed until the item generation is ready?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-05-27

I now took on the approach of creating a custom event listener. The class previously handling the menu display now implements the second event listener interface as well. The class dealing the the menu item retrieval now functions as an event source.
The menu display handler registers itself to this event source and only acts if the menu items are retrieved.

public class ShowMenu implements EventListener, QueryReadyListener {
private boolean menuItemsReady = false;
private List deviceList;

public ShowMenu(DeviceCategory deviceCategory) {
this.deviceList = EntityHandler.INSTANCE.getDevicesByCategory(deviceCategory);

public void handleEvent(Event evt) { // interface implementation of EventListener
if (menuItemsReady) processEvent(evt);

private void processEvent(Event evt) {

public void queryReady(DeviceCategory deviceCategory) { // interface implementation of QueryReadyListener
if (this.deviceCategory == deviceCategory) {
menuItemsReady = true;

It was a bit tricky with the threads handling in the EntityHandler class but it worked out OK.

I figured I might as well post it here in case it's useful for others eventhough I was the one asking the question in the first place. Please let me know if the solution is a big no. Somehow I still don't feel quite comfortable with a chain of listeners like this.

Message was edited by: prodoc