Chapter 20. Expresso Event System

Table of Contents

Introduction
Event Conditions: Success or Unsuccessful
Message Content
Event Configuration
Triggering an event from code
EMail Integration
Event notifications
User Notifications
Login Verification
Attachments
Conclusion
Contributors

Note

If you find this EDG documentation helpful please consider DONATING! to keep the doc alive and current.

 Maintainer:David Lloyd

Expresso Event Notification is a subsystem that handles letting key users know when important events are completed, or when problems have occured. Utilizing the standard JavaMail API and the Java Activation Framework, Expresso provides easy access from your application to email.

Introduction

The event-driven processing feature allows any system event (e.g. the publication of a report, a system error, a server being restarted) to trigger email notifications to be sent to a specified list of users (both local and remote (internet)). Any message or attachment can be included with the notification, and an event can be set to trigger other events if required (e.g. a data load might trigger a report to be run). The list of messages and users to be notified is maintained in a series of database tables. When a server-side task, such as loading data into a data warehouse, is completed, it triggers an event with a specific code. The event is then broadcast to a list of specified users that are subscribed to receive the event.

The goal of the Expresso event system is to send email messages to a specified number of people when a specified event occurs. The configuration of the Event system is done through database tables, while the triggering of an Event can take place in one line of code. Events are always asynchronous, and depending on how the system administrator sets up the website, when events are triggered, it is possible that nothing will happen.

An example of an event is a system error - this is a pre-defined event that comes with the system. This event can then have a list of users associated with it that get notified when the event occurs, in the case of a system error, you would probably want to notify your system administrator.

The developer then simply has to specify that an event is triggered and the appropriate notifications are sent out automatically by the system.

Event Conditions: Success or Unsuccessful

Every event is either "successful" (such as a load completing correctly) or "unsuccessful" (such as a load aborting due to a database problem). Successful events can have a different group of users from unsuccessful events - for example, a number of people might want to know that the data load is completed, but you might want to tell the system administrator only if the load fails. Of course, the same people can also be notified of both success and failure if so desired.

Message Content

The event e-mail contains a message from the server-side object, which can give details about the event (for example, how many records got loaded, or what the exact error message from the database was in the case of a failure).

Event Configuration

The Event configuration tables can be reached through the Operations page from the main Expresso frame. The two tables are:

  • Event Definitions - This table contains a list of all defined events. An example of a defined Event is SYS_ERROR

  • Event Email Recipients - This table contains data on who to send email notices to when a particular event triggers

Event Definitions and Event Email Recipients are connected with a Master/Detail relationship.

The Event Definitions table is fairly straight forward. The two fields are event name and event description. A pre-built example is SYSERROR which has the description of "System Error." The name SYSERROR is the name of the event that gets triggered in code as will be demonstrated shortly.

The Event Email Recipients contains the rest of the Event configuration information. When adding a new recipient, you decide on who to send the notification to, what event, and why. For SYSERROR, for example, you could select "System Error." from the dropdown box for Event code, and 3 for the user ID (Usually Administrator).

Now the last part of the Event Email Recipient is a little bit different. Each Event has a status associated with it: Success or Failure. For example, if a user successfully downloaded a file, the download controller could trigger a DOWNLOAD event with a success status, whereas if the connection died for some reason, the download controller could trigger a DOWNLOAD event with failure status. Each of these statuses is configurable with who gets what notifications. For example, you could send a DOWNLOAD success event to an automated mail archival system for statistical reference, while you would want to send failure events to the administrators so they can see if there are an unusual number of failures occurring.

Triggering an event from code

You can trigger an event from code with very little code:

import
  com.jcorporate.expresso.core.misc.EventHandler;
  EventHandler.Event("default", "SYSERROR","Successful
  Test Message", true);

EventHandler.Event is an asynchronous call. If you watch the runtime logs, you will see the mail going out a few seconds after the call. The parameters for the call are:

  1. The data context (or db name) in this case default

  2. The name of the event to fire as defined in the Event Definitions Table

  3. The message to dispatch when the event is fired. This will be the text of the email message that the Event dispatches.

  4. The final parameter is set to true if this is a 'success' message, and false if it is a 'failure' message.

EMail Integration

The framework has email integration as part of its base feature set. Instead of the application programmer having to develop his/her own email notification system, there is a base level email integration built right in. From that base email class, there are several different classes that make use of the email notification class.

Some facilities provided for email include:

  • Event notifications: Discussed above, Expresso's event notification mechanism uses email by default to inform users when specific events, including system errors, occur.

  • User notifications: The ability to send email to particular users.

  • Login Verification: An optional portion of the registration process allows users to be emailed in order to verify their email address before authorizing their account for login, assuring your user data is up-to-date.

  • Attachments: An easy mechanism is provided to attach one or more files to any email being sent to a user, the contents of which can be created by your custom application.

Event notifications

The Job class, a class to provide cron or batch like functions, has a mechanism for emailing certain parties that can be customized to alert the certain recipients when the job has started, when the job has finished, and/or when the job encounters in error.

User Notifications

There are times that an email needs to be sent to particular users and to those users explicitly. The EventHandler and UserInfo objects can work together to send an email to the user. An example of this is in com.jcorporate.eforum.dbobj.ForumMessage where it sends an email to everyone subscribed to get email in a forum.

EventHandler.notify(dataContext, // the database context
  tSubscribe.getFieldInt(ThreadSubscribe.FLD_UID), // the user id to send
  email to msgSubject, // the email subject message); // the email message

Login Verification

The User, DefaultUserInfo, and UserLDAP classes, which handles the registration and manipulation of users within the Expresso framework, has an email conduit already setup. This email conduit allows verification of the user, deterring spammers from registering, and keeping the database up-to-date.

Attachments

The User and DefaultUserInfo classes also have an email attachment feature. This makes it easy to attach one or more attachments to any email being sent to a user. As with most features in Expresso, this can be customized to the specific application that is being developed.

Conclusion

Contributors

The following persons have contributed their time to this chapter:

Note

Was this EDG documentation helpful? Do you wish to express your appreciation for the time expended over years developing the EDG doc? We now accept and appreciate monetary donations. Your support will keep the EDG doc alive and current. Please click the Donate button and enter ANY amount you think the EDG doc is worth. In appreciation of a $35+ donation, we'll give you a subscription service by emailing you notifications of doc updates; and donations $75+ will also receive an Expresso T-shirt. All online donation forms are SSL secured and payment can be made via Credit Card or your Paypal account. Thank you in advance.

Copyright © 2001-2004 Jcorporate Ltd. All rights reserved.