Search in sources :

Example 1 with HDBOperationTimeoutException

use of herddb.client.impl.HDBOperationTimeoutException in project herddb by diennea.

the class RoutedClientSideConnection method ensureOpen.

@Override
public Channel ensureOpen() throws HDBException {
    connectionLock.readLock().lock();
    try {
        Channel channel = this.channel;
        if (channel != null && channel.isValid()) {
            return channel;
        }
        connectionLock.readLock().unlock();
        connectionLock.writeLock().lock();
        try {
            channel = this.channel;
            if (this.channel != null) {
                if (channel.isValid()) {
                    return channel;
                }
                // channel is not valid, force close
                channel.close();
            }
            // clean up local cache, if the server restarted we would use old ids
            preparedStatements.clear();
            LOGGER.log(Level.FINE, "{0} - connect to {1}:{2} ssh:{3}", new Object[] { this, server.getHost(), server.getPort(), server.isSsl() });
            channel = this.connection.getClient().createChannelTo(server, this);
            try {
                performAuthentication(channel, server.getHost());
                this.channel = channel;
                return channel;
            } catch (TimeoutException err) {
                LOGGER.log(Level.SEVERE, "Error", err);
                if (channel != null) {
                    channel.close();
                }
                throw new HDBOperationTimeoutException(err);
            } catch (Exception err) {
                LOGGER.log(Level.SEVERE, "Error", err);
                if (channel != null) {
                    channel.close();
                }
                throw err;
            }
        } finally {
            connectionLock.writeLock().unlock();
            connectionLock.readLock().lock();
        }
    } catch (java.net.ConnectException err) {
        // this error will be retryed by the client
        throw new UnreachableServerException("Cannot connect to " + nodeId, err, nodeId);
    } catch (HDBException err) {
        throw err;
    } catch (Exception err) {
        throw new HDBException(err);
    } finally {
        connectionLock.readLock().unlock();
    }
}
Also used : UnreachableServerException(herddb.client.impl.UnreachableServerException) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) Channel(herddb.network.Channel) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) LeaderChangedException(herddb.client.impl.LeaderChangedException) RetryRequestException(herddb.client.impl.RetryRequestException) TimeoutException(java.util.concurrent.TimeoutException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) UnreachableServerException(herddb.client.impl.UnreachableServerException) DataStorageManagerException(herddb.storage.DataStorageManagerException) HDBOperationTimeoutException(herddb.client.impl.HDBOperationTimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

HDBOperationTimeoutException (herddb.client.impl.HDBOperationTimeoutException)1 LeaderChangedException (herddb.client.impl.LeaderChangedException)1 RetryRequestException (herddb.client.impl.RetryRequestException)1 UnreachableServerException (herddb.client.impl.UnreachableServerException)1 Channel (herddb.network.Channel)1 DataStorageManagerException (herddb.storage.DataStorageManagerException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 TimeoutException (java.util.concurrent.TimeoutException)1