Introduction to the Hello World Example

The Hello World example gives you a simple demonstration of GemFire capabilities.

What This Example Does

This example shows data distribution between two VMware® vFabric™ GemFire® Java applications.
  • Both applications create a GemFire cache with a GemFire data region in it. Data regions hold and manage data entries, written in key/value pairs.
  • The data region in both applications is configured to receive all data written to the region from anywhere in the GemFire system.
  • One application is a producer, writing data to the cache, and the other is a consumer, receiving what the producer writes.
  • Both applications report their caching activities to your screen. The producer reports on its writing activities. Both applications run a listener that reports on events in the application's cache.

Running the Hello World Example

Make sure your environment is configured to run the example.

Procedure
  1. Start two terminal sessions with their environments set up for GemFire and the product examples.
  2. In both sessions, change directory (cd) to the helloworld directory under your examples installation.
  3. In one terminal session, start the Consumer application.

    java helloworld.HelloWorldConsumer
    

    The application starts, creates the cache and region and then asks you to start the producer. 

        This example shows how a distributed region works with replication 
        enabled. I'll create a replicate region, then the producer will 
        create the same region and put entries into it. Because my region 
        is a replicate, all of the producer's puts are automatically 
        pushed into my region.
    
        Connecting to the distributed system and creating the cache.
        Example region, /exampleRegion, created in cache.
    
        Please start the HelloWorldProducer.
    
  4. In the other terminal session, start the Producer application.

    java helloworld.HelloWorldProducer

    The application starts, creates the cache and region, puts data entry key/values pairs into its cache, and then exits.

        Connecting to the distributed system and creating the cache.
        Example region, /exampleRegion, created in cache.
        Putting entry: Hello, World
            Received afterCreate event for entry: Hello, World
        Putting entry: Hello, Moon!
            Received afterUpdate event for entry: Hello, Moon!
    
        Closing the cache and disconnecting.
    
        Please press Enter in the HelloWorldConsumer.
    
    Note: The entry key is "Hello" for both puts, but the value changes. For each entry the producer puts, its listener receives the event and reports to your screen. The first put results in an entry creation. The second put results in an entry update, since the key, "Hello", is already in the cache.
  5. Look at the consumer session.

    Only the producer makes changes to its cache, but because of how the data region is configured, GemFire automatically distributes the changes to the consumer, so both caches receive the same events and end up with the same data in their region.

    Received afterCreate event for entry: Hello, World
    Received afterUpdate event for entry: Hello, Moon!