Skip to content

Commit

Permalink
Modify MappingBasedServletFactory to keep a static cache of Servlets …
Browse files Browse the repository at this point in the history
…and to destroy them as needed (Issue #502)
  • Loading branch information
jesse-gallagher committed Dec 11, 2023
1 parent 29d76da commit 897cfdc
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.openntf.xsp.jakartaee.util.LibraryUtil;
import org.openntf.xsp.jakartaee.util.ModuleUtil;

import com.ibm.commons.util.StringUtil;
import com.ibm.designer.runtime.domino.adapter.ComponentModule;
Expand All @@ -32,8 +35,8 @@
import jakarta.servlet.ServletContext;

public abstract class MappingBasedServletFactory implements IServletFactory {
private static final Map<String, Map<String, Servlet>> MODULE_SERVLETS = new ConcurrentHashMap<>();
private ComponentModule module;
private Servlet servlet;
private long lastUpdate;


Expand Down Expand Up @@ -120,10 +123,26 @@ protected boolean checkExists(String servletPath, String pathInfo) {
}

public final Servlet getExecutorServlet() throws ServletException {
Servlet servlet = getServlet();
if (servlet == null || lastUpdate < this.module.getLastRefresh()) {
this.servlet = createExecutorServlet(this.module);
if(servlet != null) {
servlet.destroy();
}
servlet = createExecutorServlet(this.module);
setServlet(servlet);
lastUpdate = this.module.getLastRefresh();
}
return servlet;
}

protected Servlet getServlet() {
String id = ModuleUtil.getModuleId(this.module);
return MODULE_SERVLETS.computeIfAbsent(id, key -> new ConcurrentHashMap<>())
.get(getClass().getName());
}
protected void setServlet(Servlet servlet) {
String id = ModuleUtil.getModuleId(this.module);
MODULE_SERVLETS.computeIfAbsent(id, key -> new ConcurrentHashMap<>())
.put(getClass().getName(), servlet);
}
}

0 comments on commit 897cfdc

Please sign in to comment.