io.nosqlbench.virtdata.api.ContextualMapBindings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of virtdata-lib-curves4 Show documentation
Show all versions of virtdata-lib-curves4 Show documentation
Statistical sampling library for use in virtdata libraries, based
on apache commons math 4
package io.nosqlbench.virtdata.api;
import java.util.HashMap;
import java.util.Map;
/**
* A thread-local template that describes a set of data mappers, a context object, and a method for applying
* mapped values to the context object via a String-Object map. This type is used in thread-local scope to map thread-specific
* data mapper instances to a contextual template object and a method for applying mapped values to it.
*
* This type is generally constructed by a ContextualBindingsTemplate.
*
* @param The type of the contextual template object.
* @param The resulting type from binding mapped values with the contextual template C
*/
public class ContextualMapBindings implements Binder {
private final C context;
private Bindings bindings;
private ValuesMapBinder valuesMapBinder;
public ContextualMapBindings(Bindings bindings, C context, ValuesMapBinder valuesMapBinder) {
this.bindings = bindings;
this.context = context;
this.valuesMapBinder = valuesMapBinder;
}
public Bindings getBindings() {
return bindings;
}
public C getContext() {
return context;
}
@Override
public R bind(long value) {
Map generatedValues = new HashMap();
bindings.setMap(generatedValues, value);
try { // Provide bindings context data where it may be useful
return valuesMapBinder.bindValues(context, generatedValues);
} catch (Exception e) {
throw new RuntimeException("Binding error:" + bindings.getTemplate().toString() + ": " + generatedValues, e);
}
}
}