public ReferenceStorageEngine getEngine(StorageEngineConfig engineConfig) throws SetupException{
ReferenceStorageEngine engine = activeEngines.get(engineConfig);
if(engine != null) return engine;
Constructor<? extends ReferenceStorageEngine> c = availableEngines.get(engineConfig.getClass());
if(c == null) throw new SetupException(String.format("Failure finding StorageEngine constructor for config %s", engineConfig));
try {
engine = c.newInstance(engineConfig, config);
activeEngines.put(engineConfig,engine);
return engine;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
Throwable t = e instanceof InvocationTargetException ? ((InvocationTargetException)e).getTargetException() : e;
if(t instanceof SetupException) throw ((SetupException) t);
throw new SetupException(String.format("Failure setting up new storage engine configuration for config %s", engineConfig), t);
}
}