Tuesday, 4 November 2014

Starting a Pivotal GemFireXD server from Java

The FabricServer interface provides an easy way to start an embedded GemFire XD server process in an existing Java application.

In short code as follows will get you started. Use this in DEV/TEST scenarios not for production use.

  
package pivotal.au.gemfirexd.demos.startup;

import com.pivotal.gemfirexd.FabricServer;
import com.pivotal.gemfirexd.FabricServiceManager;

import java.sql.SQLException;
import java.util.Properties;

public class StartServer1
{
    public static void main(String[] args) throws SQLException, InterruptedException {
        // TODO Auto-generated method stub
        FabricServer server = FabricServiceManager.getFabricServerInstance();

        Properties serverProps = new Properties();
        serverProps.setProperty("server-groups", "mygroup");
        serverProps.setProperty("persist-dd", "false");
        serverProps.setProperty("sys-disk-dir","./gfxd/server1");
        serverProps.setProperty("host-data","true");

        server.start(serverProps);

        server.startNetworkServer("127.0.0.1", 1527, null);

        Object lock = new Object();
        synchronized (lock) {
            while (true) {
                lock.wait();
            }
        }

    }
} 

More Information

http://gemfirexd.docs.pivotal.io/latest/userguide/index.html#developers_guide/topics/server-side/fabricserver.html

No comments: