extends NBComponent {
/**
*
@@ -101,7 +102,7 @@ public interface DriverAdapter extends NBComponent
*
* @return a synthesizer function for {@link OPTYPE} op generation
*/
- OpMapper getOpMapper();
+ OpMapper getOpMapper();
/**
* The preprocessor function allows the driver adapter to remap
@@ -159,7 +160,7 @@ public interface DriverAdapter extends NBComponent
* @return A function which can initialize a new Space, which is a place to hold
* object state related to retained objects for the lifetime of a native driver.
*/
- default Function getSpaceInitializer(NBConfiguration cfg) {
+ default LongFunction getSpaceInitializer(NBConfiguration cfg) {
return n -> null;
}
diff --git a/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/activityimpl/uniform/Space.java b/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/activityimpl/uniform/Space.java
new file mode 100644
index 000000000..6ee1961cb
--- /dev/null
+++ b/nb-apis/adapters-api/src/main/java/io/nosqlbench/adapters/api/activityimpl/uniform/Space.java
@@ -0,0 +1,37 @@
+package io.nosqlbench.adapters.api.activityimpl.uniform;
+
+/*
+ * Copyright (c) 2022 nosqlbench
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import io.nosqlbench.nb.api.components.core.NBNamedElement;
+
+/**
+ * A space is simply a separate namespace associated with an instance of a
+ * native client or driver. This allows for the emulation of many clients
+ * in testing scenarios. Within the operations for an adapter, the space
+ * may be needed, for example, to construct prepared statements, or other
+ * 'session-attached' objects. Put any state that you would normally
+ * associate with an instance of a native driver into a space, and use
+ * the {@link DriverAdapter#getSpaceCache()} to access it when needed.
+ */
+public interface Space extends NBNamedElement, AutoCloseable {
+
+ @Override
+ default void close() throws Exception {
+ }
+}
diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java
index 4765f161f..c841f47cb 100644
--- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java
+++ b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/SimpleActivity.java
@@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityconfig.yaml.OpsDocList;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpMapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
+import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
@@ -58,6 +59,7 @@ import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
+import java.util.function.LongFunction;
/**
* A default implementation of an Activity, suitable for building upon.
@@ -395,7 +397,7 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
protected OpSequence> createOpSourceFromParsedOps(
// Map> adapterCache,
// Map> mapperCache,
- List> adapters,
+ List> adapters,
List pops
) {
try {
@@ -424,10 +426,10 @@ public class SimpleActivity extends NBStatusComponent implements Activity, Invok
continue;
}
- DriverAdapter, ?> adapter = adapters.get(i);
- OpMapper extends Op> opMapper = adapter.getOpMapper();
- OpDispenser extends Op> dispenser = opMapper.apply(pop);
-
+ DriverAdapter adapter = adapters.get(i);
+ OpMapper opMapper = adapter.getOpMapper();
+ LongFunction spaceFunc = adapter.getSpaceFunc(pop);
+ OpDispenser dispenser = opMapper.apply(pop, spaceFunc);
String dryrunSpec = pop.takeStaticConfigOr("dryrun", "none");
if ("op".equalsIgnoreCase(dryrunSpec)) {
dispenser = new DryRunOpDispenserWrapper((DriverAdapter) adapter, pop, dispenser);
diff --git a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/StandardActivity.java b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/StandardActivity.java
index d3154d15d..b2a297021 100644
--- a/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/StandardActivity.java
+++ b/nb-engine/nb-engine-core/src/main/java/io/nosqlbench/engine/api/activityimpl/uniform/StandardActivity.java
@@ -23,6 +23,7 @@ import io.nosqlbench.adapters.api.activityconfig.yaml.OpsDocList;
import io.nosqlbench.adapters.api.activityimpl.OpDispenser;
import io.nosqlbench.adapters.api.activityimpl.OpMapper;
import io.nosqlbench.adapters.api.activityimpl.uniform.DriverAdapter;
+import io.nosqlbench.adapters.api.activityimpl.uniform.Space;
import io.nosqlbench.adapters.api.activityimpl.uniform.decorators.SyntheticOpTemplateProvider;
import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.adapters.api.templating.ParsedOp;
@@ -62,7 +63,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class StandardActivity extends SimpleActivity implements SyntheticOpTemplateProvider, ActivityDefObserver {
private static final Logger logger = LogManager.getLogger("ACTIVITY");
private final OpSequence> sequence;
- private final ConcurrentHashMap> adapters = new ConcurrentHashMap<>();
+ private final ConcurrentHashMap> adapters = new ConcurrentHashMap<>();
public StandardActivity(NBComponent parent, ActivityDef activityDef) {
super(parent, activityDef);
@@ -92,11 +93,11 @@ public class StandardActivity extends SimpleActivity implements
List pops = new ArrayList<>();
- List> adapterlist = new ArrayList<>();
+ List> adapterlist = new ArrayList<>();
NBConfigModel supersetConfig = ConfigModel.of(StandardActivity.class).add(yamlmodel);
Optional defaultDriverOption = defaultDriverName;
- ConcurrentHashMap> mappers = new ConcurrentHashMap<>();
+ ConcurrentHashMap> mappers = new ConcurrentHashMap<>();
for (OpTemplate ot : opTemplates) {
// ParsedOp incompleteOpDef = new ParsedOp(ot, NBConfiguration.empty(), List.of(), this);
String driverName = ot.getOptionalStringParam("driver", String.class)
@@ -112,7 +113,7 @@ public class StandardActivity extends SimpleActivity implements
// HERE
if (!adapters.containsKey(driverName)) {
- DriverAdapter, ?> adapter = Optional.of(driverName)
+ DriverAdapter adapter = Optional.of(driverName)
.flatMap(
name -> ServiceSelector.of(
name,
@@ -144,7 +145,7 @@ public class StandardActivity extends SimpleActivity implements
supersetConfig.assertValidConfig(activityDef.getParams().getStringStringMap());
- DriverAdapter, ?> adapter = adapters.get(driverName);
+ DriverAdapter adapter = adapters.get(driverName);
adapterlist.add(adapter);
ParsedOp pop = new ParsedOp(ot, adapter.getConfiguration(), List.of(adapter.getPreprocessor()), this);
Optional discard = pop.takeOptionalStaticValue("driver", String.class);
@@ -261,19 +262,20 @@ public class StandardActivity extends SimpleActivity implements
*/
@Override
public void shutdownActivity() {
- for (Map.Entry> entry : adapters.entrySet()) {
+ for (Map.Entry> entry : adapters.entrySet()) {
String adapterName = entry.getKey();
DriverAdapter, ?> adapter = entry.getValue();
- adapter.getSpaceCache().getElements().forEach((spaceName, space) -> {
- if (space instanceof AutoCloseable autocloseable) {
+ for (Space space : adapter.getSpaceCache()) {
+ if (space instanceof AutoCloseable autoCloseable) {
try {
- autocloseable.close();
+ // TODO This should be invariant now, remove conditional?
+ autoCloseable.close();
} catch (Exception e) {
throw new RuntimeException("Error while shutting down state space for " +
- "adapter=" + adapterName + ", space=" + spaceName + ": " + e, e);
+ "adapter=" + adapterName + ", space=" + space.getName() + ": " + e, e);
}
}
- });
+ }
}
}