Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 898, Don't use a caching resource manager for dev mode and make… #899

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import org.jboss.shamrock.deployment.recording.RecorderContext;
import org.jboss.shamrock.runtime.LaunchMode;
import org.jboss.shamrock.runtime.RuntimeValue;
import org.jboss.shamrock.runtime.ShutdownContext;
import org.jboss.shamrock.runtime.annotations.ConfigItem;
import org.jboss.shamrock.undertow.runtime.HttpConfig;
import org.jboss.shamrock.undertow.runtime.ServletSecurityInfoProxy;
Expand Down Expand Up @@ -185,7 +186,9 @@ public ServletDeploymentBuildItem build(ApplicationArchivesBuildItem application
InjectionFactoryBuildItem injectionFactory,
InjectionFactoryBuildItem bc,
BuildProducer<ObjectSubstitutionBuildItem> substitutions,
Consumer<ReflectiveClassBuildItem> reflectiveClasses) throws Exception {
Consumer<ReflectiveClassBuildItem> reflectiveClasses,
LaunchModeBuildItem launchMode,
ShutdownContextBuildItem shutdownContext) throws Exception {

ObjectSubstitutionBuildItem.Holder holder = new ObjectSubstitutionBuildItem.Holder(ServletSecurityInfo.class, ServletSecurityInfoProxy.class, ServletSecurityInfoSubstitution.class);
substitutions.produce(new ObjectSubstitutionBuildItem(holder));
Expand Down Expand Up @@ -216,7 +219,7 @@ public void accept(Path path) {
}
}

RuntimeValue<DeploymentInfo> deployment = template.createDeployment("test", knownFiles, knownDirectories);
RuntimeValue<DeploymentInfo> deployment = template.createDeployment("test", knownFiles, knownDirectories, launchMode.getLaunchMode(), shutdownContext);

WebMetaData result;
Path webXml = applicationArchivesBuildItem.getRootArchive().getChildPath(WEB_XML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jboss.shamrock.undertow.runtime;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.file.Paths;
import java.security.SecureRandom;
Expand Down Expand Up @@ -49,6 +50,7 @@
import io.undertow.server.handlers.resource.CachingResourceManager;
import io.undertow.server.handlers.resource.ClassPathResourceManager;
import io.undertow.server.handlers.resource.PathResourceManager;
import io.undertow.server.handlers.resource.ResourceManager;
import io.undertow.server.session.SessionIdGenerator;
import io.undertow.servlet.ServletExtension;
import io.undertow.servlet.Servlets;
Expand Down Expand Up @@ -87,7 +89,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
private static volatile Undertow undertow;
private static volatile HttpHandler currentRoot = ResponseCodeHandler.HANDLE_404;

public RuntimeValue<DeploymentInfo> createDeployment(String name, Set<String> knownFile, Set<String> knownDirectories) {
public RuntimeValue<DeploymentInfo> createDeployment(String name, Set<String> knownFile, Set<String> knownDirectories, LaunchMode launchMode, ShutdownContext context) {
DeploymentInfo d = new DeploymentInfo();
d.setSessionIdGenerator(new ShamrockSessionIdGenerator());
d.setClassLoader(getClass().getClassLoader());
Expand All @@ -100,18 +102,36 @@ public RuntimeValue<DeploymentInfo> createDeployment(String name, Set<String> kn
};
}
d.setClassLoader(cl);
//TODO: this is a big hack
//TODO: caching configuration once the new config model is in place
//TODO: we need better handling of static resources
String resourcesDir = System.getProperty(RESOURCES_PROP);
ResourceManager resourceManager;
if (resourcesDir == null) {
d.setResourceManager(new CachingResourceManager(1000, 0, null, new KnownPathResourceManager(knownFile, knownDirectories, new ClassPathResourceManager(d.getClassLoader(), "META-INF/resources")), 2000));
resourceManager = new KnownPathResourceManager(knownFile, knownDirectories, new ClassPathResourceManager(d.getClassLoader(), "META-INF/resources"));
} else {
d.setResourceManager(new CachingResourceManager(1000, 0, null, new PathResourceManager(Paths.get(resourcesDir)), 2000));
resourceManager = new PathResourceManager(Paths.get(resourcesDir));
}
if(launchMode == LaunchMode.NORMAL) {
//todo: cache configuration
resourceManager = new CachingResourceManager(1000, 0, null, resourceManager, 2000);
}

d.setResourceManager(resourceManager);


d.addWelcomePages("index.html", "index.htm");

d.addServlet(new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, DefaultServlet.class).setAsyncSupported(true));

context.addShutdownTask(new Runnable() {
@Override
public void run() {
try {
d.getResourceManager().close();
} catch (IOException e) {
log.error("Failed to close Servlet ResourceManager", e);
}
}
});
return new RuntimeValue<>(d);
}

Expand Down