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();
}
}
Aggregations