本文整理汇总了Java中org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine类的典型用法代码示例。如果您正苦于以下问题:Java GremlinGroovyScriptEngine类的具体用法?Java GremlinGroovyScriptEngine怎么用?Java GremlinGroovyScriptEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GremlinGroovyScriptEngine类属于org.apache.tinkerpop.gremlin.groovy.jsr223包,在下文中一共展示了GremlinGroovyScriptEngine类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initialize
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Override
public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException {
this.lineRecordReader.initialize(genericSplit, context);
final Configuration configuration = context.getConfiguration();
if (configuration.get(Constants.GREMLIN_HADOOP_GRAPH_FILTER, null) != null)
this.graphFilter = VertexProgramHelper.deserialize(ConfUtil.makeApacheConfiguration(configuration), Constants.GREMLIN_HADOOP_GRAPH_FILTER);
this.engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try (final InputStream stream = fs.open(new Path(configuration.get(SCRIPT_FILE)));
final InputStreamReader reader = new InputStreamReader(stream)) {
this.parse = String.join("\n", IOUtils.toString(reader), READ_CALL);
script = ((Compilable) engine).compile(this.parse);
} catch (ScriptException e) {
throw new IOException(e.getMessage(), e);
}
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:ScriptRecordReader.java
示例2: shouldGarbageCollectPhantomButNotHard
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的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();
}
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:GremlinServerIntegrateTest.java
示例3: shouldEnsureTraverseRelationshipNeedsTx
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Test
public void shouldEnsureTraverseRelationshipNeedsTx() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Bindings bindings = engine.createBindings();
bindings.put("g", graph.traversal());
bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
marko.addEdge("friend", john);
marko.addEdge("friend", pete);
this.graph.tx().commit();
Object result = engine.eval("g.V(" + marko.id().toString() + ").outE('friend')", bindings);
assertTrue(result instanceof GraphTraversal);
this.graph.tx().commit();
assertEquals(2L, ((GraphTraversal) result).count().next());
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:NativeNeo4jStructureCheck.java
示例4: shouldEnsureTraversalOfVerticesNeedsTx
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Test
public void shouldEnsureTraversalOfVerticesNeedsTx() throws ScriptException {
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
final Bindings bindings = engine.createBindings();
bindings.put("g", graph.traversal());
bindings.put("#jsr223.groovy.engine.keep.globals", "phantom");
Vertex marko = this.graph.addVertex(T.label, "Person", "name", "marko");
Vertex john = this.graph.addVertex(T.label, "Person", "name", "john");
Vertex pete = this.graph.addVertex(T.label, "Person", "name", "pete");
marko.addEdge("friend", john);
marko.addEdge("friend", pete);
this.graph.tx().commit();
Object result = engine.eval("g.V(" + marko.id().toString() + ").out('friend')", bindings);
assertTrue(result instanceof GraphTraversal);
this.graph.tx().commit();
assertEquals(2L, ((GraphTraversal) result).count().next());
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:21,代码来源:NativeNeo4jStructureCheck.java
示例5: executeGremlinScript
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();
try {
Bindings bindings = scriptEngine.createBindings();
bindings.put("graph", getGraph());
bindings.put("g", getGraph().traversal());
Object result = scriptEngine.eval(gremlinQuery, bindings);
return result;
} catch (ScriptException e) {
throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, gremlinQuery);
} finally {
releaseGremlinScriptEngine(scriptEngine);
}
}
开发者ID:apache,项目名称:incubator-atlas,代码行数:19,代码来源:Titan1Graph.java
示例6: shouldGarbageCollectPhantomButNotHard
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Test
public void shouldGarbageCollectPhantomButNotHard() throws Exception {
final Cluster cluster = TestClientFactory.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();
}
}
开发者ID:apache,项目名称:tinkerpop,代码行数:23,代码来源:GremlinServerIntegrateTest.java
示例7: shouldTest
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Test
@Ignore("This is not a test that needs to run on build - it's more for profiling the GremlinGroovyScriptEngine")
public void shouldTest() throws Exception {
final Random r = new Random();
final List<Pair<String, Integer>> scripts = new ArrayList<>();
final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
for (int ix = 0; ix < 1000000; ix++) {
final String script = "1 + " + ix;
final int output = (int) engine.eval(script);
assertEquals(1 + ix, output);
if (ix % 1000 == 0) scripts.add(Pair.with(script, output));
if (ix % 25 == 0) {
final Pair<String,Integer> p = scripts.get(r.nextInt(scripts.size()));
assertEquals(p.getValue1().intValue(), (int) engine.eval(p.getValue0()));
}
}
}
开发者ID:apache,项目名称:tinkerpop,代码行数:20,代码来源:GremlinGroovyScriptEngineIntegrateTest.java
示例8: ScriptRecordWriter
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
public ScriptRecordWriter(final DataOutputStream out, final TaskAttemptContext context) throws IOException {
this.out = out;
final Configuration configuration = context.getConfiguration();
this.engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider());
//this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
final FileSystem fs = FileSystem.get(configuration);
try {
this.engine.eval(new InputStreamReader(fs.open(new Path(configuration.get(SCRIPT_FILE)))));
} catch (final ScriptException e) {
throw new IOException(e.getMessage(),e);
}
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:13,代码来源:ScriptRecordWriter.java
示例9: getGremlinScriptEngine
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Override
public GremlinGroovyScriptEngine getGremlinScriptEngine() {
Set<String> extraImports = new HashSet<String>();
extraImports.add(java.util.function.Function.class.getName());
Set<String> extraStaticImports = new HashSet<String>();
extraStaticImports.add(P.class.getName() + ".*");
extraStaticImports.add(__.class.getName() + ".*");
CompilerCustomizerProvider provider = new DefaultImportCustomizerProvider(extraImports, extraStaticImports);
GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider);
return scriptEngine;
}
开发者ID:apache,项目名称:incubator-atlas,代码行数:15,代码来源:Titan1Graph.java
示例10: releaseGremlinScriptEngine
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
@Override
public void releaseGremlinScriptEngine(ScriptEngine scriptEngine) {
if (scriptEngine instanceof GremlinGroovyScriptEngine) {
try {
((GremlinGroovyScriptEngine)scriptEngine).close();
} catch (Exception e) {
// ignore
}
}
}
开发者ID:apache,项目名称:incubator-atlas,代码行数:11,代码来源:Titan1Graph.java
示例11: Gremlin
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
public Gremlin(GraphWrapper wrapper) {
this.wrapper = wrapper;
this.engine = new GremlinGroovyScriptEngine();
final DefaultImportCustomizerProvider provider = new DefaultImportCustomizerProvider();
final Set<String> allImports = provider.getAllImports();
allImports.removeIf(path -> path.indexOf("groovy.") > -1);
engine.addImports(allImports);
engine.addImports(Sets.newHashSet("import org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP"));
this.bindings = engine.createBindings();
mapper = new ObjectMapper();
}
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:14,代码来源:Gremlin.java
示例12: createScriptEngine
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine; //导入依赖的package包/类
private static synchronized Optional<ScriptEngine> createScriptEngine(final String language,
final Set<String> imports,
final Set<String> staticImports,
final Map<String, Object> config) {
// gremlin-groovy gets special initialization for mapper imports and such. could implement this more
// generically with the DependencyManager interface, but going to wait to see how other ScriptEngines
// develop for TinkerPop3 before committing too deeply here to any specific way of doing this.
if (language.equals(gremlinGroovyScriptEngineFactory.getLanguageName())) {
final List<CompilerCustomizerProvider> providers = new ArrayList<>();
providers.add(new DefaultImportCustomizerProvider(imports, staticImports));
// the key to the config of the compilerCustomizerProvider is the fully qualified classname of a
// CompilerCustomizerProvider. the value is a list of arguments to pass to an available constructor.
// the arguments must match in terms of type, so given that configuration typically comes from yaml
// or properties file, it is best to stick to primitive values when possible here for simplicity.
final Map<String,Object> compilerCustomizerProviders = (Map<String,Object>) config.getOrDefault(
"compilerCustomizerProviders", Collections.emptyMap());
compilerCustomizerProviders.forEach((k,v) -> {
try {
final Class providerClass = Class.forName(k);
if (v != null && v instanceof List && ((List) v).size() > 0) {
final List<Object> l = (List) v;
final Object[] args = new Object[l.size()];
l.toArray(args);
final Class<?>[] argClasses = new Class<?>[args.length];
Stream.of(args).map(a -> a.getClass()).collect(Collectors.toList()).toArray(argClasses);
final Optional<Constructor> constructor = Stream.of(providerClass.getConstructors())
.filter(c -> c.getParameterCount() == argClasses.length &&
allMatch(c.getParameterTypes(), argClasses))
.findFirst();
if (constructor.isPresent()) providers.add((CompilerCustomizerProvider)
constructor.get().newInstance(args));
else
throw new IllegalStateException(String.format("Could not configure %s with the supplied options %s",
ConfigurationCustomizerProvider.class.getName(), Arrays.asList(args)));
} else {
providers.add((CompilerCustomizerProvider) providerClass.newInstance());
}
} catch(Exception ex) {
logger.warn(String.format("Could not instantiate CompilerCustomizerProvider implementation [%s]. It will not be applied.", k), ex);
}
});
final CompilerCustomizerProvider[] providerArray = new CompilerCustomizerProvider[providers.size()];
return Optional.of((ScriptEngine) new GremlinGroovyScriptEngine(providers.toArray(providerArray)));
} else {
return Optional.ofNullable(SCRIPT_ENGINE_MANAGER.getEngineByName(language));
}
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:53,代码来源:ScriptEngines.java
注:本文中的org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论