Search in sources :

Example 1 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OStorageRemote method openRemoteDatabase.

protected void openRemoteDatabase(String currentURL) {
    do {
        do {
            OChannelBinaryAsynchClient network = null;
            try {
                network = getNetwork(currentURL);
                openRemoteDatabase(network);
                final int serverVersion = network.getSrvProtocolVersion();
                connectionManager.release(network);
                return;
            } catch (OIOException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
            } catch (OException e) {
                connectionManager.release(network);
                // PROPAGATE ANY OTHER ORIENTDB EXCEPTION
                throw e;
            } catch (Exception e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception ex) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
                OLogManager.instance().error(this, "Cannot open database url=" + currentURL, e);
            }
        } while (connectionManager.getReusableConnections(currentURL) > 0);
        currentURL = useNewServerURL(currentURL);
    } while (currentURL != null);
    // REFILL ORIGINAL SERVER LIST
    parseServerURLs();
    synchronized (serverURLs) {
        throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
    }
}
Also used : OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 2 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OStorageRemote method reopenRemoteDatabase.

protected String reopenRemoteDatabase() throws IOException {
    String currentURL = getCurrentServerURL();
    do {
        do {
            final OChannelBinaryAsynchClient network = getNetwork(currentURL);
            try {
                OStorageRemoteSession session = getCurrentSession();
                OStorageRemoteNodeSession nodeSession = session.getOrCreateServerSession(network.getServerURL());
                if (nodeSession == null || !nodeSession.isValid()) {
                    openRemoteDatabase(network);
                    connectionManager.release(network);
                    return network.getServerURL();
                } else {
                    try {
                        network.writeByte(OChannelBinaryProtocol.REQUEST_DB_REOPEN);
                        network.writeInt(nodeSession.getSessionId());
                        network.writeBytes(nodeSession.getToken());
                    } finally {
                        endRequest(network);
                    }
                    final int sessionId;
                    try {
                        byte[] newToken = network.beginResponse(nodeSession.getSessionId(), true);
                        sessionId = network.readInt();
                        if (newToken != null && newToken.length > 0) {
                            nodeSession.setSession(sessionId, newToken);
                        } else {
                            nodeSession.setSession(sessionId, nodeSession.getToken());
                        }
                        OLogManager.instance().debug(this, "Client connected to %s with session id=%d", network.getServerURL(), sessionId);
                        return currentURL;
                    } finally {
                        endResponse(network);
                        connectionManager.release(network);
                    }
                }
            } catch (OIOException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().error(this, "Cannot open database with url " + currentURL, e);
            } catch (OOfflineNodeException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
            } catch (OSecurityException ex) {
                OLogManager.instance().debug(this, "Invalidate token for url=%s", ex, currentURL);
                OStorageRemoteSession session = getCurrentSession();
                session.removeServerSession(currentURL);
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception e) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
            } catch (OException e) {
                connectionManager.release(network);
                // PROPAGATE ANY OTHER ORIENTDB EXCEPTION
                throw e;
            } catch (Exception e) {
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception ex) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
            }
        } while (connectionManager.getAvailableConnections(currentURL) > 0);
        currentURL = useNewServerURL(currentURL);
    } while (currentURL != null);
    // REFILL ORIGINAL SERVER LIST
    parseServerURLs();
    synchronized (serverURLs) {
        throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
    }
}
Also used : OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 3 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OStorageRemote method getNetwork.

public OChannelBinaryAsynchClient getNetwork(final String iCurrentURL) {
    OChannelBinaryAsynchClient network;
    do {
        try {
            network = connectionManager.acquire(iCurrentURL, clientConfiguration, connectionOptions, asynchEventListener);
        } catch (OIOException cause) {
            throw cause;
        } catch (Exception cause) {
            throw OException.wrapException(new OStorageException("Cannot open a connection to remote server: " + iCurrentURL), cause);
        }
        if (!network.tryLock()) {
            // CANNOT LOCK IT, MAYBE HASN'T BE CORRECTLY UNLOCKED BY PREVIOUS USER?
            OLogManager.instance().error(this, "Removing locked network channel '%s' (connected=%s)...", iCurrentURL, network.isConnected());
            connectionManager.remove(network);
            network = null;
        }
    } while (network == null);
    return network;
}
Also used : OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 4 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OStorageRemote method close.

