The publishing of messages can be handled by the global service component /atg/portal/alert/GearMessagePublisher, which handles the creation, initialization, and publishing of JMS messages. GearMessagePublisher exposes a method called writeMessage() that takes an object as its argument. This can be any Serializable Java object.

The following example illustrates how you might make GearMessagePublisher available within a gear’s form handler. This corresponds to Step 3 of Adding Custom Alert Messages to Gears above.

InitialContext ctx = new javax.naming.InitialContext();
mPublisher = (GearMessagePublisher) ctx.lookup(getPublisherName());

In the above example, the getPublisherName method (a method you must provide) returns the property equal to "dynamo:/atg/portal/alert/GearMessagePublisher" (the "dynamo:" protocol signifies that the component is a Nucleus component.)

Note that if you are using a Nucleus component as a form handler, you can also make the gear publisher available as a property, and use the component’s .properties file to set that property to link to /atg/portal/alert/GearMessagePublisher.

Also note that repeatedly making a JNDI lookup using InitialContext() can impede performance. Consequently, you may want to create the InitialContext once and then always reference that instance. It would also make sense to cache the result of the lookup. PAF provides a utility class, atg.portal.nucleus.NucleusComponents, which does this. The following is an example of how the NucleusComponents class can be used:

mPublisher = (GearMessagePublisher)
NucleusComponents.lookup(getPublisherName());
 
loading table of contents...