diff options
author | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
commit | 8d6cd17c330388aa13fd7c39802c7400d85f972c (patch) | |
tree | 5f2c5856f58b1454e24dc16fad10751dfe9d087b /dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java | |
parent | oops (diff) | |
download | tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.gz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.xz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.zip |
[client] Redo package structure, add comments/TODOs, rename GUI classes
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java new file mode 100644 index 00000000..d7dbd972 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java @@ -0,0 +1,72 @@ +package org.openslx.dozmod.thrift; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.thrifthelper.ThriftManager; + +public class MetaDataCache { + + private static final Logger LOGGER = Logger.getLogger(MetaDataCache.class); + + /** + * How long to cache data. + */ + private static final int CACHE_TIME_MS = 60 * 60 * 1000; + + private static final ACache<List<OperatingSystem>> osCache = new ACache<List<OperatingSystem>>(CACHE_TIME_MS) { + @Override + protected List<OperatingSystem> update() throws TException { + try { + return ThriftManager.getSatClient().getOperatingSystems(); + } catch (Exception e) { + LOGGER.warn("Could not get OS list from satellite, trying master for backup...", e); + } + return ThriftManager.getMasterClient().getOperatingSystems(); + } + }; + + private static final ACache<List<Virtualizer>> virtualizerCache = new ACache<List<Virtualizer>>(CACHE_TIME_MS) { + @Override + protected List<Virtualizer> update() throws TException { + try { + return ThriftManager.getSatClient().getVirtualizers(); + } catch (TException e) { + LOGGER.warn("Could not get virtualizer list from satellite, trying master for backup...", e); + } + return ThriftManager.getMasterClient().getVirtualizers(); + } + }; + + /** + * Get all known/valid operating systems an image can be marked as. + * + * @return + */ + public static List<OperatingSystem> getOperatingSystems() { + return osCache.get(); + } + + public static OperatingSystem getOsById(int id){ + List<OperatingSystem> list = getOperatingSystems(); + if (list == null) + return null; + for (OperatingSystem os : list) { + if (os.getOsId() == id) return os; + } + return null; + } + + /** + * Get all supported virtualizers an image can be declared to be run as. + * + * @return + */ + public static List<Virtualizer> getVirtualizers() { + return virtualizerCache.get(); + } + +}
\ No newline at end of file |