From 0119ad27079ff069832c81dae98292a9e024c403 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 5 Feb 2020 08:43:41 +0100 Subject: Revert "Merge pull request #12060 from vespa-engine/revert-12040-bratseth/anonymous-query-profile-types-take-2" This reverts commit 558506aa9008c5255f849892f476c819391f06a7, reversing changes made to 17e572d4dad3c9e5040544072dbdc9f7a703e7bd. --- .../main/java/com/yahoo/component/ComponentId.java | 49 ++++++++++++---------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'component/src') diff --git a/component/src/main/java/com/yahoo/component/ComponentId.java b/component/src/main/java/com/yahoo/component/ComponentId.java index 05c710e3fc1..4613be09543 100644 --- a/component/src/main/java/com/yahoo/component/ComponentId.java +++ b/component/src/main/java/com/yahoo/component/ComponentId.java @@ -32,15 +32,15 @@ public final class ComponentId implements Comparable { private int count = 0; public int getAndIncrement() { return count++; } } - private static ThreadLocal gid = new ThreadLocal() { + private static ThreadLocal threadLocalUniqueId = new ThreadLocal() { @Override protected Counter initialValue() { return new Counter(); } }; - private static AtomicInteger uniqueTid = new AtomicInteger(0); - private static ThreadLocal tid = new ThreadLocal() { + private static AtomicInteger threadIdCounter = new AtomicInteger(0); + private static ThreadLocal threadId = new ThreadLocal() { @Override protected String initialValue() { - return new String("_"+uniqueTid.getAndIncrement()+"_"); + return new String("_" + threadIdCounter.getAndIncrement() + "_"); } }; @@ -58,7 +58,7 @@ public final class ComponentId implements Comparable { } private String createAnonymousName(String name) { - return new StringBuilder(name).append(tid.get()).append(gid.get().getAndIncrement()).toString(); + return new StringBuilder(name).append(threadId.get()).append(threadLocalUniqueId.get().getAndIncrement()).toString(); } public ComponentId(String name, Version version, ComponentId namespace) { @@ -148,10 +148,7 @@ public final class ComponentId implements Comparable { return spec.compareTo(other.spec); } - /** - * Creates a componentId that is unique for this run-time instance - */ - // TODO: Check if we really need this. -JB + /** Creates a componentId that is unique for this run-time instance */ public static ComponentId createAnonymousComponentId(String baseName) { return new ComponentId(baseName, null, null, true); } @@ -196,27 +193,27 @@ public final class ComponentId implements Comparable { * Creates an id from a file first name string encoded in the standard translation (see {@link #toFileName}). * Note that any file last name, like e.g ".xml" must be stripped off before handoff to this method. */ - public static ComponentId fromFileName(final String fileName) { + public static ComponentId fromFileName(String fileName) { // Initial assumptions - String id=fileName; - Version version =null; - ComponentId namespace=null; + String id = fileName; + Version version = null; + ComponentId namespace = null; // Split out namespace, if any - int at=id.indexOf("@"); - if (at>0) { - String newId=id.substring(0,at); - namespace=ComponentId.fromString(id.substring(at+1)); - id=newId; + int at = id.indexOf("@"); + if (at > 0) { + String newId = id.substring(0, at); + namespace = ComponentId.fromString(id.substring(at + 1)); + id = newId; } // Split out version, if any - int dash=id.lastIndexOf("-"); - if (dash>0) { - String newId=id.substring(0,dash); + int dash = id.lastIndexOf("-"); + if (dash > 0) { + String newId = id.substring(0, dash); try { - version=new Version(id.substring(dash+1)); - id=newId; + version = new Version(id.substring(dash + 1)); + id = newId; } catch (IllegalArgumentException e) { // don't interpret the text following the dash as a version @@ -229,4 +226,10 @@ public final class ComponentId implements Comparable { return new ComponentId(id,version,namespace); } + /** WARNING: For testing only: Resets counters creating anonymous component ids for this thread. */ + public static void resetGlobalCountersForTests() { + threadId.set("_0_"); + threadLocalUniqueId.set(new Counter()); + } + } -- cgit v1.2.3