LATEST VERSION: 8.2.6 - CHANGELOG
Pivotal GemFire® v8.2

Server Managed Caching Example

Server Managed Caching Example

This example uses the client/server topology to scale an application vertically, with many clients benefitting from centralized server-side data management.

Server-managed caching is the model for independent scalability of data and application tiers. You isolate data management in cache servers and connect to them from application server clients, so many clients benefit from the management resources of the servers.

GemFire's client/server caching gives you dynamic server pool management, server load balancing and conditioning, logical server grouping, and automatic server failover for high availability.

The servers run in one distributed system. Each client runs in its own separate distributed system. The clients forward data requests to the servers that their caches cannot fulfill. The clients also forward client-side updates. Additionally, clients can register interest in server-side data, either by specifying the data keys or by registering queries that run continuously. In both cases, updates on the server side are automatically forwarded to the client.

Running the Example

This example shows a simple client/server installation with one worker client, that gets and puts data in its cache, and one consumer client, that just receives events from the server. Both clients are connected to a single cache server. The worker client requests data from the server. If the server does not have the data cached, it automatically runs a data loader to get it. The server returns the data to the worker client. The worker client then updates the data in its cache. The update is automatically distributed to the server. The server forwards all changes made by the worker client to the consumer client. Both clients have an asynchronous listener that reports local caching activity to standard out, so you can see what is happening.

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.
  1. Change to the <InstallDirectory>/SampleCode/quickstart directory.
  2. In one session, start the cache server (see Running GemFire Server Processes for more information):

    $ gfsh start server --name=server_mc --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.

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

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.ClientConsumer all-keys
  4. When the consumer client asks you to start the worker client, start it in another session:

    $ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.ClientWorker 
  5. Follow the instructions on the screens, noting the listener output from each client. When both clients have exited, stop the cache server:

    $ gfsh stop server --dir=server_mc

Example Source Files

Program and cache configuration files for the clients and the server, including the loader and listener declared in the Server.xml and Client.xml files. (The server is a GemFire cacheserver process and does not have a Java 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

  • com.gemstone.gemfire.cache.client.ClientCacheFactory
  • com.gemstone.gemfire.cache.client.Pool
  • REPLICATE in com.gemstone.gemfire.cache.RegionShortcut
  • CACHING_PROXY in com.gemstone.gemfire.cache.client.ClientRegionShortcut