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)
pull/159/head
reger 10 years ago
parent af2d66e3d8
commit 6bc8a9b11e

@ -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>

@ -135,6 +135,7 @@ public class Jetty9HttpServerImpl implements YaCyHttpServer {
// as fundamental component leave this hardcoded, other servlets may be defined in web.xml only
ServletHolder 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, "/*");

@ -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
}
}
}
Loading…
Cancel
Save