summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-06-10 13:28:48 +0200
committerChristian Klinger2016-06-10 13:28:48 +0200
commit323d75df568fded734bbd768fff0368801198f04 (patch)
tree1dffefe53f35d80e98eee007072c568eb20d71cf
parent[client] published image button states (diff)
downloadtutor-module-323d75df568fded734bbd768fff0368801198f04.tar.gz
tutor-module-323d75df568fded734bbd768fff0368801198f04.tar.xz
tutor-module-323d75df568fded734bbd768fff0368801198f04.zip
removed the caching mechanism.
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java61
1 files changed, 16 insertions, 45 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
index 5f82bac1..232ab93d 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/web/WebServer.java
@@ -3,8 +3,7 @@ package org.openslx.bwlp.sat.web;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.sql.SQLException;
-import java.util.Collections;
-import java.util.LinkedHashMap;
+
import java.util.Map;
import org.apache.commons.io.output.ByteArrayOutputStream;
@@ -12,7 +11,6 @@ import org.apache.log4j.Logger;
import org.openslx.bwlp.sat.database.mappers.DbLecture;
import org.openslx.bwlp.sat.fileserv.FileServer;
import org.openslx.bwlp.thrift.iface.TNotFoundException;
-import org.openslx.util.GenericDataCache;
import org.openslx.util.Json;
import org.openslx.util.vm.VmMetaData;
import org.simpleframework.xml.Serializer;
@@ -24,39 +22,8 @@ public class WebServer extends NanoHTTPD {
private static final Logger LOGGER = Logger.getLogger(WebServer.class);
- private static final int LIST_CACHE_MS = 15000;
- private static final int LIST_CACHE_MAX_ENTRIES = 16;
-
- private static final Map<String, XmlDataCache> lectureListCache = Collections.synchronizedMap(new LinkedHashMap<String, XmlDataCache>() {
- private static final long serialVersionUID = -8461839969909678055L;
-
- @Override
- protected boolean removeEldestEntry(Map.Entry<String, XmlDataCache> eldest) {
- return size() > LIST_CACHE_MAX_ENTRIES;
- }
- });
-
private static final Serializer serializer = new Persister();
- private class XmlDataCache extends GenericDataCache<byte[]> {
-
- private final String locationId;
-
- public XmlDataCache(String locations) {
- super(LIST_CACHE_MS);
- this.locationId = locations;
- }
-
- @Override
- protected byte[] update() throws Exception {
- VmChooserListXml listXml = DbLecture.getUsableListXml(false, locationId);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- serializer.write(listXml, baos);
- return baos.toByteArray();
- }
-
- }
-
public WebServer(int port) {
super("127.0.0.1", port);
super.maxRequestSize = 65535;
@@ -65,7 +32,8 @@ public class WebServer extends NanoHTTPD {
/**
* Extract request source ip address. Honors the x-forwarded-for header.
*
- * @param headers map of headers as supplied by nanohttpd
+ * @param headers
+ * map of headers as supplied by nanohttpd
* @return IP address, or empty string if unknown
*/
private String extractIp(Map<String, String> headers) {
@@ -107,7 +75,12 @@ public class WebServer extends NanoHTTPD {
private Response handle(IHTTPSession session, String uri) {
// Our special stuff
if (uri.startsWith("/vmchooser/list")) {
- return serveVmChooserList(session.getParms());
+ try {
+ return serveVmChooserList(session.getParms());
+ } catch (Exception e) {
+ LOGGER.debug("problem while retrieving the vmChooserList", e);
+ return internalServerError();
+ }
}
if (uri.startsWith("/vmchooser/lecture/")) {
return serveLectureStart(uri.substring(19));
@@ -152,20 +125,18 @@ public class WebServer extends NanoHTTPD {
new ByteArrayInputStream(meta.getFilteredDefinitionArray()));
}
- private Response serveVmChooserList(Map<String, String> params) {
+ private Response serveVmChooserList(Map<String, String> params) throws Exception {
String locations = params.get("locations");
- XmlDataCache cache = lectureListCache.get(locations);
- if (cache == null) {
- cache = new XmlDataCache(locations);
- lectureListCache.put(locations, cache);
- }
+
+ VmChooserListXml listXml = DbLecture.getUsableListXml(false, locations);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ serializer.write(listXml, baos);
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "text/xml; charset=utf-8",
- new ByteArrayInputStream(cache.get()));
+ new ByteArrayInputStream(baos.toByteArray()));
}
public static Response internalServerError() {
- return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain",
- "Internal Server Error");
+ return new NanoHTTPD.Response(NanoHTTPD.Response.Status.INTERNAL_ERROR, "text/plain", "Internal Server Error");
}
public static Response notFound() {