summaryrefslogtreecommitdiffstats
path: root/component
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-02-04 07:41:31 +0100
committerGitHub <noreply@github.com>2020-02-04 07:41:31 +0100
commit72cd1c70fdbe01968ef5a6ed6e05f5fa0ba4d319 (patch)
tree1552b25d1eb0233bfb1cdc8c36adf8190302af52 /component
parent17e572d4dad3c9e5040544072dbdc9f7a703e7bd (diff)
Revert "Bratseth/anonymous query profile types take 2"
Diffstat (limited to 'component')
-rw-r--r--component/abi-spec.json1
-rw-r--r--component/src/main/java/com/yahoo/component/ComponentId.java49
2 files changed, 23 insertions, 27 deletions
diff --git a/component/abi-spec.json b/component/abi-spec.json
index cd42b8ff95a..a6b6a558db6 100644
--- a/component/abi-spec.json
+++ b/component/abi-spec.json
@@ -73,7 +73,6 @@
"public static com.yahoo.component.ComponentId fromString(java.lang.String)",
"public java.lang.String toFileName()",
"public static com.yahoo.component.ComponentId fromFileName(java.lang.String)",
- "public static void resetGlobalCountersForTests()",
"public bridge synthetic int compareTo(java.lang.Object)"
],
"fields": []
diff --git a/component/src/main/java/com/yahoo/component/ComponentId.java b/component/src/main/java/com/yahoo/component/ComponentId.java
index 4613be09543..05c710e3fc1 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<ComponentId> {
private int count = 0;
public int getAndIncrement() { return count++; }
}
- private static ThreadLocal<Counter> threadLocalUniqueId = new ThreadLocal<Counter>() {
+ private static ThreadLocal<Counter> gid = new ThreadLocal<Counter>() {
@Override protected Counter initialValue() {
return new Counter();
}
};
- private static AtomicInteger threadIdCounter = new AtomicInteger(0);
- private static ThreadLocal<String> threadId = new ThreadLocal<String>() {
+ private static AtomicInteger uniqueTid = new AtomicInteger(0);
+ private static ThreadLocal<String> tid = new ThreadLocal<String>() {
@Override protected String initialValue() {
- return new String("_" + threadIdCounter.getAndIncrement() + "_");
+ return new String("_"+uniqueTid.getAndIncrement()+"_");
}
};
@@ -58,7 +58,7 @@ public final class ComponentId implements Comparable<ComponentId> {
}
private String createAnonymousName(String name) {
- return new StringBuilder(name).append(threadId.get()).append(threadLocalUniqueId.get().getAndIncrement()).toString();
+ return new StringBuilder(name).append(tid.get()).append(gid.get().getAndIncrement()).toString();
}
public ComponentId(String name, Version version, ComponentId namespace) {
@@ -148,7 +148,10 @@ public final class ComponentId implements Comparable<ComponentId> {
return spec.compareTo(other.spec);
}
- /** Creates a componentId that is unique for this run-time instance */
+ /**
+ * Creates a componentId that is unique for this run-time instance
+ */
+ // TODO: Check if we really need this. -JB
public static ComponentId createAnonymousComponentId(String baseName) {
return new ComponentId(baseName, null, null, true);
}
@@ -193,27 +196,27 @@ public final class ComponentId implements Comparable<ComponentId> {
* Creates an id from a file <b>first</b> name string encoded in the standard translation (see {@link #toFileName}).
* <b>Note</b> that any file last name, like e.g ".xml" must be stripped off before handoff to this method.
*/
- public static ComponentId fromFileName(String fileName) {
+ public static ComponentId fromFileName(final 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
@@ -226,10 +229,4 @@ public final class ComponentId implements Comparable<ComponentId> {
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());
- }
-
}