LOG.trace("syncup guard {}", nodeId.getValue());
final long stampBeforeGuard = System.nanoTime();
- final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);//TODO handle InteruptedException
+ final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);
+ if (guard == null) {
+ return Futures.immediateFuture(false);
+ }
+ final long stampAfterGuard = System.nanoTime();
try {
- final long stampAfterGuard = System.nanoTime();
if (LOG.isDebugEnabled()) {
LOG.debug("syncup start {} waiting:{} guard:{} thread:{}", nodeId.getValue(),
formatNanos(stampAfterGuard - stampBeforeGuard),
}
final ListenableFuture<Boolean> endResult =
- delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);//TODO handle InteruptedException
+ delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);
Futures.addCallback(endResult, new FutureCallback<Boolean>() {
@Override
}
});
return endResult;
- } catch(InterruptedException e) {
+ } catch (InterruptedException e) {
releaseGuardForNodeId(guard);
throw e;
}
* @param flowcapableNodePath II of node for which guard should be acquired
* @return semaphore guard
*/
- private Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath)
- throws InterruptedException {
+ private Semaphore summonGuardAndAcquire(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath) {
+ final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
final Semaphore guard = Preconditions.checkNotNull(semaphoreKeeper.summonGuard(flowcapableNodePath),
- "no guard for " + flowcapableNodePath);
-
- if (LOG.isDebugEnabled()) {
- final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
- try {
- LOG.debug("syncup summon {} guard:{} thread:{}", nodeId.getValue(), guard, threadName());
- } catch (Exception e) {
- LOG.error("error logging guard after summon before aquiring {}", nodeId);
- }
+ "no guard for " + nodeId.getValue());
+ try {
+ guard.acquire();
+ } catch (InterruptedException e) {
+ LOG.error("syncup summon {} failed {}", nodeId.getValue(), e);
+ return null;
}
-
- guard.acquire();
+ LOG.trace("syncup summon {} guard:{} thread:{}", nodeId.getValue(), guard, threadName());
return guard;
}
* @param guard semaphore guard which should be unlocked
*/
private void releaseGuardForNodeId(final Semaphore guard) {
- if (guard == null) {
- return;
+ if (guard != null) {
+ guard.release();
+ LOG.trace("syncup release guard:{} thread:{}", guard, threadName());
}
- guard.release();
}
private static String threadName() {