X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FDeadlockMonitor.java;h=20e5fe658411f2b694885496b948217a4e59ef48;hb=refs%2Fchanges%2F73%2F46573%2F5;hp=b59b48e5a98eafb05d92622e1b1d9363c81f91a0;hpb=0a16f37f1baa4a2616e9b7289a445649b4f3132d;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java index b59b48e5a9..20e5fe6584 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/DeadlockMonitor.java @@ -1,17 +1,24 @@ -package org.opendaylight.controller.config.manager.impl; +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package org.opendaylight.controller.config.manager.impl; -import javax.annotation.Nullable; -import javax.annotation.concurrent.GuardedBy; import java.util.Deque; import java.util.LinkedList; import java.util.concurrent.TimeUnit; +import javax.annotation.Nullable; +import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DeadlockMonitor implements AutoCloseable { - private static final Logger LOGGER = LoggerFactory.getLogger(DeadlockMonitorRunnable.class); + private static final Logger LOG = LoggerFactory.getLogger(DeadlockMonitor.class); private static final long WARN_AFTER_MILLIS = 5000; @@ -20,7 +27,7 @@ public class DeadlockMonitor implements AutoCloseable { @GuardedBy("this") private final Deque moduleIdentifierWithNanosStack = new LinkedList<>(); @GuardedBy("this") - private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.EMPTY; + private ModuleIdentifierWithNanos top = ModuleIdentifierWithNanos.empty; public DeadlockMonitor(TransactionIdentifier transactionIdentifier) { this.transactionIdentifier = transactionIdentifier; @@ -34,7 +41,7 @@ public class DeadlockMonitor implements AutoCloseable { if (popping) { moduleIdentifierWithNanosStack.pop(); if (moduleIdentifierWithNanosStack.isEmpty()) { - top = ModuleIdentifierWithNanos.EMPTY; + top = ModuleIdentifierWithNanos.empty; } else { top = moduleIdentifierWithNanosStack.peekLast(); } @@ -43,7 +50,7 @@ public class DeadlockMonitor implements AutoCloseable { moduleIdentifierWithNanosStack.push(current); top = current; } - LOGGER.trace("setCurrentlyInstantiatedModule {}, top {}", currentlyInstantiatedModule, top); + LOG.trace("setCurrentlyInstantiatedModule {}, top {}", currentlyInstantiatedModule, top); } public boolean isAlive() { @@ -68,26 +75,31 @@ public class DeadlockMonitor implements AutoCloseable { @Override public void run() { - ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); // null moduleId - while (this.isInterrupted() == false) { - ModuleIdentifierWithNanos copy = new ModuleIdentifierWithNanos(DeadlockMonitor.this.top); - if (old.moduleIdentifier == null || old.equals(copy) == false) { + // null moduleId + ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); + while (!this.isInterrupted()) { + ModuleIdentifierWithNanos copy; + synchronized(this) { + copy = new ModuleIdentifierWithNanos(DeadlockMonitor.this.top); + } + + if (old.moduleIdentifier == null || !old.equals(copy)) { // started old = copy; } else { // is the getInstance() running longer than WARN_AFTER_MILLIS ? long runningTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - copy.nanoTime); if (runningTime > WARN_AFTER_MILLIS) { - LOGGER.warn("{} did not finish after {} ms", copy.moduleIdentifier, runningTime); + LOG.warn("{} did not finish after {} ms", copy.moduleIdentifier, runningTime); } } try { - sleep(1000); + sleep(WARN_AFTER_MILLIS); } catch (InterruptedException e) { interrupt(); } } - LOGGER.trace("Exiting {}", this); + LOG.trace("Exiting {}", this); } @Override @@ -96,11 +108,8 @@ public class DeadlockMonitor implements AutoCloseable { } } - - - private static class ModuleIdentifierWithNanos { - private static ModuleIdentifierWithNanos EMPTY = new ModuleIdentifierWithNanos(); + private static ModuleIdentifierWithNanos empty = new ModuleIdentifierWithNanos(); @Nullable private final ModuleIdentifier moduleIdentifier;