use of org.exist.config.Configuration in project exist by eXist-db.
the class PluginsManagerImpl method start.
@Override
public void start(final DBBroker broker, final Txn transaction) throws EXistException {
boolean interrupted = false;
try {
try {
collection = broker.getCollection(COLLETION_URI);
if (collection == null) {
collection = broker.getOrCreateCollection(transaction, COLLETION_URI);
if (collection == null) {
return;
}
// if db corrupted it can lead to unrunnable issue
// throw new ConfigurationException("Collection '/db/system/plugins' can't be created.");
collection.setPermissions(broker, Permission.DEFAULT_SYSTEM_SECURITY_COLLECTION_PERM);
broker.saveCollection(transaction, collection);
}
} catch (final TriggerException | PermissionDeniedException | IOException | LockException e) {
LOG.warn("Loading PluginsManager configuration failed: {}", e.getMessage());
}
final Configuration _config_ = Configurator.parse(this, broker, collection, CONFIG_FILE_URI);
configuration = Configurator.configure(this, _config_);
// load plugins by META-INF/services/
try {
final MethodHandles.Lookup lookup = MethodHandles.lookup();
for (final Class<? extends Plug> pluginClazz : listServices(Plug.class)) {
try {
final MethodHandle methodHandle = lookup.findConstructor(pluginClazz, methodType(void.class, PluginsManager.class));
final Function<PluginsManager, Plug> ctor = (Function<PluginsManager, Plug>) LambdaMetafactory.metafactory(lookup, "apply", methodType(Function.class), methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact();
final Plug plgn = ctor.apply(this);
jacks.put(pluginClazz.getName(), plgn);
} catch (final Throwable e) {
if (e instanceof InterruptedException) {
// NOTE: must set interrupted flag
interrupted = true;
}
LOG.error(e);
}
}
} catch (final Throwable e) {
LOG.error(e);
}
for (final Plug jack : jacks.values()) {
jack.start(broker, transaction);
}
} finally {
if (interrupted) {
// NOTE: must set interrupted flag
Thread.currentThread().interrupt();
}
}
}
Aggregations