Avis Example

This page contains a simple example scenario using Avis to illustrate how it operates.

In this example we imagine a scenario where we have a large number of servers in several company departments that we wish to monitor. We install a small Elvin client on each host we want to monitor that runs the code below every minute:1

The diagram below is an overview of the example scenario. We'll expand on what this means in the following sections.

Example overview diagram


The code below runs on each host we wish to monitor. It puts a message on the Elvin bus tagged with the message type and version.2 The messages describe the host's name, department and percentage of free disk space.

Elvin elvin = new Elvin ("elvin://elvin_router");
Notification ntfn = new Notification ();

ntfn.set ("Status-Message", 1000);
ntfn.set ("Host-Name", hostName ());
ntfn.set ("Department",  lookupDepartment ());
ntfn.set ("Percent-Disk-Free", diskFreePercentage ());

elvin.send (ntfn);

elvin.close ();


Once we have hosts emitting status messages, we might add a logging client somewhere in the control centre that stores them in a central rotating log file. The code below does this by listening for any status message.

Elvin elvin = new Elvin ("elvin://elvin_router");

// Listen for any version 1.x status message 
Subscription statusSub =
  elvin.subscribe ("Status-Message < 2000");

statusSub.addListener (new NotificationListener ()
  public void notificationReceived (NotificationEvent e)
    addLog (e.notification.getString ("Host-Name"),
            e.notification.getInt ("Percent-Disk-Free"));



Perhaps later on we decide we need to be alerted if any of the servers in in the "IT" department get too low on disk space.

Elvin elvin = new Elvin ("elvin://elvin_router");

// Listen for status messages in the IT
// department where disk space is 10% or less

Subscription alertSub =
    ("Status-Message < 2000 && " +
     "Department == 'IT' && " +
     "Percent-Disk-Free <= 10");

alertSub.addListener (new NotificationListener ()
  public void notificationReceived (NotificationEvent e)
    alert ("Host %s has low disk space (%i percent)",
           e.notification.get ("Host-Name"),
           e.notification.get ("Percent-Disk-Free"));

The alert () routine called by the subscription handler above might do something like flash the message on a big display, send an email or SMS. In fact alert () might be better off emittng another kind of "alert" Elvin notification that is handled by several listening services that could do any of the above.

One useful example of a service that reacts to alerts would be one that emits a text message in the tickertape instant messaging format. This format can be displayed by a number of ticker clients, either on a big display or on an administrator's desktop.

More Information

One widely deployed public use of Elvin has been as a wide-area instant messaging and presence network. This network was initiated by the Elvin project at DSTC as an inter-organisation communication aid and has continued to be maintained since DSTC's closure.

One client for this network is the Sticker tickertape messaging client. Sticker can be both a useful testing client for Avis and a real world example of using Elvin messaging. The source code for Sticker is available at the tickertape.org downloads page.

  1. The source code examples on this page are written using the Avis Java client library for Elvin. Please see the client library page for more details.

  2. A tag value of 1000 == version 1.0, 1001 == 1.1, 2000 == 2.0 etc. This kind of versioning can be very useful for long-lived formats allowing you to have several versions in use on the bus without interfering with each other.