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 | |
| 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
10 files changed, 18 insertions, 169 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 { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java index 1484394e..992d5562 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java @@ -17,13 +17,13 @@ import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList; import org.openslx.bwlp.sat.thrift.cache.OrganizationList; import org.openslx.bwlp.sat.util.Configuration; import org.openslx.bwlp.sat.util.Json; -import org.openslx.bwlp.sat.util.QuickTimer; -import org.openslx.bwlp.sat.util.QuickTimer.Task; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.NetDirection; import org.openslx.bwlp.thrift.iface.NetRule; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; public class App { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java index fe36fff9..1f36adfb 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/SessionManager.java @@ -9,14 +9,14 @@ import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; import org.openslx.bwlp.sat.database.mappers.DbUser; import org.openslx.bwlp.sat.permissions.User; -import org.openslx.bwlp.sat.util.QuickTimer; -import org.openslx.bwlp.sat.util.QuickTimer.Task; import org.openslx.bwlp.thrift.iface.AuthorizationError; import org.openslx.bwlp.thrift.iface.Role; import org.openslx.bwlp.thrift.iface.TAuthorizationException; import org.openslx.bwlp.thrift.iface.TInvalidTokenException; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; /** * Manages user sessions. Mainly used to map tokens to users. diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java index 87898d33..903db0c5 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OperatingSystemList.java @@ -6,10 +6,10 @@ import java.util.List; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.sat.database.mappers.DbOsVirt; -import org.openslx.bwlp.sat.util.QuickTimer; -import org.openslx.bwlp.sat.util.QuickTimer.Task; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; /** * Holds the list of all known organizations. The list is synchronized with diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java index 35f3ebcf..4325b152 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/thrift/cache/OrganizationList.java @@ -5,10 +5,10 @@ import java.util.List; import org.apache.thrift.TException; import org.openslx.bwlp.sat.database.mappers.DbOrganization; -import org.openslx.bwlp.sat.util.QuickTimer; -import org.openslx.bwlp.sat.util.QuickTimer.Task; import org.openslx.bwlp.thrift.iface.Organization; import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; /** * Holds the list of all known organizations. The list is synchronized with diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/QuickTimer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/QuickTimer.java deleted file mode 100644 index 14745f97..00000000 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/QuickTimer.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.openslx.bwlp.sat.util; - -import java.util.Timer; -import java.util.TimerTask; - -import org.apache.log4j.Logger; - -/** - * This is a global, static {@link Timer} you can use anywhere for repeating - * tasks that will <b>not take a significant amount of time to execute</b>. This - * means they should not run any complex data base queries (better yet, none at - * all) or do heavy file I/O, etc.. - * The main reason for this class is to prevent having {@link Timer} threads - * everywhere in the server for trivial tasks. - */ -public class QuickTimer { - - private static final Logger LOGGER = Logger.getLogger(QuickTimer.class); - - private static final Timer timer = new Timer("QuickTimer"); - - public static void scheduleAtFixedDelay(Task task, long delay, long period) { - timer.schedule(task, delay, period); - } - - public static void scheduleAtFixedRate(Task task, long delay, long period) { - timer.scheduleAtFixedRate(task, delay, period); - } - - public static void scheduleOnce(Task task, long delay) { - timer.schedule(task, delay); - } - - public static void scheduleOnce(Task timerTask) { - scheduleOnce(timerTask, 1); - } - - /** - * Cancel this timer. Should only be called when the server is shutting - * down. - */ - public static void cancel() { - timer.cancel(); - } - - public static abstract class Task extends TimerTask { - - @Override - public final void run() { - try { - fire(); - } catch (Throwable t) { - LOGGER.warn("A Task threw an exception!", t); - } - } - - public abstract void fire(); - - } - -} |
