Orientdb 3.0m.02: Timeout on reading response when connecting to a remote database

时间:2017-08-04 13:11:37

标签: orientdb

I'm trying to connect to a remote orientdb connection withe the java api, using the 3.0 m2 cersion of OrientDB. I have already installed the Orientdb Ditribution orientdb-community-spatial-3.0.0m2, with the demodb.

The code is very straightforward:

         orientDb = new OrientDB("remote:localhost", "root", "root", OrientDBConfig.defaultConfig());

        // open a session on the database
        session = orientDb.open("demodb", "admin", "admin");

.. throwing immediatly an exception:

java.io.IOException: Timeout on reading response at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:249) at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:176) at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1274) at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1309) at com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1254) at com.orientechnologies.orient.client.remote.OStorageRemote.open(OStorageRemote.java:392) at com.orientechnologies.orient.core.db.document.ODatabaseDocumentRemote.internalOpen(ODatabaseDocumentRemote.java:144) at com.orientechnologies.orient.core.db.OrientDBRemote.open(OrientDBRemote.java:82) at com.orientechnologies.orient.core.db.OrientDB.open(OrientDB.java:209) at com.orientechnologies.orient.core.db.OrientDB.open(OrientDB.java:194) at com.activus.connectit.storage.graph.StorageGraphDb.dbSetup(StorageGraphDb.java:91)

Is it a bug, or a misuse of the java API ?

2 个答案:

答案 0 :(得分:0)

试试这个:

String DBname="db-name";
        String currentPath="remote:localhost/"+DBname;

        OServerAdmin serverAdmin;
        try 
        {
            serverAdmin = new OServerAdmin(currentPath).connect("root", "root"); 
            if(serverAdmin.existsDatabase())
            {  

                OrientGraph g=new OrientGraph(currentPath); 

                // DO SOMETHING ...

                g.shutdown();

            }
            serverAdmin.close();  
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }   

希望有所帮助

此致

答案 1 :(得分:0)

我创建了一个用于测试两种连接模式的小类:

import java.io.IOException;    
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;

/**
 * @author bsupiot
 *
 */
public class OrientDBSimpleConnectionTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // try connect with legacy tinkerpop
        if (!connectWithTinkerpop()) {

            // try with new unified interface
            connectWithUnifiedInterface();
        }
    }

    /**
     * connect with OrientDB 3.0 unified interface
     */
    public static boolean connectWithUnifiedInterface() {
        try  {
        // connect to remote database engine
        OrientDB orientDb = new OrientDB("remote:localhost", "root", "root", 
        OrientDBConfig.defaultConfig());

        // open a session on the database
        ODatabaseDocument session = orientDb.open("demodb", "admin", "admin");

        session.close();
        orientDb.close();

        // RUntime exception will be thrown if any problem has occured
        return true;
        } catch (Throwable ex) {
            ex.printStackTrace();
            return false;
        }
    }

    /**
     * connect winth tinkerpop
     */
    public static boolean connectWithTinkerpop() {
        try {
            // create a server adminitration
            OServerAdmin serverAdmin = new 
             OServerAdmin("remote:localhost/demodb").connect("root", "root");
            // if the database already exists
            if (serverAdmin.existsDatabase()) {
                OrientGraph g = new OrientGraph("remote:localhost/demodb");
                System.out.println("connected: " + g);
                g.shutdown();
                return true;
            } else {
                System.out.println("database does not exists");
                return false;
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
            return false;
        }
    }

}

The two functions throwsthe same exception.
Noty that when Orientdb server is not started, I have (as excpected) a "connection refused" exception.

Regards