Search in sources :

Example 16 with Configuration

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();
        }
    }
}
Also used : Configuration(org.exist.config.Configuration) MethodHandles(java.lang.invoke.MethodHandles) Function(java.util.function.Function) LockException(org.exist.util.LockException) PermissionDeniedException(org.exist.security.PermissionDeniedException) TriggerException(org.exist.collections.triggers.TriggerException) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

Configuration (org.exist.config.Configuration)16 DocumentImpl (org.exist.dom.persistent.DocumentImpl)5 InputStream (java.io.InputStream)4 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)3 Database (org.exist.Database)3 ConfigurationException (org.exist.config.ConfigurationException)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 AccountImpl (org.exist.security.internal.AccountImpl)3 Test (org.junit.Test)3 MethodHandle (java.lang.invoke.MethodHandle)2 MethodHandles (java.lang.invoke.MethodHandles)2 EXistException (org.exist.EXistException)2 Collection (org.exist.collections.Collection)2 AbstractRealm (org.exist.security.AbstractRealm)2 AuthenticationException (org.exist.security.AuthenticationException)2 Realm (org.exist.security.realm.Realm)2 BrokerPoolServiceException (org.exist.storage.BrokerPoolServiceException)2 DBBroker (org.exist.storage.DBBroker)2 AtomicLazyVal (com.evolvedbinary.j8fu.lazy.AtomicLazyVal)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1