Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
make Quality of Service Servlet available to prioritize requests from local host This assigns priorities to incoming requests. Higher priority numbers are served before lower. (disabled by default in defaults/web.xml, uncomment or copy entry to DATA/Settings/web.xml)
reger6bc8a9b11e0d
diff --git a/defaults/web.xml b/defaults/web.xmlindex 41cdbfb42..349a3bc6b 100644--- a/defaults/web.xml+++ b/defaults/web.xml@@ -9,6 +9,20 @@<display-name>YaCy</display-name><description>Decentralized Web Search</description>+ <!-- Quality of Service filter to prioritize service for requests from localhost -->+ <!-- uncomment this to activate+ <filter>+ <description>Quality of Service Filter, to prioritize requests from localhost</description>+ <filter-name>YaCyQoSFilter</filter-name>+ <filter-class>net.yacy.http.servlets.YaCyQoSFilter</filter-class>+ <async-supported>true</async-supported>+ </filter>+ <filter-mapping>+ <filter-name>YaCyQoSFilter</filter-name>+ <url-pattern>/*</url-pattern>+ </filter-mapping>+ -->+<!-- Standard YaCy Servlets --><!-- Default servlet for all YaCy output@@ -17,6 +31,7 @@<servlet><servlet-name>YaCyDefaultServlet</servlet-name><servlet-class>net.yacy.http.servlets.YaCyDefaultServlet</servlet-class>+ <async-supported>true</async-supported></servlet><servlet-mapping><servlet-name>YaCyDefaultServlet</servlet-name>diff --git a/source/net/yacy/http/Jetty9HttpServerImpl.java b/source/net/yacy/http/Jetty9HttpServerImpl.javaindex c31517f61..cf4123640 100644--- a/source/net/yacy/http/Jetty9HttpServerImpl.java+++ b/source/net/yacy/http/Jetty9HttpServerImpl.java@@ -135,9 +135,10 @@ public class Jetty9HttpServerImpl implements YaCyHttpServer {// as fundamental component leave this hardcoded, other servlets may be defined in web.xml onlyServletHolder sholder = new ServletHolder(YaCyDefaultServlet.class);sholder.setInitParameter("resourceBase", htrootpath);+ sholder.setAsyncSupported(true); // needed for YaCyQoSFilter//sholder.setInitParameter("welcomeFile", "index.html"); // default is index.html, welcome.html- htrootContext.addServlet(sholder,"/*");-+ htrootContext.addServlet(sholder, "/*");+// -----------------------------------------------------------------------------// here we set and map the mandatory servlets, needed for typical YaCy operation// to make sure they are available even if removed in individual web.xmldiff --git a/source/net/yacy/http/servlets/YaCyQoSFilter.java b/source/net/yacy/http/servlets/YaCyQoSFilter.javanew file mode 100644index 000000000..e7bf6cdf9--- /dev/null+++ b/source/net/yacy/http/servlets/YaCyQoSFilter.java@@ -0,0 +1,49 @@+/**+ * YaCyQoSFilter+ * Copyright 2015 by Burkhard Buelte+ * First released 26.04.2015 at http://yacy.net+ *+ * This library is free software; you can redistribute it and/or+ * modify it under the terms of the GNU Lesser General Public+ * License as published by the Free Software Foundation; either+ * version 2.1 of the License, or (at your option) any later version.+ *+ * This library is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+ * Lesser General Public License for more details.+ *+ * You should have received a copy of the GNU Lesser General Public License+ * along with this program in the file lgpl21.txt+ * If not, see <http://www.gnu.org/licenses/>.+ */+package net.yacy.http.servlets;++import javax.servlet.ServletRequest;+import net.yacy.cora.protocol.Domains;+import org.eclipse.jetty.servlets.QoSFilter;++/**+ * Quality of Service Filter based on Jetty QosFilter+ * to prioritize requests from localhost+ * The intention is to improve the responsivness of web/user interface for the local admin+ * To activate this filter uncomment the predefined filter setting in web.xml+ */+public class YaCyQoSFilter extends QoSFilter {++ /**+ * set priority for localhost to max+ * @param request+ * @return priority+ */+ @Override+ protected int getPriority(ServletRequest request) {+ if (request.getServerName().equalsIgnoreCase(Domains.LOCALHOST)) {+ return 10; // highest priority for "localhost"+ } else if (Domains.isLocalhost(request.getRemoteHost())) {+ return 9;+ } else {+ return super.getPriority(request); // standard: authenticated = 2, other = 1 or 0+ }+ }+}