本文整理汇总了Java中org.apache.tinkerpop.gremlin.driver.Cluster.open方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.open方法的具体用法?Java Cluster.open怎么用?Java Cluster.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tinkerpop.gremlin.driver.Cluster
的用法示例。
在下文中一共展示了Cluster.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Override
public Object connect(final List<String> args) throws RemoteException {
if (args.size() < 1) throw new RemoteException("Expects the location of a configuration file as an argument");
try {
this.currentCluster = Cluster.open(args.get(0));
final boolean useSession = args.size() >= 2 && (args.get(1).equals(TOKEN_SESSION) || args.get(1).equals(TOKEN_SESSION_MANAGED));
if (useSession) {
final String sessionName = args.size() == 3 ? args.get(2) : UUID.randomUUID().toString();
session = Optional.of(sessionName);
final boolean managed = args.get(1).equals(TOKEN_SESSION_MANAGED);
this.currentClient = this.currentCluster.connect(sessionName, managed);
} else {
this.currentClient = this.currentCluster.connect();
}
this.currentClient.init();
return String.format("Configured %s", this.currentCluster) + getSessionStringSegment();
} catch (final FileNotFoundException ignored) {
throw new RemoteException("The 'connect' option must be accompanied by a valid configuration file");
} catch (final Exception ex) {
throw new RemoteException("Error during 'connect' - " + ex.getMessage(), ex);
}
}
示例2: DriverRemoteConnection
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
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);
}
示例3: shouldNotUseInterpreterMode
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldNotUseInterpreterMode() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect(name.getMethodName());
client.submit("def subtractAway(x,y){x-y};[]").all().get();
client.submit("multiplyIt = { x,y -> x * y};[]").all().get();
assertEquals(2, client.submit("x = 1 + 1").all().get().get(0).getInt());
assertEquals(3, client.submit("y = x + 1").all().get().get(0).getInt());
assertEquals(5, client.submit("z = x + y").all().get().get(0).getInt());
final Map<String,Object> m = new HashMap<>();
m.put("x", 10);
assertEquals(-5, client.submit("z - x", m).all().get().get(0).getInt());
assertEquals(15, client.submit("addItUp(x,z)", m).all().get().get(0).getInt());
assertEquals(5, client.submit("subtractAway(x,z)", m).all().get().get(0).getInt());
assertEquals(50, client.submit("multiplyIt(x,z)", m).all().get().get(0).getInt());
cluster.close();
}
示例4: shouldGarbageCollectPhantomButNotHard
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldGarbageCollectPhantomButNotHard() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
assertEquals(2, client.submit("addItUp(1,1)").all().join().get(0).getInt());
assertEquals(0, client.submit("def subtract(x,y){x-y};subtract(1,1)").all().join().get(0).getInt());
assertEquals(0, client.submit("subtract(1,1)").all().join().get(0).getInt());
final Map<String, Object> bindings = new HashMap<>();
bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_PHANTOM);
assertEquals(4, client.submit("def multiply(x,y){x*y};multiply(2,2)", bindings).all().join().get(0).getInt());
try {
client.submit("multiply(2,2)").all().join().get(0).getInt();
fail("Should throw an exception since reference is phantom.");
} catch (RuntimeException ignored) {
} finally {
cluster.close();
}
}
示例5: shouldFailWithScriptExecutionException
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailWithScriptExecutionException() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("1/0");
try {
results.all().join();
fail("Should have thrown exception over bad serialization");
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
assertTrue(inner instanceof ResponseException);
assertThat(inner.getMessage(), endsWith("Division by zero"));
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
// from time to time, especially in the console if you're just exploring.
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
cluster.close();
}
示例6: shouldProcessRequestsOutOfOrder
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldProcessRequestsOutOfOrder() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
final ResultSet rsZero = client.submit("'zero'");
final CompletableFuture<List<Result>> futureFive = rsFive.all();
final CompletableFuture<List<Result>> futureZero = rsZero.all();
final long start = System.nanoTime();
assertFalse(futureFive.isDone());
assertEquals("zero", futureZero.get().get(0).getString());
logger.info("Eval of 'zero' complete: " + TimeUtil.millisSince(start));
assertFalse(futureFive.isDone());
assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());
logger.info("Eval of 'five' complete: " + TimeUtil.millisSince(start));
}
示例7: shouldProcessSessionRequestsInOrder
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldProcessSessionRequestsInOrder() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect(name.getMethodName());
final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
final ResultSet rsZero = client.submit("'zero'");
final CompletableFuture<List<Result>> futureFive = rsFive.all();
final CompletableFuture<List<Result>> futureZero = rsZero.all();
final AtomicBoolean hit = new AtomicBoolean(false);
while (!futureFive.isDone()) {
// futureZero can't finish before futureFive - racy business here?
assertThat(futureZero.isDone(), is(false));
hit.set(true);
}
// should have entered the loop at least once and thus proven that futureZero didn't return ahead of
// futureFive
assertThat(hit.get(), is(true));
assertEquals("zero", futureZero.get().get(0).getString());
assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());
}
示例8: shouldWaitForAllResultsToArrive
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldWaitForAllResultsToArrive() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final AtomicInteger checked = new AtomicInteger(0);
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
while (!results.allItemsAvailable()) {
assertTrue(results.getAvailableItemCount() < 10);
checked.incrementAndGet();
Thread.sleep(100);
}
assertTrue(checked.get() > 0);
assertEquals(9, results.getAvailableItemCount());
cluster.close();
}
示例9: shouldIterate
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldIterate() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("[1,2,3,4,5,6,7,8,9]");
final Iterator<Result> itty = results.iterator();
final AtomicInteger counter = new AtomicInteger(0);
while (itty.hasNext()) {
counter.incrementAndGet();
assertEquals(counter.get(), itty.next().getInt());
}
assertEquals(9, counter.get());
assertThat(results.allItemsAvailable(), is(true));
// can't stream it again
assertThat(results.iterator().hasNext(), is(false));
cluster.close();
}
示例10: shouldFailWithBadServerSideSerialization
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldFailWithBadServerSideSerialization() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("TinkerGraph.open().variables()");
try {
results.all().join();
fail();
} catch (Exception ex) {
final Throwable inner = ExceptionUtils.getRootCause(ex);
assertTrue(inner instanceof ResponseException);
assertEquals(ResponseStatusCode.SERVER_ERROR_SERIALIZATION, ((ResponseException) inner).getResponseStatusCode());
}
// should not die completely just because we had a bad serialization error. that kind of stuff happens
// from time to time, especially in the console if you're just exploring.
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
cluster.close();
}
示例11: shouldHandleRequestSentThatNeverReturns
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
@org.junit.Ignore("Can't seem to make this test pass consistently")
public void shouldHandleRequestSentThatNeverReturns() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
final ResultSet results = client.submit("Thread.sleep(10000); 'should-not-ever-get-back-coz-we-killed-the-server'");
stopServer();
// give the server a chance to kill everything
Thread.sleep(1000);
try {
results.all().get(10000, TimeUnit.MILLISECONDS);
fail("Server was stopped before the request could execute");
} catch (TimeoutException toe) {
fail("Should not have tossed a TimeOutException getting the result");
} catch (Exception ex) {
final Throwable cause = ExceptionUtils.getCause(ex);
assertThat(cause.getMessage(), containsString("rejected from java.util.concurrent.ThreadPoolExecutor"));
}
cluster.close();
}
示例12: shouldUseSimpleSandbox
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Test
public void shouldUseSimpleSandbox() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
try {
// this should return "nothing" - there should be no exception
client.submit("java.lang.System.exit(0)").all().get();
fail("The above should not have executed in any successful way as sandboxing is enabled");
} catch (Exception ex) {
assertThat(ex.getCause().getMessage(), containsString("[Static type checking] - Not authorized to call this method: java.lang.System#exit(int)"));
} finally {
cluster.close();
}
}
示例13: DriverRemoteConnection
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
public DriverRemoteConnection(final Configuration conf) {
final boolean hasClusterConf = IteratorUtils.anyMatch(conf.getKeys(), k -> k.startsWith("clusterConfiguration"));
if (conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && hasClusterConf)
throw new IllegalStateException(String.format("A configuration should not contain both '%s' and 'clusterConfiguration'", GREMLIN_REMOTE_DRIVER_CLUSTERFILE));
remoteTraversalSourceName = conf.getString(GREMLIN_REMOTE_DRIVER_SOURCENAME, DEFAULT_TRAVERSAL_SOURCE);
try {
final Cluster cluster;
if (!conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) && !hasClusterConf)
cluster = Cluster.open();
else
cluster = conf.containsKey(GREMLIN_REMOTE_DRIVER_CLUSTERFILE) ?
Cluster.open(conf.getString(GREMLIN_REMOTE_DRIVER_CLUSTERFILE)) : Cluster.open(conf.subset("clusterConfiguration"));
client = cluster.connect(Client.Settings.build().create()).alias(remoteTraversalSourceName);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
tryCloseCluster = true;
this.conf = Optional.of(conf);
}
示例14: open
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
@Override
public void open() {
logger.info("init gremlin client via {}", property);
Configuration configuration = new BaseConfiguration();
property.keySet().forEach(key -> configuration.setProperty(key.toString(), property.get(key)));
//transform hosts
String hosts = configuration.getString(GREMLIN_SERVER_HOSTS, DEFAULT_GREMLIN_SERVER_HOSTS);
configuration.clearProperty(GREMLIN_SERVER_HOSTS);
configuration.setProperty(GREMLIN_SERVER_HOSTS, Arrays.asList(hosts.split(",")));
cluster = Cluster.open(configuration.subset("gremlin.server"));
client = cluster.connect();
}
示例15: using
import org.apache.tinkerpop.gremlin.driver.Cluster; //导入方法依赖的package包/类
/**
* 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);
}
}