NCache provides the ability to generate custom notifications. A producer application can call a single method that invokes handlers on all the subscribers of the custom notification event. In a clustered environment, custom notifications are convenient means of communication among the participants of the cluster. Even in local environment, a producer consumer style communication between applications is easily achieved using this facility.
Using custom notifications is a two step process. One is a producer end of the notification and other is a consumer end.
-
To register we simply implement an interface CustomListener on a class:
import com.alachisoft.ncache.event.*;
public class CacheEventListner implements CustomListener
{
public void customEventOccured(CustomEvent event)
{
System.out.println("Custom EVENT :- Custom event is raised for Key[ " + event.getKey() + " ] with value: " + event.getSource().toString());
}
}
-
The custom notification is simply raised by calling:
CacheEventListner();
Cache _cache = NCache.initializeCache("myCache");
_cache.addCustomEventListener(onItemUpdated);
_cache.raiseCustomEvent("custom-Object", "Custom.Event");
_cache.unRegisterCustomNotification();
_cache.removeCustomEventListener(onItemUpdated);;
See Also