use of io.gravitee.repository.Scope in project gravitee-gateway by gravitee-io.
the class RepositoryPluginHandler method handle.
@Override
public void handle(Plugin plugin) {
try {
ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin, this.getClass().getClassLoader());
final Class<?> repositoryClass = classloader.loadClass(plugin.clazz());
LOGGER.info("Register a new repository plugin: {} [{}]", plugin.id(), plugin.clazz());
Assert.isAssignable(Repository.class, repositoryClass);
Repository repository = createInstance((Class<Repository>) repositoryClass);
for (Scope scope : repository.scopes()) {
if (!repositories.containsKey(scope)) {
String requiredRepositoryType = repositoryTypeByScope.get(scope);
// Load only repository plugin for a given scope (provided in the configuration)
if (repository.type().equalsIgnoreCase(requiredRepositoryType)) {
LOGGER.info("Repository [{}] loaded by {}", scope, repository.type());
// Not yet loaded, let's mount the repository in application context
try {
ApplicationContext repoApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) {
@Override
public Set<Class<?>> configurations() {
return Collections.singleton(repository.configuration(scope));
}
});
registerRepositoryDefinitions(repository, repoApplicationContext);
repositories.put(scope, repository);
} catch (Exception iae) {
LOGGER.error("Unexpected error while creating context for repository instance", iae);
pluginContextFactory.remove(plugin);
}
} else {
LOGGER.debug("Scoped repository [{}] must be loaded by {}. Skipping registration", scope, requiredRepositoryType);
}
} else {
LOGGER.warn("Repository scope {} already loaded by {}", scope, repositories.get(scope));
}
}
} catch (Exception iae) {
LOGGER.error("Unexpected error while create repository instance", iae);
}
}
use of io.gravitee.repository.Scope in project gravitee-management-rest-api by gravitee-io.
the class RepositoryPluginHandler method handle.
@Override
public void handle(Plugin plugin) {
try {
ClassLoader classloader = pluginClassLoaderFactory.getOrCreateClassLoader(plugin, this.getClass().getClassLoader());
final Class<?> repositoryClass = classloader.loadClass(plugin.clazz());
LOGGER.info("Register a new repository: {} [{}]", plugin.id(), plugin.clazz());
Assert.isAssignable(Repository.class, repositoryClass);
Repository repository = createInstance((Class<Repository>) repositoryClass);
Collection<Scope> scopes = scopeByRepositoryType.getOrDefault(repository.type(), Collections.EMPTY_LIST);
for (Scope scope : scopes) {
if (!repositories.containsKey(scope)) {
// Not yet loaded, let's mount the repository in application context
try {
ApplicationContext applicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) {
@Override
public Set<Class<?>> configurations() {
return Collections.singleton(repository.configuration(scope));
}
});
registerRepositoryDefinitions(repository, applicationContext);
repositories.put(scope, repository);
} catch (Exception iae) {
LOGGER.error("Unexpected error while creating context for repository instance", iae);
pluginContextFactory.remove(plugin);
}
} else {
LOGGER.warn("Repository scope {} already loaded by {}", scope, repositories.get(scope));
}
}
} catch (Exception iae) {
LOGGER.error("Unexpected error while create repository instance", iae);
}
}
Aggregations