+ return success;
+ }
+
+ // Blocking of cachers working on same file
+
+ /**
+ * Register a cacher writing to the specified file path
+ * @param inFilePath destination path to tile file
+ * @return true if nobody else has claimed this file yet
+ */
+ private synchronized static boolean registerCacher(String inFilePath)
+ {
+ if (DOWNLOADING_FILES.contains(inFilePath))
+ {
+ return false;
+ }
+ // Nobody has claimed this file yet
+ DOWNLOADING_FILES.add(inFilePath);
+ return true;
+ }
+
+ /**
+ * Cacher has finished dealing with the specified file
+ * @param inFilePath destination path to tile file
+ */
+ private synchronized static void unregisterCacher(String inFilePath)
+ {
+ DOWNLOADING_FILES.remove(inFilePath);
+ }
+
+ // Limiting of active threads
+
+ /**
+ * @return true if another thread is allowed to become active
+ */
+ private synchronized static boolean canStartNewThread()
+ {
+ final int MAXIMUM_NUM_THREADS = 8;
+ if (NUMBER_ACTIVE_THREADS < MAXIMUM_NUM_THREADS)
+ {
+ NUMBER_ACTIVE_THREADS++;
+ return true;
+ }
+ // Already too many threads active
+ return false;
+ }
+
+ /**
+ * Inform that one of the previously active threads has now completed
+ */
+ private synchronized static void threadFinished()
+ {
+ if (NUMBER_ACTIVE_THREADS > 0)
+ {
+ NUMBER_ACTIVE_THREADS--;
+ }