import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.applications.frsync.SemaphoreKeeper;
import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
+import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
}
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
- final FlowCapableNode configTree, final FlowCapableNode operationalTree,
- final LogicalDatastoreType dsType) throws InterruptedException {
+ final SyncupEntry syncupEntry) throws InterruptedException {
final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
- LOG.trace("syncup guard {}", nodeId.getValue());
+ LOG.trace("syncup guard decorator: {}", nodeId.getValue());
final long stampBeforeGuard = System.nanoTime();
final Semaphore guard = summonGuardAndAcquire(flowcapableNodePath);
}
final ListenableFuture<Boolean> endResult =
- delegate.syncup(flowcapableNodePath, configTree, operationalTree, dsType);
-
- Futures.addCallback(endResult, new FutureCallback<Boolean>() {
- @Override
- public void onSuccess(@Nullable final Boolean result) {
- if (LOG.isDebugEnabled()) {
- final long stampFinished = System.nanoTime();
- LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
- formatNanos(stampFinished - stampBeforeGuard),
- formatNanos(stampFinished - stampAfterGuard),
- formatNanos(stampAfterGuard - stampBeforeGuard),
- guard.availablePermits(), threadName());
- }
-
- releaseGuardForNodeId(guard);
- }
+ delegate.syncup(flowcapableNodePath, syncupEntry);
- @Override
- public void onFailure(final Throwable t) {
- if (LOG.isDebugEnabled()) {
- final long stampFinished = System.nanoTime();
- LOG.warn("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
- formatNanos(stampFinished - stampBeforeGuard),
- formatNanos(stampFinished - stampAfterGuard),
- formatNanos(stampAfterGuard - stampBeforeGuard),
- guard.availablePermits(), threadName());
- }
-
- releaseGuardForNodeId(guard);
- }
- });
+ Futures.addCallback(endResult, createSyncupCallback(guard, stampBeforeGuard, stampAfterGuard, nodeId));
return endResult;
} catch (InterruptedException e) {
releaseGuardForNodeId(guard);
}
}
- private String formatNanos(long nanos) {
+ private static FutureCallback<Boolean> createSyncupCallback(final Semaphore guard,
+ final long stampBeforeGuard,
+ final long stampAfterGuard,
+ final NodeId nodeId) {
+ return new FutureCallback<Boolean>() {
+ @Override
+ public void onSuccess(@Nullable final Boolean result) {
+ if (LOG.isDebugEnabled()) {
+ final long stampFinished = System.nanoTime();
+ LOG.debug("syncup finished {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+ formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+ formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+ }
+ releaseGuardForNodeId(guard);
+ }
+ @Override
+ public void onFailure(final Throwable t) {
+ final long stampFinished = System.nanoTime();
+ LOG.error("syncup failed {} took:{} rpc:{} wait:{} guard:{} permits thread:{}", nodeId.getValue(),
+ formatNanos(stampFinished - stampBeforeGuard), formatNanos(stampFinished - stampAfterGuard),
+ formatNanos(stampAfterGuard - stampBeforeGuard), guard.availablePermits(), threadName());
+ releaseGuardForNodeId(guard);
+ }};
+ }
+
+ private static String formatNanos(long nanos) {
return "'" + TimeUnit.NANOSECONDS.toMillis(nanos) + " ms'";
}
* Unlock and release guard.
* @param guard semaphore guard which should be unlocked
*/
- private void releaseGuardForNodeId(final Semaphore guard) {
+ private static void releaseGuardForNodeId(final Semaphore guard) {
if (guard != null) {
guard.release();
LOG.trace("syncup release guard:{} thread:{}", guard, threadName());