public void close(final boolean iForce, boolean onDelete) {
    if (status == STATUS.CLOSED)
        return;
    stateLock.acquireWriteLock();
    try {
        if (status == STATUS.CLOSED)
            return;
        final OStorageRemoteSession session = getCurrentSession();
        if (session != null) {
            final Collection<OStorageRemoteNodeSession> nodes = session.getAllServerSessions();
            if (!nodes.isEmpty()) {
                for (OStorageRemoteNodeSession nodeSession : nodes) {
                    OChannelBinaryAsynchClient network = null;
                    try {
                        network = getNetwork(nodeSession.getServerURL());
                        network.beginRequest(OChannelBinaryProtocol.REQUEST_DB_CLOSE, session);
                        endRequest(network);
                        connectionManager.release(network);
                    } catch (OIOException ex) {
                        // IGNORING IF THE SERVER IS DOWN OR NOT REACHABLE THE SESSION IS AUTOMATICALLY CLOSED.
                        OLogManager.instance().debug(this, "Impossible to comunicate to the server for close: %s", ex);
                        connectionManager.remove(network);
                    } catch (IOException ex) {
                        // IGNORING IF THE SERVER IS DOWN OR NOT REACHABLE THE SESSION IS AUTOMATICALLY CLOSED.
                        OLogManager.instance().debug(this, "Impossible to comunicate to the server for close: %s", ex);
                        connectionManager.remove(network);
                    }
                }
                session.close();
                sessions.remove(session);
                if (!checkForClose(iForce))
                    return;
            } else {
                if (!iForce)
                    return;
            }
        }
        status = STATUS.CLOSING;
        // CLOSE ALL THE CONNECTIONS
        for (String url : serverURLs) {
            connectionManager.closePool(url);
        }
        sbTreeCollectionManager.close();
        super.close(iForce, onDelete);
        status = STATUS.CLOSED;
        Orient.instance().unregisterStorage(this);
    } finally {
        stateLock.releaseWriteLock();
    }
}
Also used : OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException)

Example 5 with OIOException

use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.

the class OChannelBinaryAsynchClient method beginRequest.

public void beginRequest(final byte iCommand, final OStorageRemoteSession session) throws IOException {
    final OStorageRemoteNodeSession nodeSession = session.getServerSession(getServerURL());
    if (nodeSession == null)
        throw new OIOException("Invalid session for URL '" + getServerURL() + "'");
    writeByte(iCommand);
    writeInt(nodeSession.getSessionId());
    if (nodeSession.getToken() != null) {
        // if (!session.hasConnection(this) || true) {
        writeBytes(nodeSession.getToken());
    // session.addConnection(this);
    // } else
    // writeBytes(new byte[] {});
    }
}
Also used : OStorageRemoteNodeSession(com.orientechnologies.orient.client.remote.OStorageRemoteNodeSession) OIOException(com.orientechnologies.common.io.OIOException)

Aggregations

OIOException (com.orientechnologies.common.io.OIOException)14 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)6 IOException (java.io.IOException)6 OException (com.orientechnologies.common.exception.OException)5 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)4 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)4 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)4 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)4 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)4 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)4 NamingException (javax.naming.NamingException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)1 OSystemException (com.orientechnologies.common.exception.OSystemException)1 OCallable (com.orientechnologies.common.util.OCallable)1 OStorageRemoteNodeSession (com.orientechnologies.orient.client.remote.OStorageRemoteNodeSession)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)1 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)1