我的gremlin-server.yaml文件如下:
host: localhost
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphManager : com.orientechnologies.tinkerpop.server.OrientGremlinGraphManager
graphs: {
graph : ../config/db1.properties,
graph2 : ../config/db2.properties
}
scriptEngines: {
gremlin-groovy: {
plugins: { org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
org.apache.tinkerpop.gremlin.orientdb.jsr223.OrientDBGremlinPlugin: {},
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [java.lang.Math], methodImports: [java.lang.Math#*]},
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {files: [../config/db.groovy]}}}}
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.orientdb.io.OrientIoRegistry] }} # application/vnd.gremlin-v3.0+gryo
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v3.0+gryo-stringd
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.orientdb.io.OrientIoRegistry] }} # application/json
processors:
- { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }}
- { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }}我使用java连接到gremlin服务器。有没有一种方法可以从代码中检索图形名称:Graphandgraph2?
或者,如果我将图和graph2遍历绑定到db.groovy文件中的g和g2,并将它们添加为全局绑定,那么是否有方法检索名称:G和g2?
发布于 2020-06-04 12:10:11
没有直接的API来获得这个清单,但是如果您使用基于脚本的请求,并且您的提供程序实现没有出于安全原因而不允许这样做(或者考虑到它实现协议的方式,它就是不支持它),就可以得到它。简而言之,我只希望这种方法能够与TinkerPop的Gremlin实现一起工作,并且如果禁用或配置了安全沙箱以允许访问所涉及的类。
Gremlin承载一个处理脚本的ScriptEngine实例。它有一个“上下文”,它可以作为同名的变量使用。您可以通过以下方式访问该变量:
gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> context
==>org.apache.tinkerpop.gremlin.jsr223.GremlinScriptContext@c7ef4c5一旦有了它,您就可以过滤掉Graph (或者更有可能的话是使用fitler GraphTraversalSource实例),并获得服务器上已知的名称:
gremlin> context.getBindings(javax.script.ScriptContext.GLOBAL_SCOPE).entrySet().findAll{it.value instanceof Graph}.key
==>graph
gremlin> context.getBindings(javax.script.ScriptContext.GLOBAL_SCOPE).entrySet().findAll{it.value instanceof GraphTraversalSource}.key
==>g正如您所看到的,它在符合要求的驱动程序中工作得很好:
gremlin> cluster = Cluster.open()
==>localhost/127.0.0.1:8182
gremlin> client = cluster.connect()
==>org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient@5408d4b3
gremlin> client.submit("context.getBindings(javax.script.ScriptContext.GLOBAL_SCOPE).entrySet().findAll{it.value instanceof GraphTraversalSource}.key").all().get()
==>result{object=g class=java.lang.String}https://stackoverflow.com/questions/62074067
复制相似问题