Database Reference
In-Depth Information
Notifications for the Redis Client
Adding pubsub notifications to the Redis client from the last section is
easy. First, the Aggregator class needs a way of calling the
notification event. This is done through the Notifier interface:
public interface Notifier {
public void notify( String key, String resolution,
long timestamp,long quantized, String
quantizedString);
}
This is called after every update in the each method. The following
code optionally notifies a channel when available:
if (notifier != null ) {
notifier.notify(key,a. resolutionString (),timestamp,
quantized,quantizedString);
}
The Redis client then publishes the update to the appropriate channel
so data consumers can be updated. In this case, the resolution of the
update is included in the channel so consumers can subscribe to the
appropriate level of detail:
public void notify( String key, String resolution,
long timestamp,
long quantized, String quantizedString) {
jedis.publish(key+":"+resolution, quantizedString);
}
If a real-time data source is not available in the development environment,
another option is to simulate the flow of real-time data using a simple
JavaScript driver to send “real-time” events. This driver emits messages
every second with a sine wave for testing visualization methods described in
the remainder of this section:
Search WWH ::




Custom Search