动态连接到orientdb
我有一个java应用程序,它使用orientDB API(tinkerprop包)创建类并从orientDB插入和获取数据。数据库正在另一台服务器上运行 我希望我的应用程序能够在orientDB关闭后出现的情况下,我不需要重新启动java应用程序来获得与orientDB的连接。(数据库可用时,应自动刷新连接) 在复制设置中,我可能有2个节点,但如果两个节点都需要重新启动,我的应用程序也需要重新启动。(遇到由于仲裁不可到达错误导致插入未发生的情况,最后需要重新启动两台服务器) 我尝试了以下代码动态连接到orientdb,orientdb,orientdb2.2,Orientdb,Orientdb2.2,我有一个java应用程序,它使用orientDB API(tinkerprop包)创建类并从orientDB插入和获取数据。数据库正在另一台服务器上运行 我希望我的应用程序能够在orientDB关闭后出现的情况下,我不需要重新启动java应用程序来获得与orientDB的连接。(数据库可用时,应自动刷新连接) 在复制设置中,我可能有2个节点,但如果两个节点都需要重新启动,我的应用程序也需要重新启动。(遇到由于仲裁不可到达错误导致插入未发生的情况,最后需要重新启动两台服务器) 我尝试了以下代码 w
while(true)
{
try {
OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/testdb", "root", "root").setupPool(1,50);
OrientGraphNoTx graph = factory.getNoTx();
Thread.sleep(1*30*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
但是当我关闭orientDB服务器时,应用程序终止了。服务器关闭时引发以下异常
Exception in thread "main" com.orientechnologies.orient.core.exception.OStorageException: Cannot create a connection to remote server address(es): [127.0.0.1:2424]
DB name="testdb"
at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1960)
at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1860)
at com.orientechnologies.orient.client.remote.OStorageRemote.open(OStorageRemote.java:356)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:258)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPooled.internalOpen(OPartitionedDatabasePool.java:447)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.openDatabase(OPartitionedDatabasePool.java:310)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.acquire(OPartitionedDatabasePool.java:268)
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.<init>(OrientBaseGraph.java:143)
at com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx.<init>(OrientGraphNoTx.java:62)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory$2.getGraph(OrientGraphFactory.java:116)
at com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getNoTx(OrientGraphFactory.java:240)
线程“main”com.orientechnologies.orient.core.Exception.OStorageException中的异常:无法创建到远程服务器地址的连接:[127.0.0.1:2424]
DB name=“testdb”
在com.orientechnologies.orient.client.remote.ostrageremote.openRemoteDatabase上(ostrageremote.java:1960)
在com.orientechnologies.orient.client.remote.ostrageremote.openRemoteDatabase(ostrageremote.java:1860)
在com.orientechnologies.orient.client.remote.ostrageremote.open上(ostrageremote.java:356)
位于com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.open(ODatabaseDocumentTx.java:258)
在com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPooled.internalOpen(OPartitionedDatabasePool.java:447)
位于com.orientechnologies.orient.core.db.OPartitionedDatabasePool.openDatabase(OPartitionedDatabasePool.java:310)
在com.orientechnologies.orient.core.db.OPartitionedDatabasePool.acquire(OPartitionedDatabasePool.java:268)
位于com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.(OrientBaseGraph.java:143)
在com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx上(OrientGraphNoTx.java:62)
在com.tinkerpop.blueprints.impls.orient.OrientGraphFactory$2.getGraph(OrientGraphFactory.java:116)
在com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.getNoTx(OrientGraphFactory.java:240)
将OStorageException添加到catch块就足够了:
while(true)
{
try {
OrientGraphFactory factory = new OrientGraphFactory("remote:localhost/testdb", "root", "root").setupPool(1,50);
OrientGraphNoTx graph = factory.getNoTx();
Thread.sleep(1*30*1000);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (OStorageException e2) {
e2.printStackTrace();
} catch(OOfflineNodeException e3){
e3.printStackTrace();
}
}
难道你不能检查服务器的运行状况并实现一个循环来重新连接吗?我已经在我的问题中添加了代码,我试图检查服务器的运行状况也就是com.orientechnologies.common.concur.OOfflineNodeException异常