Friday, 26 September 2014

Pivotal GemFire 8 - Starting a Locator / Server directly from IntelliJ 13.x

With the introduction of Pivotal GemFire 8 developers can easily incorporate starting/stopping GemFire Locators/Servers directly within Java code allowing them to easily integrate GemFire  management within their IDE. This ensures developers can develop/test/run GemFire applications all within their IDE of choice making them much more productive using very simple Launcher API's

The locator is a Pivotal GemFire process that tells new, connecting members where running members are located and provides load balancing for server use. A GemFire server is a Pivotal GemFire process that runs as a long-lived, configurable member of a distributed system. The GemFire server is used primarily for hosting long-lived data regions and for running standard GemFire processes such as the server in a client/server configuration.

In this post I am going to show how we can use the following classes to launch a Pivotal GemFire  locator / server from code directly within IntelliJ IDEA allowing you to develop/test GemFire applications directly from your IDE of choice.

Note: In this post we use Intellij IDEA 13.x

com.gemstone.gemfire.distributed.LocatorLauncher API
com.gemstone.gemfire.distributed.ServerLauncher API

1. Add the GemFire 8 maven REPO to your project to ensure we pull the required JAR files.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""




            <name>GemStone Maven RELEASE Repository</name>

2. Create a class as follows to start a locator
package pivotal.gemfire.compression;

import com.gemstone.gemfire.distributed.LocatorLauncher;

import java.util.concurrent.TimeUnit;

public class StartLocator
    public static void main(String[] args)
        LocatorLauncher locatorLauncher  = new LocatorLauncher.Builder()
                .set("jmx-manager", "true")
                .set("jmx-manager-start", "true")
                .set("jmx-manager-http-port", "8083")
                .set("jmx-manager-ssl", "false")

        System.out.println("Attempting to start Locator");


        locatorLauncher.waitOnStatusResponse(30, 5, TimeUnit.SECONDS);

        System.out.println("Locator successfully started");


3. Create a class as follow to start a single cache server, could create as many iof these as you need
package pivotal.gemfire.compression;

import com.gemstone.gemfire.distributed.ServerLauncher;

public class StartMember
    public static void main(String[] args){
        ServerLauncher serverLauncher  = new ServerLauncher.Builder()
                .set("cache-xml-file", "cache.xml")
                .set("log-level", "info")

        System.out.println("Attempting to start cache server");


        System.out.println("Cache server successfully started");

4. Create a cache.xml with a dummy region
        "-//GemStone Systems, Inc.//GemFire Declarative Caching 8.0//EN"
    <cache-server bind-address="localhost" port="0" hostname-for-clients="localhost"/>

    <region name="CompressedRegion">
        <region-attributes data-policy="partition">
            <partition-attributes redundant-copies="1" total-num-buckets="113"/>
                <lru-heap-percentage action="overflow-to-disk"/>

    <resource-manager critical-heap-percentage="75" eviction-heap-percentage="65"/>


5. Edit the run configurations for to include GEMFIRE env variable as shown below.

6. Run as shown below.

7. Run as shown below.

8. Finally from the IDE run a script called to view the cluster member/regions to ensure it worked.

. ./

gfsh <<EOF
connect --locator=localhost[10334];
list members;
list regions;


More Information

Pivotal GemFire Locator Processes

Pivotal GemFire Server Processes

No comments: