LATEST VERSION: 8.1.0 - CHANGELOG
Pivotal GemFire® v8.1

Interest Registration Example

Interest Registration Example

Client interest registration can give you automatic updates from the server for individual keys, key lists, and all keys matching a regular expression.

This example modifies the Server Managed Caching Example's default interest registration to show explicit key registration and the use of regular expressions.

Running the Example

The default behavior for the Server Managed Caching Example is to register interest in all data in the region.

The example has one worker client, which gets and puts data in its cache, and one consumer client, which receives events from the single cacheserver. The consumer client registers interest in some or all keys in the data region. The worker client updates its cache, and the updates are automatically forwarded to the server cache. The server forwards to the consumer only those events in which the consumer has registered interest. The clients have an asynchronous listener that reports local cache activity to standard out, so you can see what is happening. The server uses a cache loader to load data it does not already have in its cache when the worker client requests it.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment for Running the Examples.
You will run this example twice, once registering interest in a specific set of keys, the second time, registering interest in keys matching a regular expression.
  1. In one session, start the cache server:

    $ gfsh start server --name=server_int_reg --cache-xml-file=xml/Server.xml --classpath="$GEMFIRE/SampleCode/quickstart/classes"

    The gfsh command starts a cache server in the background, displays the status of the server and some environment information, and then exits to the command prompt.

  2. In the same session, start the consumer client:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.ClientConsumer keyset
    
  3. When the consumer client asks you to do so, start the worker client in another session:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.ClientWorker
    
  4. Follow the instructions on the screens, noting the listener output from each client. After both clients exit, stop the cacheserver:

    $ gfsh stop server --dir=server_int_reg
    
  5. To run the example using a regular expression for interest registration, run the example again, replacing "keyset" in the ClientConsumer startup with "regex".

Example Source Files

Program and cache configuration source files for the clients and the server, including the loader and listener declared in the Server.xml and Client.xml files, respectively. (The server is a GemFire cacheserver process and does not have an example source file.)

Table 1. Cache configuration files, located in SampleCode/quickstart/xml
Server.xml Configures a cache to serve caching clients. The example region also is configured with a loader.
Client.xml Configures a region as a client region in a client/server cache. The region's pool connects to the cacheserver.

Table 2. Java program files, located in SampleCode/quickstart/quickstart
ClientWorker.java A client program that exercises the server cache.
ClientConsumer.java A consumer client that registers interest in events on the server. The server sends automatic updates for the events.
SimpleCacheLoader.java A very simple CacheLoader implementation.
SimpleCacheListener.java A CacheListener that reports cache events.

Related Javadocs

See also:
  • com.gemfire.cache.Region.registerInterest