diff options
| author | Simon Rettberg | 2015-07-10 17:25:00 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2015-07-10 17:25:00 +0200 |
| commit | ec117f81f1ac0abaee5983444e6389c6bb43927b (patch) | |
| tree | ba6e19500e5485883097f52b14dbeb3ede499c29 /dozentenmodul/src/main/java | |
| parent | [client] next/finish wizard buttons woes... (diff) | |
| download | tutor-module-ec117f81f1ac0abaee5983444e6389c6bb43927b.tar.gz tutor-module-ec117f81f1ac0abaee5983444e6389c6bb43927b.tar.xz tutor-module-ec117f81f1ac0abaee5983444e6389c6bb43927b.zip | |
[*] Move common classes to master-sync-shared
Diffstat (limited to 'dozentenmodul/src/main/java')
5 files changed, 10 insertions, 100 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java index b8680607..6c2202a0 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/BlockProgressBar.java @@ -22,7 +22,7 @@ public class BlockProgressBar extends Canvas { private boolean simpleMode = true; - public BlockProgressBar(Composite parent) { + public BlockProgressBar(Composite parent, byte[] blocks) { super(parent, SWT.NO_BACKGROUND); setupListeners(); white = getDisplay().getSystemColor(SWT.COLOR_WHITE); @@ -34,6 +34,7 @@ public class BlockProgressBar extends Canvas { blockColors[2] = getDisplay().getSystemColor(SWT.COLOR_YELLOW); blockColors[3] = blue; blockColors[4] = getDisplay().getSystemColor(SWT.COLOR_GREEN); + this.blocks.setBlocks(blocks); } public void setStatus(byte[] blocks) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java deleted file mode 100644 index 4b859f66..00000000 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ACache.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.openslx.dozmod.thrift; - -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.log4j.Logger; - -public abstract class ACache<T> { - - private static final Logger LOGGER = Logger.getLogger(ACache.class); - - /** - * How long the cached data is valid after fetching - */ - private final int validMs; - - /** - * Deadline when the cache goes invalid - */ - private long validUntil = 0; - - /** - * The data being held - */ - private final AtomicReference<T> item = new AtomicReference<>(); - - public ACache(int validMs) { - this.validMs = validMs; - } - - /** - * Get the cached object, but refresh the cache first if - * the cached instance is too old. - * - * @return - */ - public T get() { - return get(CacheMode.DEFAULT); - } - - /** - * Get the cached object, using the given cache access strategy. - * ALWAYS_CACHED: Never refresh the cache, except if it has never been fetched before - * DEFAULT: Only fetch from remote if the cached value is too old - * NEVER_CACHED: Always fetch from remote. If it fails, return null - * - * @param mode Cache access strategy as described above - * @return T - */ - public T get(CacheMode mode) { - switch (mode) { - case ALWAYS_CACHED: - if (validUntil == 0) - ensureUpToDate(true); - break; - case DEFAULT: - ensureUpToDate(false); - break; - case NEVER_CACHED: - if (!ensureUpToDate(true)) - return null; - break; - } - return item.get(); - } - - private synchronized boolean ensureUpToDate(boolean force) { - final long now = System.currentTimeMillis(); - if (!force && now < validUntil) - return true; - T fetched; - try { - fetched = update(); - if (fetched == null) - return false; - } catch (Exception e) { - LOGGER.warn("Could not fetch fresh data", e); - return false; - } - item.set(fetched); - validUntil = now + validMs; - return true; - } - - protected abstract T update() throws Exception; - - // - - public static enum CacheMode { - ALWAYS_CACHED, - DEFAULT, - NEVER_CACHED - } - -} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java index a2fac063..e8cb696e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ImageCache.java @@ -6,14 +6,15 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.bwlp.thrift.iface.TInternalServerError; -import org.openslx.dozmod.thrift.ACache.CacheMode; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; +import org.openslx.util.GenericDataCache.CacheMode; public class ImageCache { private static final int CACHE_TIME_LIST_MS = 2 * 60 * 1000; - private static final ACache<List<ImageSummaryRead>> listCache = new ACache<List<ImageSummaryRead>>(CACHE_TIME_LIST_MS) { + private static final GenericDataCache<List<ImageSummaryRead>> listCache = new GenericDataCache<List<ImageSummaryRead>>(CACHE_TIME_LIST_MS) { @Override protected List<ImageSummaryRead> update() throws TAuthorizationException, TInternalServerError, TException { List<ImageSummaryRead> result = null; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java index d7dbd972..00dd7905 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java @@ -7,6 +7,7 @@ import org.apache.thrift.TException; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; public class MetaDataCache { @@ -17,7 +18,7 @@ public class MetaDataCache { */ private static final int CACHE_TIME_MS = 60 * 60 * 1000; - private static final ACache<List<OperatingSystem>> osCache = new ACache<List<OperatingSystem>>(CACHE_TIME_MS) { + private static final GenericDataCache<List<OperatingSystem>> osCache = new GenericDataCache<List<OperatingSystem>>(CACHE_TIME_MS) { @Override protected List<OperatingSystem> update() throws TException { try { @@ -29,7 +30,7 @@ public class MetaDataCache { } }; - private static final ACache<List<Virtualizer>> virtualizerCache = new ACache<List<Virtualizer>>(CACHE_TIME_MS) { + private static final GenericDataCache<List<Virtualizer>> virtualizerCache = new GenericDataCache<List<Virtualizer>>(CACHE_TIME_MS) { @Override protected List<Virtualizer> update() throws TException { try { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java index dde31d89..3b8d4765 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/OrganizationCache.java @@ -6,6 +6,7 @@ import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; public class OrganizationCache { @@ -16,7 +17,7 @@ public class OrganizationCache { */ private static final int CACHE_TIME_MS = 20 * 60 * 1000; - private static final ACache<List<Organization>> cache = new ACache<List<Organization>>(CACHE_TIME_MS) { + private static final GenericDataCache<List<Organization>> cache = new GenericDataCache<List<Organization>>(CACHE_TIME_MS) { @Override protected List<Organization> update() throws Exception { |
