List of usage examples for org.apache.zookeeper.recipes.lock ZooKeeperOperation execute
boolean execute() throws KeeperException, InterruptedException;
From source file:com.zookeeper.lyt.lock.ProtocolSupport.java
License:Apache License
/** * Perform the given operation, retrying if the connection fails * @return object. it needs to be cast to the callee's expected * return type./*from ww w .j ava2 s . c o m*/ */ protected Object retryOperation(ZooKeeperOperation operation) throws KeeperException, InterruptedException { KeeperException exception = null; for (int i = 0; i < retryCount; i++) { try { return operation.execute(); } catch (KeeperException.SessionExpiredException e) { LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e); throw e; } catch (KeeperException.ConnectionLossException e) { if (exception == null) { exception = e; } LOG.debug("Attempt " + i + " failed with connection loss so " + "attempting to reconnect: " + e, e); retryDelay(i); } } throw exception; }