summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
diff options
context:
space:
mode:
authorJonathan Bauer2016-04-27 17:24:15 +0200
committerJonathan Bauer2016-04-27 17:24:15 +0200
commita40ddb0a580348d68ff0c515275ffa252b686c1e (patch)
treee2436a05c935fd7b6c408e4cafb5be5dce6e16ce /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
parent[server] Fix upload handling if image already exists (diff)
downloadtutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.gz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.tar.xz
tutor-module-a40ddb0a580348d68ff0c515275ffa252b686c1e.zip
[client] first working draft for published images stuff
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
new file mode 100644
index 00000000..e57a4a24
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/cache/ImagePublishedCache.java
@@ -0,0 +1,55 @@
+package org.openslx.dozmod.thrift.cache;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.ImagePublishData;
+import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
+import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
+import org.openslx.dozmod.gui.window.ImageListWindow;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.GenericDataCache;
+import org.openslx.util.GenericDataCache.CacheMode;
+
+public class ImagePublishedCache {
+
+ private final static Logger LOGGER = Logger.getLogger(ImagePublishedCache.class);
+
+ private static final int CACHE_TIME_LIST_MS = 30 * 1000;
+
+ private static final GenericDataCache<List<ImageSummaryRead>> listCache = new GenericDataCache<List<ImageSummaryRead>>(
+ CACHE_TIME_LIST_MS) {
+ @Override
+ protected List<ImageSummaryRead> update()
+ throws TAuthorizationException, TInvocationException,
+ TException {
+ List<ImageSummaryRead> result = null;
+ int pageSize = Session.getSatelliteConfig().pageSize;
+ for (int i = 0;; ++i) {
+ List<ImageSummaryRead> page = null;
+ try {
+ page = ThriftManager.getMasterClient().getPublicImages(Session.getMasterToken(), i);
+ } catch (TException e) {
+ LOGGER.error("Could not get the list of public images from the masterserver.", e);
+ }
+ if (result == null) {
+ result = page;
+ } else {
+ result.addAll(page);
+ }
+ if (page.size() < pageSize)
+ break;
+ }
+ return result;
+ }
+ };
+
+ public static List<ImageSummaryRead> get(boolean forceRefresh) {
+ return listCache.get(forceRefresh ? CacheMode.NEVER_CACHED
+ : CacheMode.DEFAULT);
+ }
+
+}