X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FDeadlockMonitor.java;h=cad98b30f4edd9a3f2689fd43bfa0a6127316103;hb=81674d6fd50b419b868d0851062e23f34b34557d;hp=9882b4662cce2b75519b509135fd17c961e12e9d;hpb=384479f0181763f3202f2f7ad681e90182bcc820;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 9882b4662c..cad98b30f4 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,5 +1,5 @@ /* - * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 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, @@ -27,21 +27,21 @@ 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) { + public DeadlockMonitor(final TransactionIdentifier transactionIdentifier) { this.transactionIdentifier = transactionIdentifier; thread = new DeadlockMonitorRunnable(); thread.start(); } - public synchronized void setCurrentlyInstantiatedModule(ModuleIdentifier currentlyInstantiatedModule) { + public synchronized void setCurrentlyInstantiatedModule(final ModuleIdentifier currentlyInstantiatedModule) { boolean popping = currentlyInstantiatedModule == null; if (popping) { moduleIdentifierWithNanosStack.pop(); if (moduleIdentifierWithNanosStack.isEmpty()) { - top = ModuleIdentifierWithNanos.EMPTY; + top = ModuleIdentifierWithNanos.empty; } else { top = moduleIdentifierWithNanosStack.peekLast(); } @@ -75,14 +75,15 @@ public class DeadlockMonitor implements AutoCloseable { @Override public void run() { - ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); // null moduleId - while (this.isInterrupted() == false) { + // null moduleId + ModuleIdentifierWithNanos old = new ModuleIdentifierWithNanos(); + while (!this.isInterrupted()) { ModuleIdentifierWithNanos copy; - synchronized(this) { + synchronized (this) { copy = new ModuleIdentifierWithNanos(DeadlockMonitor.this.top); } - if (old.moduleIdentifier == null || old.equals(copy) == false) { + if (old.moduleIdentifier == null || !old.equals(copy)) { // started old = copy; } else { @@ -94,7 +95,7 @@ public class DeadlockMonitor implements AutoCloseable { } try { sleep(WARN_AFTER_MILLIS); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { interrupt(); } } @@ -107,45 +108,43 @@ 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; private final long nanoTime; private ModuleIdentifierWithNanos() { - this((ModuleIdentifier)null); + this((ModuleIdentifier) null); } - private ModuleIdentifierWithNanos(ModuleIdentifier moduleIdentifier) { + private ModuleIdentifierWithNanos(final ModuleIdentifier moduleIdentifier) { this.moduleIdentifier = moduleIdentifier; nanoTime = System.nanoTime(); } - private ModuleIdentifierWithNanos(ModuleIdentifierWithNanos copy) { + private ModuleIdentifierWithNanos(final ModuleIdentifierWithNanos copy) { moduleIdentifier = copy.moduleIdentifier; nanoTime = copy.nanoTime; } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(final Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - ModuleIdentifierWithNanos that = (ModuleIdentifierWithNanos) o; + ModuleIdentifierWithNanos that = (ModuleIdentifierWithNanos) object; if (nanoTime != that.nanoTime) { return false; } - if (moduleIdentifier != null ? !moduleIdentifier.equals(that.moduleIdentifier) : that.moduleIdentifier != null) { + if (moduleIdentifier != null ? !moduleIdentifier.equals(that.moduleIdentifier) + : that.moduleIdentifier != null) { return false; } @@ -155,15 +154,13 @@ public class DeadlockMonitor implements AutoCloseable { @Override public int hashCode() { int result = moduleIdentifier != null ? moduleIdentifier.hashCode() : 0; - result = 31 * result + (int) (nanoTime ^ (nanoTime >>> 32)); + result = 31 * result + (int) (nanoTime ^ nanoTime >>> 32); return result; } @Override public String toString() { - return "ModuleIdentifierWithNanos{" + - moduleIdentifier + - '}'; + return "ModuleIdentifierWithNanos{" + moduleIdentifier + '}'; } } }