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