mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-12-23 23:50:28 -06:00
add typed Indexed property to fix ThreadNum
This commit is contained in:
parent
0013c9f411
commit
c04e3c0987
@ -18,6 +18,8 @@
|
||||
|
||||
package io.nosqlbench.engine.core.lifecycle;
|
||||
|
||||
import io.nosqlbench.nb.api.metadata.Indexed;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -36,7 +38,7 @@ public class IndexedThreadFactory implements ThreadFactory {
|
||||
this.uncaughtExceptionHandler = exceptionHandler;
|
||||
}
|
||||
|
||||
public class IndexedThread extends Thread {
|
||||
public class IndexedThread extends Thread implements Indexed {
|
||||
|
||||
private final int threadIndex;
|
||||
private String metricName = "default-name-" + Thread.currentThread().getName();
|
||||
@ -46,10 +48,6 @@ public class IndexedThreadFactory implements ThreadFactory {
|
||||
this.threadIndex = threadIndex;
|
||||
}
|
||||
|
||||
public int getThreadIndex() {
|
||||
return threadIndex;
|
||||
}
|
||||
|
||||
public void setMetricName(String metricName) {
|
||||
this.metricName = metricName;
|
||||
}
|
||||
@ -57,6 +55,11 @@ public class IndexedThreadFactory implements ThreadFactory {
|
||||
public String getMetricName() {
|
||||
return metricName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return threadIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,5 @@
|
||||
package io.nosqlbench.nb.api.metadata;
|
||||
|
||||
public interface Indexed {
|
||||
int getIndex();
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.nondeterministic.to_int;
|
||||
|
||||
import io.nosqlbench.nb.api.metadata.Indexed;
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
@ -41,6 +42,10 @@ public class ThreadNum implements LongToIntFunction {
|
||||
private final ThreadLocal<Integer> threadLocalInt = new ThreadLocal<Integer>() {
|
||||
@Override
|
||||
protected Integer initialValue() {
|
||||
if (Thread.currentThread() instanceof Indexed ) {
|
||||
return ((Indexed)Thread.currentThread()).getIndex();
|
||||
}
|
||||
|
||||
Matcher matcher = pattern.matcher(Thread.currentThread().getName());
|
||||
if (matcher.matches()) {
|
||||
return Integer.valueOf(matcher.group(1));
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package io.nosqlbench.virtdata.library.basics.shared.nondeterministic.to_long;
|
||||
|
||||
import io.nosqlbench.nb.api.metadata.Indexed;
|
||||
import io.nosqlbench.virtdata.api.annotations.Categories;
|
||||
import io.nosqlbench.virtdata.api.annotations.Category;
|
||||
import io.nosqlbench.virtdata.api.annotations.ThreadSafeMapper;
|
||||
@ -34,6 +35,10 @@ public class ThreadNum implements LongUnaryOperator {
|
||||
private final ThreadLocal<Long> threadLocalInt = new ThreadLocal<Long>() {
|
||||
@Override
|
||||
protected Long initialValue() {
|
||||
if (Thread.currentThread() instanceof Indexed) {
|
||||
return (long) ((Indexed)Thread.currentThread()).getIndex();
|
||||
}
|
||||
|
||||
Matcher matcher = pattern.matcher(Thread.currentThread().getName());
|
||||
if (matcher.matches()) {
|
||||
return Long.valueOf(matcher.group(1));
|
||||
|
Loading…
Reference in New Issue
Block a user