Changeset 6779 in josm for trunk/src


Ignore:
Timestamp:
2014-01-29T23:19:15+01:00 (10 years ago)
Author:
simon04
Message:

Initialize validator tests on demand, separate initialization of validator from presets, print initialization timing information to console

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r6730 r6779  
    501501        List<Callable<Void>> tasks = new ArrayList<Callable<Void>>();
    502502
    503         tasks.add(new Callable<Void>() {
     503        tasks.add(new InitializationTask(tr("Initializing OSM API")) {
    504504
    505505            @Override
    506             public Void call() throws Exception {
     506            public void initialize() throws Exception {
    507507                // We try to establish an API connection early, so that any API
    508508                // capabilities are already known to the editor instance. However
    509509                // if it goes wrong that's not critical at this stage.
    510                 if (initListener != null) {
    511                     initListener.updateStatus(tr("Initializing OSM API"));
    512                 }
    513510                try {
    514511                    OsmApi.getOsmApi().initialize(null, true);
     
    516513                    Main.warn(getErrorMessage(Utils.getRootCause(e)));
    517514                }
    518                 return null;
    519515            }
    520516        });
    521517
    522         tasks.add(new Callable<Void>() {
     518        tasks.add(new InitializationTask(tr("Initializing validator")) {
    523519
    524520            @Override
    525             public Void call() throws Exception {
    526                 if (initListener != null) {
    527                     initListener.updateStatus(tr("Initializing presets"));
    528                 }
    529                 TaggingPresetPreference.initialize();
    530                 // some validator tests require the presets to be initialized
    531                 // TODO remove this dependency for parallel initialization
    532                 if (initListener != null) {
    533                     initListener.updateStatus(tr("Initializing validator"));
    534                 }
     521            public void initialize() throws Exception {
    535522                validator = new OsmValidator();
    536523                MapView.addLayerChangeListener(validator);
    537                 return null;
    538524            }
    539525        });
    540526
    541         tasks.add(new Callable<Void>() {
     527        tasks.add(new InitializationTask(tr("Initializing presets")) {
    542528
    543529            @Override
    544             public Void call() throws Exception {
    545                 if (initListener != null) {
    546                     initListener.updateStatus(tr("Initializing map styles"));
    547                 }
     530            public void initialize() throws Exception {
     531                TaggingPresetPreference.initialize();
     532            }
     533        });
     534
     535        tasks.add(new InitializationTask(tr("Initializing map styles")) {
     536
     537            @Override
     538            public void initialize() throws Exception {
    548539                MapPaintPreference.initialize();
    549                 return null;
    550540            }
    551541        });
    552542
    553         tasks.add(new Callable<Void>() {
     543        tasks.add(new InitializationTask(tr("Loading imagery preferences")) {
    554544
    555545            @Override
    556             public Void call() throws Exception {
    557                 if (initListener != null) {
    558                     initListener.updateStatus(tr("Loading imagery preferences"));
    559                 }
     546            public void initialize() throws Exception {
    560547                ImageryPreference.initialize();
    561                 return null;
    562548            }
    563549        });
     
    590576        contentPanePrivate.updateUI();
    591577
     578    }
     579
     580    private abstract class InitializationTask implements Callable<Void> {
     581
     582        private final String name;
     583
     584        protected InitializationTask(String name) {
     585            this.name = name;
     586        }
     587
     588        public abstract void initialize() throws Exception;
     589
     590        @Override
     591        public Void call() throws Exception {
     592            if (initListener != null) {
     593                initListener.updateStatus(name);
     594            }
     595            final long startTime = System.currentTimeMillis();
     596            initialize();
     597            final long elapsedTime = System.currentTimeMillis() - startTime;
     598            Main.debug(tr("{0} completed in {1}", name, Utils.getDurationString(elapsedTime)));
     599            return null;
     600        }
    592601    }
    593602
  • trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

    r6529 r6779  
    6868            return;
    6969
     70        OsmValidator.initializeTests();
    7071        OsmValidator.initializeErrorLayer();
    7172
  • trunk/src/org/openstreetmap/josm/actions/upload/ValidateUploadHook.java

    r6683 r6779  
    143143
    144144        if (ed.getValue() != 1) {
     145            OsmValidator.initializeTests();
    145146            OsmValidator.initializeErrorLayer();
    146147            Main.map.validatorDialog.unfurlDialog();
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r6691 r6779  
    138138        checkValidatorDir();
    139139        initializeGridDetail();
    140         initializeTests(getTests());
    141140        loadIgnoredErrors(); //FIXME: load only when needed
    142141    }
     
    295294    }
    296295
     296    private static boolean testsInitialized = false;
     297
     298    /**
     299     * Initializes all tests if this operations hasn't been performed already.
     300     */
     301    public static synchronized void initializeTests() {
     302        if (!testsInitialized) {
     303            Main.debug("Initializing validator tests");
     304            final long startTime = System.currentTimeMillis();
     305            initializeTests(getTests());
     306            testsInitialized = true;
     307            final long elapsedTime = System.currentTimeMillis() - startTime;
     308            Main.debug("Initializing validator tests completed in " + Utils.getDurationString(elapsedTime));
     309        }
     310    }
     311
    297312    /**
    298313     * Initializes all tests
Note: See TracChangeset for help on using the changeset viewer.