mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
streamline applying Stoppable
This commit is contained in:
parent
9fc0530c17
commit
996675f79d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 nosqlbench
|
||||
* Copyright (c) 2022-2023 nosqlbench
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -22,4 +22,12 @@ public interface Stoppable {
|
||||
* completes, the request will cause the component to stop cooperatively.
|
||||
*/
|
||||
void requestStop();
|
||||
|
||||
static void stop(Object... candidates) {
|
||||
for (Object candidate : candidates) {
|
||||
if (candidate instanceof Stoppable stoppable) {
|
||||
stoppable.requestStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -463,12 +463,7 @@ public class CoreMotor<D> implements ActivityDefObserver, Motor<D>, Stoppable {
|
||||
public synchronized void requestStop() {
|
||||
RunState currentState = motorState.get();
|
||||
if (Objects.requireNonNull(currentState) == Running) {
|
||||
if (input instanceof Stoppable) {
|
||||
((Stoppable) input).requestStop();
|
||||
}
|
||||
if (action instanceof Stoppable) {
|
||||
((Stoppable) action).requestStop();
|
||||
}
|
||||
Stoppable.stop(input, action);
|
||||
motorState.enterState(Stopping);
|
||||
} else {
|
||||
logger.warn(() -> "attempted to stop motor " + this.getSlotId() + ": from non Running state:" + currentState);
|
||||
|
@ -20,6 +20,8 @@ import io.nosqlbench.engine.api.activityapi.core.RunState;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A value type which encodes the atomic state of a RunState tally.
|
||||
*/
|
||||
@ -39,21 +41,43 @@ public class RunStateImage {
|
||||
}
|
||||
|
||||
public boolean is(RunState runState) {
|
||||
return counts[runState.ordinal()]>0;
|
||||
return counts[runState.ordinal()] > 0;
|
||||
}
|
||||
|
||||
public boolean isOnly(RunState runState) {
|
||||
for (int i = 0; i < counts.length; i++) {
|
||||
if (counts[i]>0 && i!=runState.ordinal()) {
|
||||
if (counts[i] > 0 && i != runState.ordinal()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isNonOther(RunState... runStates) {
|
||||
int[] scan = Arrays.copyOf(counts, counts.length);
|
||||
for (RunState runState : runStates) {
|
||||
scan[runState.ordinal()]=0;
|
||||
}
|
||||
for (int i : scan) {
|
||||
if (i>0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public RunState getMinState() {
|
||||
for (int ord = 0; ord < counts.length - 1; ord++) {
|
||||
if (counts[ord] > 0) {
|
||||
return RunState.values()[ord];
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("There were zero states, so min state is undefined");
|
||||
}
|
||||
|
||||
public RunState getMaxState() {
|
||||
for (int ord = counts.length-1; ord >= 0; ord--) {
|
||||
if (counts[ord]>0) {
|
||||
for (int ord = counts.length - 1; ord >= 0; ord--) {
|
||||
if (counts[ord] > 0) {
|
||||
return RunState.values()[ord];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user