use of io.nosqlbench.nb.api.annotations.Annotator in project nosqlbench by nosqlbench.
the class Annotators method init.
/**
* Initialize the active annotators. This method must be called before any others.
*
* @param annotatorsConfig A (possibly empty) set of annotator configurations, in any form
* supported by {@link ConfigLoader}
*/
public static synchronized void init(String annotatorsConfig) {
ConfigLoader loader = new ConfigLoader();
annotators = new ArrayList<>();
LinkedHashMap<String, ServiceLoader.Provider<Annotator>> providers = getProviders();
List<Map> configs = loader.load(annotatorsConfig, Map.class);
if (configs != null) {
for (Map cmap : configs) {
Object typeObj = cmap.remove("type");
String typename = typeObj.toString();
ServiceLoader.Provider<Annotator> annotatorProvider = providers.get(typename);
if (annotatorProvider == null) {
throw new RuntimeException("Annotation provider with selector '" + typename + "' was not found.");
}
Annotator annotator = annotatorProvider.get();
if (annotator instanceof NBMapConfigurable) {
NBMapConfigurable NBMapConfigurable = (NBMapConfigurable) annotator;
NBMapConfigurable.applyConfig(cmap);
}
if (annotator instanceof NBConfigurable) {
NBConfigurable nbConfigurable = (NBConfigurable) annotator;
NBConfiguration cfg = nbConfigurable.getConfigModel().apply(cmap);
nbConfigurable.applyConfig(cfg);
}
annotators.add(annotator);
}
}
logger.debug("Initialized " + Annotators.annotators.size() + " annotators, since the configuration is empty.");
}
use of io.nosqlbench.nb.api.annotations.Annotator in project nosqlbench by nosqlbench.
the class Annotators method getProviders.
private static synchronized LinkedHashMap<String, ServiceLoader.Provider<Annotator>> getProviders() {
ServiceLoader<Annotator> loader = ServiceLoader.load(Annotator.class);
LinkedHashMap<String, ServiceLoader.Provider<Annotator>> providers;
providers = new LinkedHashMap<>();
loader.stream().forEach(provider -> {
Class<? extends Annotator> type = provider.type();
if (!type.isAnnotationPresent(Service.class)) {
throw new RuntimeException("Annotator services must be annotated with distinct selectors\n" + "such as @Service(Annotator.class,selector=\"myimpl42\")");
}
Service service = type.getAnnotation(Service.class);
providers.put(service.selector(), provider);
});
return providers;
}
use of io.nosqlbench.nb.api.annotations.Annotator in project nosqlbench by nosqlbench.
the class Annotators method recordAnnotation.
public static synchronized void recordAnnotation(Annotation annotation) {
for (Annotator annotator : getAnnotators()) {
try {
logger.trace("calling annotator " + annotator.getClass().getAnnotation(Service.class).selector());
annotator.recordAnnotation(annotation);
} catch (Exception e) {
logger.error(e);
}
}
}
Aggregations