public DriverRemoteConnection(final Configuration conf) {
    if (conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE)
        && conf.containsKey("clusterConfiguration"))
      throw new IllegalStateException(
          String.format(
              "A configuration should not contain both '%s' and 'clusterConfiguration'",
              GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE));

    connectionGraphName = conf.getString(GREMLIN_REMOTE_GRAPH_DRIVER_GRAPHNAME, DEFAULT_GRAPH);

    try {
      final Cluster cluster;
      if (!conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE)
          && !conf.containsKey("clusterConfiguration")) cluster = Cluster.open();
      else
        cluster =
            conf.containsKey(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE)
                ? Cluster.open(conf.getString(GREMLIN_REMOTE_GRAPH_DRIVER_CLUSTERFILE))
                : Cluster.open(conf.subset("clusterConfiguration"));

      client =
          cluster
              .connect(Client.Settings.build().unrollTraversers(false).create())
              .alias(connectionGraphName);
    } catch (Exception ex) {
      throw new IllegalStateException(ex);
    }

    tryCloseCluster = true;
    this.conf = Optional.of(conf);
  }
Ejemplo n.º 2
0
  public boolean initializePath(String path) {
    try {
      _cluster = Cluster.open(path);
      _client = _cluster.connect();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    if (_cluster == null || _client == null) {
      return false;
    }

    return true;
  }
Ejemplo n.º 3
0
  public boolean initialize() {
    try {
      _cluster = Cluster.open("./src/main/resources/remote2.yaml");
      _client = _cluster.connect();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    if (_cluster == null || _client == null) {
      return false;
    }

    return true;
  }
 /**
  * Creates a {@link DriverRemoteConnection} using a new {@link Cluster} instance created from the
  * supplied configuration file. When {@link #close()} is called, this new {@link Cluster} is also
  * closed.
  */
 public static DriverRemoteConnection using(
     final String clusterConfFile, final String connectionGraphName) {
   try {
     return new DriverRemoteConnection(Cluster.open(clusterConfFile), true, connectionGraphName);
   } catch (Exception ex) {
     throw new IllegalStateException(ex);
   }
 }
 private DriverRemoteConnection(
     final Cluster cluster, final boolean tryCloseCluster, final String connectionGraphName) {
   client =
       cluster
           .connect(Client.Settings.build().unrollTraversers(false).create())
           .alias(connectionGraphName);
   this.connectionGraphName = connectionGraphName;
   this.tryCloseCluster = tryCloseCluster;
 }
 /**
  * This constructor is largely just for unit testing purposes and should not typically be used
  * externally.
  */
 DriverRemoteConnection(final Cluster cluster, final Configuration conf) {
   connectionGraphName = conf.getString(GREMLIN_REMOTE_GRAPH_DRIVER_GRAPHNAME, DEFAULT_GRAPH);
   client =
       cluster
           .connect(Client.Settings.build().unrollTraversers(false).create())
           .alias(connectionGraphName);
   tryCloseCluster = false;
   this.conf = Optional.of(conf);
 }
Ejemplo n.º 7
0
  public void close() {
    _client.close();
    _cluster.close();
    //
    // Workaround of a bug in Tinkerpop Driver 3.1.0-incubating, going to be fixed soon
    fixThreadLeakInGremlinCluster(_cluster);

    _client = null;
    _cluster = null;
  }
Ejemplo n.º 8
0
  public boolean initialize(String config) {
    try {

      _cluster = Cluster.open("./src/main/resources/" + config + ".yaml");

      //			if(config == "local"){
      //				_cluster = Cluster.open("./src/main/resources/local.yaml");
      //			}else{
      //				_cluster = Cluster.open("./src/main/resources/remote.yaml");
      //			}
      _client = _cluster.connect();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    if (_cluster == null || _client == null) {
      return false;
    }

    return true;
  }
  /**
   * Creates a {@link DriverRemoteConnection} using an Apache {@code Configuration} object. This
   * method of creation is typically used by {@link RemoteGraph} when being constructed via {@link
   * GraphFactory}. The {@code Configuration} object should contain one of two required keys,
   * either: {@code clusterConfigurationFile} or {@code clusterConfiguration}. The {@code
   * clusterConfigurationFile} key is a pointer to a file location containing a configuration for a
   * {@link Cluster}. The {@code clusterConfiguration} should contain the actual contents of a
   * configuration that would be used by a {@link Cluster}. This {@code configuration} may also
   * contain the optional, but likely necessary, {@code connectionGraphName} which tells the {@code
   * DriverServerConnection} which graph on the server to bind to.
   */
  public static DriverRemoteConnection using(final Configuration conf) {
    if (conf.containsKey("clusterConfigurationFile") && conf.containsKey("clusterConfiguration"))
      throw new IllegalStateException(
          "A configuration should not contain both 'clusterConfigurationFile' and 'clusterConfiguration'");

    if (!conf.containsKey("clusterConfigurationFile") && !conf.containsKey("clusterConfiguration"))
      throw new IllegalStateException(
          "A configuration must contain either 'clusterConfigurationFile' and 'clusterConfiguration'");

    final String connectionGraphName = conf.getString("connectionGraphName", "graph");
    if (conf.containsKey("clusterConfigurationFile"))
      return using(conf.getString("clusterConfigurationFile"), connectionGraphName);
    else {
      return using(Cluster.open(conf.subset("clusterConfiguration")), connectionGraphName);
    }
  }