• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Management Level Event Notifications

Events can be registered for management operations including Cache Clear, Cache Stopped, and Member Joined/Left. Here, we describe how to register and unregister Management Level Event notifications.

Prerequisites

  • .NET
  • Java
  • To learn about the standard prerequisites required to work with all NCache client-side features, please refer to the given page on Client-Side API Prerequisites.
  • Make sure to enable event notifications using the NCache Management Center.
  • For API details, refer to: ICache, CacheItem, MemberJoined, MemberLeft, CacheStopped, CacheCleared.
  • To learn about the standard prerequisites required to work with all NCache client-side features, please refer to the given page on Client-Side API Prerequisites.
  • Make sure to enable event notifications using the NCache Management Center.
  • For API details, refer to: Cache, CacheDataModificationListener, CacheStatusEventListener, getEventType, removeCacheNotificationListener, CacheStatusNotificationType, MemberJoined, removeCacheStatusEventListener, addCacheStatusEventListener, CacheStopped, addCacheClearedListener, removeCacheClearedListener, getNotificationService.

Cache Clear Event

In some cases, the application must get notified when the cache is cleared. For the Cache Clear Event, the user has to implement a method that has the same signature as the CacheClearedCallback. The following method must be implemented in the application to perform the desired processing when the cache-cleared notification is fired.

  • .NET
  • Java
// Precondition: Cache is already connected

// Register cache cleared event
// OnCacheCleared callback will be triggered on cache clear event
cache.NotificationService.CacheCleared += OnCacheCleared;
// Precondition: Cache is already connected

CacheClearedListener clearedListener = new CacheClearedListenerImpl();
// Register cache cleared event

cache.getNotificationService().addCacheClearedListener(clearedListener);
Note

To ensure the operation is fail-safe, it is recommended to handle any potential exceptions within your application, as explained in Handling Failures. To receive the Cache Clear event, the following line of code must be incorporated into the application:

  • .NET
  • Java
// Perform the tasks after getting the cache clear event
Console.WriteLine("Cache has been cleared.");
System.out.println("Cache has been cleared..");

If you do not want to receive any notifications for the cache clear event, add the following line in your application:

  • .NET
  • Java
// Precondition: Cache is already connected

// UnRegister cache cleared event
cache.NotificationService.CacheCleared -= OnCacheCleared;
// Precondition: Cache is already connected

// UnRegister cache cleared event
cache.getNotificationService().removeCacheClearedListener(clearedListener);

Cache Stopped Event

Similar to the Cache Clear Event, you can also receive notifications when the cache is stopped. The following method must be implemented in the application to perform processing when the Cache Stopped is fired.

  • .NET
  • Java
// Precondition: Cache is already connected

// Register cache stopped event
// OnCacheStopped callback will be triggered when cache is stopped
cache.NotificationService.CacheStopped += OnCacheStopped;
// Precondition: Cache is already connected

CacheStatusEventListener stoppedListener = new CacheStatusEventListenerImpl();
EnumSet<CacheStatusNotificationType> statusNotificationTypes = EnumSet.of(CacheStatusNotificationType.CacheStopped);

// Register cache stopped event
cache.getNotificationService().addCacheStatusEventListener(stoppedListener, statusNotificationTypes);
System.out.println("Registered for cache stopped notifications.");

To receive the cache stopped event, the following line of code must be incorporated into the application:

  • .NET
  • Java
// Perform the tasks after getting the cache stopped event
Console.WriteLine($"'{cacheName}' has been stopped.");
// Perform the tasks after getting the cache stopped event
System.out.println("'" + cacheName + "' has been stopped.");

If you do not want to receive any notifications for cache stopped events, add the following line in your application:

  • .NET
  • Java
// Precondition: Cache is already connected

// UnRegister cache stopped event
cache.NotificationService.CacheStopped -= OnCacheStopped;
// Precondition: Cache is already connected

// UnRegister cache stopped event
cache.getNotificationService().removeCacheStatusEventListener(stoppedListener, statusNotificationTypes);

Member Joined Event

The user can also get notified, whenever a member joins a cluster. The following method must be implemented in the application to perform processing when a member joins a cluster.

  • .NET
  • Java
// Perform task after Member Joined event gets fired
Console.WriteLine($"Node with IP:{nodeInfo.IpAddress} has joined the cluster.");
System.out.println("Node with IP:" + nodeInfo.getIpAddress() + " has joined the cluster.");

To receive the Member Joined Event, the following line of code must be incorporated into the application:

  • .NET
  • Java
// Precondition: Cache is already connected

// Register memebr join event
// OnMemeberJoined callback will be triggered when a new member joins cache
cache.NotificationService.MemberJoined += OnMemberJoined;
// Precondition: Cache is already connected

CacheStatusEventListener memberJoinedListener = new CacheStatusEventListenerImpl();
EnumSet<CacheStatusNotificationType> statusNotificationTypes = EnumSet.of(CacheStatusNotificationType.MemberJoined);

// Register member joined event

cache.getNotificationService().addCacheStatusEventListener(memberJoinedListener, statusNotificationTypes);
System.out.println("Registered for member joined notifications.");

If you do not want to receive any notifications for Member Joined Events, add the following line to your application:

  • .NET
  • Java
// Precondition: Cache is already connected

// UnRegister member join event
cache.NotificationService.MemberJoined -= OnMemberJoined;
// Precondition: Cache is already connected

// UnRegister member join event
cache.getNotificationService().removeCacheStatusEventListener(memberJoinedListener, statusNotificationTypes);

Member Left Event

The user can get notified whenever a member leaves a cluster. The following method must be implemented in the application to perform processing when a member leaves a cluster.

  • .NET
  • Java
// Precondition: Cache is already connected

// Register memebr left event
// OnMemeberleft callback will be triggered when a member leaves cache
cache.NotificationService.MemberLeft += OnMemberLeft;
// Precondition: Cache is already connected

CacheStatusEventListener memberLeftListener = new CacheStatusEventListenerImpl();
EnumSet<CacheStatusNotificationType> statusNotificationTypes = EnumSet.of(CacheStatusNotificationType.ALL);

// Register member left event

cache.getNotificationService().addCacheStatusEventListener(memberLeftListener, statusNotificationTypes);
System.out.println("Registered for member left notifications.");

To receive the Member Left event, the following line of code must be incorporated into the application:

  • .NET
  • Java
// Perform task after Member Left event gets fired
Console.WriteLine($"Node with IP:{nodeInfo.IpAddress} has left the cluster.");
// Perform task after Member Left event gets fired
System.out.println("Node with IP:" + nodeInfo.getIpAddress() + " has left the cluster.");

If you do not want to receive any notifications for Member Left Events, add the following line in your application:

  • .NET
  • Java
// Precondition: Cache is already connected

// UnRegister memeber left event
cache.NotificationService.MemberLeft -= OnMemberLeft;
// Precondition: Cache is already connected

// UnRegister member left event.
cache.getNotificationService().removeCacheStatusEventListener(memberLeftListener, statusNotificationTypes);

Additional Resources

NCache provides a sample application for Management Level Event Notifications on GitHub.

See Also

.NET: Alachisoft.NCache.Runtime.Events namespace.
Java: com.alachisoft.ncache.events namespace.

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top