Pivotal GemFire® v8.0

Configuring a Client/Server Architecture

Configuring a Client/Server Architecture

To use the GemFire client/server architecture, you configure both cache servers and client caches.

Cache servers operate in a peer-to-peer relationship with other cache servers. Multiple client processes can connect to cache servers to retrieve and update data. Clients connect using connection pools.

The following Spring application context XML configuration (from the basic/partitioned example) declares a cache server (using a separate class to generate the server port number):
		<gfe:cache-server port="#{portGenerator.generatePort(40404,40406)}" />

		<bean id="portGenerator"
			class="" />
The server's Java class (from the basic/partitioned example) references the Spring application context XML configuration file to create the server:
public class Server {
	private static Log log = LogFactory.getLog(Server.class);
	 public static void main(String args[]) throws IOException {

		ApplicationContext context = new ClassPathXmlApplicationContext("server/cache-config.xml");
		CacheServer server = context.getBean(CacheServer.class);
		System.out.println("server running on port " + server.getPort());
		System.out.println("Press <Enter> to terminate the server");;

You configure a GemFire client cache to access data from a cache server. In this type of architecture, many clients can connect to a smaller number of cache servers. The clients can use connection pools to connect to the servers.

The following Spring application context XML configuration (from the basic/partitioned example) creates a client cache, region, and connection pool:
    <gfe:client-cache properties-ref="gemfire-props"/>
    <gfe:client-region id="Order" data-policy="empty"/>
    	<gfe:server host="localhost" port="40404"/>
    	<gfe:server host="localhost" port="40405"/>
    	<gfe:server host="localhost" port="40406"/>
The client's Java code (from the basic/partitioned example) uses the client cache to update data:
public class Client {
	private static Log log = LogFactory.getLog(Client.class);
	private static boolean partitionByCountry;
	public static void main(String args[]) throws IOException {
		 if (args.length >= 1 && args[0].equalsIgnoreCase("partitionByCountry")) {
				log.debug("partitioning by country");
				partitionByCountry = true;
		ApplicationContext context = new ClassPathXmlApplicationContext("client/cache-config.xml");
		Region<OrderKey,Order> region = context.getBean(Region.class);

		//Create some orders
		Random rand = new Random(new Date().getTime()); 
		for (long orderId = 1; orderId <= 100; orderId++) {
			Address shipTo = new Address("Some Street","Some City",(orderId%3 == 0)?"UK":"US"); 
			Order order = new Order(orderId, (new Long(rand.nextInt(100)+1)),shipTo);
			OrderKey orderKey = getOrderKey(orderId,shipTo.getCountry());
			region.put(orderKey, order);