Summary: Advance events scenarios
OverviewWhile in most cases, using the DefaultDataEventSession as desribed in the Space Events page is enough to get the job done, in some cases it is not enough. For instance if you want a mechanism that detects that an event listener is no longer active due to space failure, or to make sure that if the client proxy terminates unexpectedly, the listener resources are cleaned up in the space. All of these, and more, are covered in this page. Event Mechanism in GeneralEvent registration is done using a supplied template, and a callback method. The registration notify template can be stored in one or more spaces, depending on the template and cluster topology. Every time an event occurs in a space, which matches the given template and event type in that space, the event is triggered at the proxy, which activates the callback method. What happens if the space or the proxy is no longer available? What happens if the proxy can't manage the events overload? These issues can be addressed by customizing a data event session, with appropriate behaviors to handle these issues. Customizing DataEventSession BehaviorIn order to customize the behavior of an IDataEventSession, a new one needs to be created, using a specific DataEventConfig that configures the behavior. This section describes different scenarios, and how to address them, by customizing the data event session EventSessionConfig eventSessionConfig = new EventSessionConfig(); //Customize the eventSessionConfig ... //Create a customized data event session IDataEventSession dataEventSession = proxy.CreateDataEventSession(eventSessionConfig); Detecting an Event Listener Failure/DisconnectionAn event listener that is registered for an event might be disconnected for the following reasons:
In order to detect and handle listener disconnection, the auto renewal mechanism can be used. When adding a new listener, one of the parameters is the leaseTime. A leaseTime is a concept that appears in many places in the API. The idea behind it, is that it allows you to specify how long to keep the object alive in the space. In a listener context, it means how long the event registration should remain active (in milliseconds). By default, the lease time is forever (Long.MaxValue). The auto renewal idea is that the listener is added with a limited lease, for example 10 seconds, and the proxy automatically renews the lease before it expires. The client can register to the EventSessionConfig.AutoRenewalFailed event, and be notified if the auto renewal failed. This approach solves the following issues:
Configuring data event session with auto renewal EventSessionConfig eventSessionConfig = new EventSessionConfig(); eventSessionConfig.AutoRenew = true; The auto renewal process uses a few parameters that dictate the timing of its behavior. These values have proper defaults, but can be altered, for example: //Auto renewal is active for 1 minute eventSessionConfig.AutoRenewTotalDuration = 60000; //Each time renew the lease for 10 seconds eventSessionConfig.AutoRenewLeaseDuration = 10000; //The network latency can reach 5 seconds, send renewal request 5 seconds before the lease expires. eventSessionConfig.AutoRenewRTT = 5000; Managing High Notifications ThroughputWhen a notification is sent from the space to the client, the callback method is executed inside a thread that belongs to the resource pool of the proxy. As a result, this thread is occupied until the callback method returns. As a good practice, it is recommended to create the callback method that returns as fast as possible, otherwise the resources pool of the proxy can be choked, and cause a slow consumer scenario. If the notifications should trigger a long running job, it is better to put this job in a queue, and handle it in a client thread later on. It is possible to reduce network traffic, and concurrent threads that handle notifications, by using the batch notification mechanism. Instead of sending each notification separately, notifications are grouped together in the space, and sent as one batch. Configuring data event session with batch notifications The batch notification is sent when either one of these two parameters has been reached or exceeded. Either the pending notification size has reached the BatchSize, or the time, in milliseconds, that elapsed from the last sent notification batch, exceeds BatchTime. EventSessionConfig eventSessionConfig = new EventSessionConfig(); eventSessionConfig.Batch = true; //Send notifications when the batch size reached 100 eventSessionConfig.BatchSize = 100; //Send notifications at maximum every 1 seconds. eventSessionConfig.BatchTime = 1000; |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |