io.nosqlbench.engine.api.activityimpl.CoreServices Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of engine-api Show documentation
Show all versions of engine-api Show documentation
The engine API for nosqlbench;
Provides the interfaces needed to build internal modules for the
nosqlbench core engine
/*
*
* Copyright 2016 jshook
* 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.
* /
*/
package io.nosqlbench.engine.api.activityimpl;
import io.nosqlbench.engine.api.activityapi.core.Activity;
import io.nosqlbench.engine.api.activityapi.cyclelog.buffers.results.ResultReadable;
import io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultFilterDispenser;
import io.nosqlbench.engine.api.activityapi.cyclelog.filters.ResultValueFilterType;
import io.nosqlbench.engine.api.activityapi.input.InputDispenser;
import io.nosqlbench.engine.api.activityapi.input.InputType;
import io.nosqlbench.engine.api.activityapi.output.OutputDispenser;
import io.nosqlbench.engine.api.activityapi.output.OutputType;
import io.nosqlbench.engine.api.util.SimpleConfig;
import java.util.Optional;
import java.util.function.Predicate;
public class CoreServices {
public static Optional getOutputDispenser(A activity) {
OutputDispenser outputDispenser = new SimpleConfig(activity, "output").getString("type")
.flatMap(OutputType.FINDER::get)
.map(mt -> mt.getOutputDispenser(activity)).orElse(null);
if (outputDispenser==null) {
return Optional.empty();
}
Optional> outputFilterDispenser = getOutputFilter(activity);
if (outputFilterDispenser.isPresent()) {
outputDispenser = new FilteringOutputDispenser(outputDispenser, outputFilterDispenser.get());
}
return Optional.ofNullable(outputDispenser);
}
public static Optional> getOutputFilter(A activity) {
String paramdata= activity.getParams().getOptionalString("of")
.orElse(activity.getParams().getOptionalString("outputfilter").orElse(null));
if (paramdata==null) {
return Optional.empty();
}
return getFilterPredicate(paramdata);
}
// public static Optional getResultFilterDispenser(A activity) {
// Optional intPredicateDispenser = new SimpleConfig(activity, "resultfilter")
// .getString("type")
// .flatMap(ExperimentalResultFilterType.FINDER::get)
// .map(rft -> rft.getFilterDispenser(activity));
// return intPredicateDispenser;
// }
//
public static InputDispenser getInputDispenser(A activity) {
String inputTypeName = new SimpleConfig(activity, "input").getString("type").orElse("atomicseq");
InputType inputType = InputType.FINDER.getOrThrow(inputTypeName);
InputDispenser dispenser = inputType.getInputDispenser(activity);
Optional> inputFilterDispenser = getInputFilter(activity);
if (inputFilterDispenser.isPresent()) {
dispenser = new FilteringInputDispenser(dispenser, inputFilterDispenser.get());
}
return dispenser;
}
public static Optional> getInputFilter(A activity) {
String paramdata= activity.getParams().getOptionalString("if")
.orElse(activity.getParams().getOptionalString("inputfilter").orElse(null));
if (paramdata==null) {
return Optional.empty();
}
return getFilterPredicate(paramdata);
}
private static Optional> getFilterPredicate(String paramdata) {
String type = new SimpleConfig(paramdata).getString("type").orElse("core");
Optional cycleResultFilterType = ResultValueFilterType.FINDER.get(type);
Optional crfd = cycleResultFilterType.map(crft -> crft.getDispenser(paramdata));
Optional> predicate = crfd.map(ResultFilterDispenser::getResultFilter);
return predicate;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy