Allow the preset loading system to function if there are no orc files.
[debian/openrocket] / core / src / net / sf / openrocket / startup / ConcurrentComponentPresetDatabaseLoader.java
index a4191da3cf6a4e33e82fd805b3d9a5dcce8483c7..3a70b7e505a27fe660c4452d03e9ff6042797187 100644 (file)
@@ -49,7 +49,7 @@ public class ConcurrentComponentPresetDatabaseLoader {
                        }
                });
 
-               loaderPool = Executors.newFixedThreadPool(15, new ThreadFactory() {
+               loaderPool = Executors.newFixedThreadPool(3, new ThreadFactory() {
                        int threadCount = 0;
                        @Override
                        public Thread newThread(Runnable r) {
@@ -70,10 +70,12 @@ public class ConcurrentComponentPresetDatabaseLoader {
        public void await() throws InterruptedException {
                latch.await();
                loaderPool.shutdown();
-               loaderPool.awaitTermination(10, TimeUnit.SECONDS);
+               loaderPool.awaitTermination(90, TimeUnit.SECONDS);
                writerPool.shutdown();
-               writerPool.awaitTermination(10, TimeUnit.SECONDS);
-               iterator.close();
+               writerPool.awaitTermination(90, TimeUnit.SECONDS);
+               if ( iterator != null ) {
+                       iterator.close();
+               }
                long end = System.currentTimeMillis();
                log.debug("Time to load presets: " + (end-startTime) + "ms " + presetCount + " loaded from " + fileCount + " files");
        }
@@ -88,18 +90,14 @@ public class ConcurrentComponentPresetDatabaseLoader {
                        iterator = DirectoryIterator.findDirectory(SYSTEM_PRESET_DIR,
                                        new SimpleFileFilter("", false, "orc"));
 
-                       if (iterator == null) {
-                               throw new IllegalStateException("Component preset directory " + SYSTEM_PRESET_DIR +
-                                               " not found, distribution built wrong");
-                       }
-
-                       while( iterator.hasNext() ) {
-                               Pair<String,InputStream> f = iterator.next();
-                               FileLoader loader = new FileLoader( f.getV(), f.getU() );
-                               loaderPool.execute(loader);
-                               fileCount ++;
+                       if (iterator != null) {
+                               while( iterator.hasNext() ) {
+                                       Pair<String,InputStream> f = iterator.next();
+                                       FileLoader loader = new FileLoader( f.getV(), f.getU() );
+                                       loaderPool.execute(loader);
+                                       fileCount ++;
+                               }
                        }
-
                        latch.countDown();
                }
        }