All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jooby.internal.run.JoobyMultiModuleFinder Maven / Gradle / Ivy

There is a newer version: 3.5.3
Show newest version
/*
 * Jooby https://jooby.io
 * Apache License Version 2.0 https://jooby.io/LICENSE.txt
 * Copyright 2014 Edgar Espina
 */
package io.jooby.internal.run;

import static java.util.Collections.emptySet;

import java.nio.file.Path;
import java.util.Set;

import org.jboss.modules.ModuleLoader;
import org.jboss.modules.ModuleSpec;

/**
 * The new class loader since 3.x. It creates 3 modules with their own classloader:
 *
 * 

- classes: project classes - resources: project resources - jars: project dependencies * *

This approach reduce memory footprint allowing fast restart. */ public class JoobyMultiModuleFinder extends JoobyModuleFinder { public JoobyMultiModuleFinder( String name, Set classes, Set resources, Set jars, Set watchDirs) { super(name, classes, resources, jars, watchDirs); } @Override public ModuleSpec findModule(String name, ModuleLoader delegateLoader) { var resources = resources(name); if (resources == null) { return null; } return createModuleSpec(name, resources, dependencies(name, true)); } public Set dependencies(String name) { return dependencies(name, false); } private Set dependencies(String name, boolean addResources) { if (this.main.equals(name)) { // class only; depends on resources + jars return addResources ? Set.of(RESOURCES, JARS) : Set.of(JARS); } else if (JARS.equals(name)) { // jars depends on main when reflection is required (hibernate, jackson, quartz); return addResources ? Set.of(RESOURCES, main) : Set.of(main); } return emptySet(); } private Set resources(String name) { if (this.main.equals(name)) { return classes; } else if (RESOURCES.equals(name)) { return resources; } else if (JARS.equals(name)) { return jars; } return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy