GemStone® GemFire Enterprise

Client/Server Caching API Example

The clientAPI example demonstrates how to configure your client applications through the GemFire API instead of through the cache.xml. For information on client/server caching, see the GemFire Enterprise Developer's Guide and the online Java documentation under the com.gemstone.gemfire.cache package in subpackages util, client, and server.

The Configuration Files
The distributed system configuration file is used by the locator and cacheserver processes that you will be running.

The cacheserver also uses the server.xml cache configuration file. The client does not use any configuration files.

The Client/Server Processes
The processes used for this example are:

Running the Examples
Follow these instructions to run the configuration examples.

    When you run the examples, if you get a startup failure with a message indicating socket creation failure or that the port is already in use, make sure you are not starting a second copy of the same GemFire process, with the same port configuration. If you are not, then the port specification probably conflicts with some other non-GemFire application. Follow the instructions in Changing the ports used in the examples for the process that is failing to start.

You need two terminal sessions: one to run the locator, cacheserver, and client subscriber, and the other to run the client publisher. For both sessions, make sure the environment is set according to the instructions in examples/EnvSetup.html.

  1. Change directory to examples/dist/clientAPI. The example instructions assume you are starting from that directory.

  2. In one session, start the locator:
  3. gemfire start-locator -port=41111
  4. When that returns, run the cacheserver in the same session:

  5. cacheserver start cache-xml-file=server.xml
  6. When that returns, start the client subscriber in the same session:
  7. java clientAPI.Client subscriber
    The subscriber starts, connects to the server, and reports that it is waiting for the publisher to do its puts.

  8. Start the client publisher in the other session:
  9. java clientAPI.Client publisher

    When the clients finish, both exit automatically.

  10. In the first session, stop the locator and cacheserver:
  11.     cacheserver stop 
        gemfire stop-locator -port=41111
Changing the ports used in the examples
To change the server port, substitute your port number for the port specification in the cache-server configuration in server.xml.

To change the locator port, substitute your port number in these places: