use of org.apache.curator.CuratorConnectionLossException in project xian by happyyangyuan.
the class CuratorFrameworkImpl method performBackgroundOperation.
private void performBackgroundOperation(OperationAndData<?> operationAndData) {
try {
if (client.isConnected()) {
operationAndData.callPerformBackgroundOperation();
} else {
// important - allow connection resets, timeouts, etc. to occur
client.getZooKeeper();
if (operationAndData.getElapsedTimeMs() >= client.getConnectionTimeoutMs()) {
throw new CuratorConnectionLossException();
}
operationAndData.sleepFor(1, TimeUnit.SECONDS);
queueOperation(operationAndData);
}
} catch (Throwable e) {
ThreadUtils.checkInterrupted(e);
/**
* Fix edge case reported as CURATOR-52. ConnectionState.checkTimeouts() throws KeeperException.ConnectionLossException
* when the initial (or previously failed) connection cannot be re-established. This needs to be run through the retry policy
* and callbacks need to get invoked, etc.
*/
if (e instanceof CuratorConnectionLossException) {
WatchedEvent watchedEvent = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState.Disconnected, null);
CuratorEvent event = new CuratorEventImpl(this, CuratorEventType.WATCHED, KeeperException.Code.CONNECTIONLOSS.intValue(), null, null, operationAndData.getContext(), null, null, null, watchedEvent, null);
if (checkBackgroundRetry(operationAndData, event)) {
queueOperation(operationAndData);
} else {
logError("Background retry gave up", e);
}
} else {
handleBackgroundOperationException(operationAndData, e);
}
}
}
use of org.apache.curator.CuratorConnectionLossException in project fabric8 by jboss-fuse.
the class CuratorFrameworkImpl method performBackgroundOperation.
private void performBackgroundOperation(OperationAndData<?> operationAndData) {
try {
if (client.isConnected()) {
operationAndData.callPerformBackgroundOperation();
} else {
// important - allow connection resets, timeouts, etc. to occur
client.getZooKeeper();
if (operationAndData.getElapsedTimeMs() >= client.getConnectionTimeoutMs()) {
throw new CuratorConnectionLossException();
}
operationAndData.sleepFor(1, TimeUnit.SECONDS);
queueOperation(operationAndData);
}
} catch (Throwable e) {
ThreadUtils.checkInterrupted(e);
/**
* Fix edge case reported as CURATOR-52. ConnectionState.checkTimeouts() throws KeeperException.ConnectionLossException
* when the initial (or previously failed) connection cannot be re-established. This needs to be run through the retry policy
* and callbacks need to get invoked, etc.
*/
if (e instanceof CuratorConnectionLossException) {
WatchedEvent watchedEvent = new WatchedEvent(Watcher.Event.EventType.None, Watcher.Event.KeeperState.Disconnected, null);
CuratorEvent event = new CuratorEventImpl(this, CuratorEventType.WATCHED, KeeperException.Code.CONNECTIONLOSS.intValue(), null, null, operationAndData.getContext(), null, null, null, watchedEvent, null);
if (checkBackgroundRetry(operationAndData, event)) {
queueOperation(operationAndData);
} else {
logError("Background retry gave up", e);
}
} else {
handleBackgroundOperationException(operationAndData, e);
}
}
}
Aggregations