PreCache NetInjector Documentation Center : PreCache NetInjector Application Development

Basic Case, Subscription— Java

   







Notification

— accessing the notification's content


When we published the notification, we set a value for a predefined attribute called Message. The subscriber must access this attribute of the channel.

The class definition creating the subscriber already included a reference to the notification:

notify(Notification n,Object closure)

Each matching notification is passed to the application as the first argument of the notify method. n contains the contents of the notification's attributes.

The value of our predefined attribute Message was set to Hello World by the publisher (see Notification, Basic Case, Publication — Java).

getPredefinedAttr retrieves the attribute value stored in the notification. This retrieval occurs within the notify method.

message = n.getPredefinedAttrString(
"Message");

System.out.println(
"Incoming notification for (
" + closure + ")");

The complete subscriber output should read:

Incoming notification for (My First Subscription): Hello World.