LATEST VERSION: 8.0.0 - CHANGELOG
Pivotal GemFire® v8.0

Overview of Application Development with Spring Data GemFire

Overview of Application Development with Spring Data GemFire

In Pivotal GemFire, a common architecture that separates the business logic from the system configuration is the client/server architecture. In this type of system, client application processes are cache clients that produce and consume data while server processes manage the distribution of data among the nodes of the system.

This type of architecture allows for a scalable, highly-available, low latency system where a farm of cache servers provide services to many clients.

For example, consider the basic/replicated-cs code example (See Spring Data GemFire Code Examples.) In this example, the Server.java class and the server/cache-config.xml file define a cache, its associated properties, a cache-server, a replicated region called Customer, and an associated cache listener. When this module is deployed, it defines a server node that can service data requests for the Customer data region.

Note: The cache-config.xml file discussed in this section is a Spring Framework application context XML file that is using the Spring Data GemFire namespace. See Configuring GemFire Components with the Spring Framework.

The server/cache-config.xml file contains the following configurations:

<util:properties id="gemfire-props">
  <prop key="log-level">warning</prop>
</util:properties>
    
<gfe:cache properties-ref="gemfire-props"/>
    
<gfe:cache-server/>
    
<gfe:replicated-region id="Customer">
  <gfe:cache-listener>
     <bean class="org.springframework.data.gemfire.examples.util.LoggingCacheListener"/>
  </gfe:cache-listener>
</gfe:replicated-region>

The Server.java class reserves the fixed port number 4040, and then references the server/cache-config.xml file for configuration:

public class Server {
	 public static void main(String args[]) throws IOException {
		try {
			new ServerPortGenerator().bind(new ServerSocket(), 40404,1);
		} catch (IOException e) {
			System.out.println("Sorry port 40404 is in use. Do you have another cache server process already running?");
			System.exit(1);
			
		}

		new ClassPathXmlApplicationContext("server/cache-config.xml");

		System.out.println("Press <Enter> to terminate the server");
		System.in.read();
		System.exit(0);
	}
}

The client/cache-config.xml configuration file simply defines a datasource for connecting to the server:

	<gfe-data:datasource>
  		<gfe-data:server host="localhost" port="40404"/>
  	</gfe-data:datasource>

The Client.java class uses the configuration file to create an application context and get the Customer region, and then creates and puts new Customer entries in the region:

public class Client {

	@SuppressWarnings("unchecked")
	public static void main(String args[]) throws IOException {
		
		ApplicationContext context = new ClassPathXmlApplicationContext("client/cache-config.xml");
		Region<Long,Customer> region = context.getBean(Region.class);
	
		Customer dave = new Customer(1L,new EmailAddress("dave@matthews.com"),"Dave","Matthews");
		Customer alicia = new Customer(2L,new EmailAddress("alicia@keys.com"),"Alicia","Keys");
		region.put(dave.getId(),dave);
		region.put(alicia.getId(),alicia);
		 
	}
}

For complete documentation of Spring Data GemFire, see the Spring Data GemFire Reference Guide . This guide, Pivotal GemFire User's Guide, provides complete documentation of Pivotal GemFire.