private static ConnectionFactory instance = null;
private String address = "xxx.xxx.xxx.xxx"; /* Default address */
private int port = 8182; /* Default port */
private Cluster cluster = null;
private Client client = null;
/**
* Constructor for the titan graph connection. The constructor cannot be called directly.
*
*/
private ConnectionFactory() {
}
/**
* Get an instance of the Connection factory. If an instance already exist, the existing one is passed
* back to the caller. If class instance does not exist, a new one is crated.
*
* @return ConnectionFactory instance
*/
public static ConnectionFactory getInstance() {
if(instance == null) {
instance = new ConnectionFactory();
instance.openConnection();
}
return instance;
}
/**
* Opens the connection to the graph database.
*
*/
public void openConnection() {
GryoMessageSerializerV1d0 serializerClass = null;
Cluster.Builder clusterBuilder = null;
Map<String, Object> configMap = null;
/* This is required so that the result vertex can be serialized to string */
serializerClass = new GryoMessageSerializerV1d0();
configMap = new HashMap<String, Object>();
configMap.put("serializeResultToString", "true");
serializerClass.configure(configMap, null);
/* Build cluster configuration */
clusterBuilder = Cluster.build(address);
clusterBuilder.port(port);
clusterBuilder.serializer(serializerClass);
/* create a cluster instance */
cluster = clusterBuilder.create();
client = cluster.connect();
I hope now you have the idea of my code.