我正在用 TinkerPop3 编写一个 Java 应用程序。它与 Neo4j 图形通信,并使用neo4j-gremlin 3.0.0.M7
库通过 Gremlin 发送读/写查询。
同时,我想通过 HTTP 使用gremlin-server 3.0.0.M7
. 另外,这些操作工作得很好。但是,由于不允许多个连接(即GremlinServer
对象和 Java 代码都试图获得图上的锁),这似乎是不可能同时进行的。
当然,解决方法可能涉及从 Java 程序中创建一个客户端并将其连接到服务器。但是,我宁愿消除这种引入的通信开销。
最大的问题:这可能吗?
为了完整起见,这是我的最小代码。请注意,mygremlin-server-neo4j.yaml
指的是标准包含neo4j-empty.properties
的文件,它包含与我的 Java 代码中的 Neo4jGraph 对象相同的 neo4j 图形数据目录(即/tmp/neo4j
)。
import com.tinkerpop.gremlin.neo4j.structure.Neo4jGraph;
import com.tinkerpop.gremlin.server.GremlinServer;
import com.tinkerpop.gremlin.server.Settings;
public class Main {
Neo4jGraph g;
GremlinServer s;
public static void main (String[] argv) {
new Main().start();
}
private void start () {
try {
Settings settings = Settings.read(getClass().getResourceAsStream("/gremlin-server-neo4j.yaml"));
s = new GremlinServer(settings);
s.run();
} catch (Exception e) {
e.printStackTrace();
}
g = Neo4jGraph.open("/tmp/neo4j");
// Gremlin code here
g.close();
s.stop();
}
}
最后,例外:
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /tmp/neo4j
at com.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.<init>(Neo4jGraph.java:160)
at com.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.open(Neo4jGraph.java:175)
at com.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.open(Neo4jGraph.java:184)
at org.test.Main.start(Main.java:33)
at org.test.Main.main(Main.java:15)
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /tmp/neo4j
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:366)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:59)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:91)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:181)
at com.tinkerpop.gremlin.neo4j.structure.Neo4jGraph.<init>(Neo4jGraph.java:133)
... 4 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.StoreLockerLifecycleAdapter@67ec8477' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:513)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:343)
... 8 more
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: /tmp/neo4j/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:82)
at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:44)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:507)
... 10 more
Caused by: java.io.IOException: Unable to lock org.neo4j.kernel.impl.nioneo.store.StoreFileChannel@baf1bb3
at org.neo4j.kernel.impl.nioneo.store.FileLock.wrapFileChannelLock(FileLock.java:38)
at org.neo4j.kernel.impl.nioneo.store.FileLock.getOsSpecificFileLock(FileLock.java:93)
at org.neo4j.kernel.DefaultFileSystemAbstraction.tryLock(DefaultFileSystemAbstraction.java:93)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:74)
... 12 more