Changeset 39032


Ignore:
Timestamp:
2024-05-17T23:04:48+12:00 (3 weeks ago)
Author:
anupama
Message:

Rewritten with clearer branch cases: either we're turning off EDT changes (globally with single flag, or locally with byapss param), or we're running with EDT changes and we're either already on the Event Dispatch Thread or need to switch into it. Once more tested it out with the complex createCollection case to ensure that GLI runs fine and testing runs (albeit with progress bar not updating).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r39031 r39032  
    275275    }
    276276
    277     // print calling thread's name
     277    // print calling thread's name and the thread we run on if we're bypassing EDT changes
     278    // or would have bypassed if we *weren't* testing
    278279    if(bypassIfNotTesting) {
    279280        System.err.println("Calling thread name: " + Thread.currentThread().getName()
     
    285286        }
    286287    }
    287    
     288
     289    // If we're turning off EDT changes globally or on a case by case basis,
     290    // we're not running the Runnable code on the EDT any more, but whatever
     291    // thread GLI *would* have run the code on if we hadn't made the EDT changes
    288292    if(TURN_OFF_EVENTDISPATCH_CHANGES
    289        || (bypassIfNotTesting && !TestingPreparation.TEST_MODE)
    290        || EventQueue.isDispatchThread()) {   
    291        
     293       || (bypassIfNotTesting && !TestingPreparation.TEST_MODE)) {
     294               
    292295        if (bypassIfNotTesting && !TestingPreparation.TEST_MODE) {
    293296        System.err.println("@@@@" + callerDescription + " - Bypassing EDT change");
     
    299302        }
    300303       
    301         if(TURN_OFF_EVENTDISPATCH_CHANGES
    302            || (bypassIfNotTesting && !TestingPreparation.TEST_MODE)) {
    303        
    304         // run it as before the EDT changes to GLI:
    305         if(runVariant == RUN_IN_THREAD_PARAM_WITH_START) {
    306             // start off the param thread to run the runnable in thread of param
    307             // instead of whatever the current thread of the calling function is
    308             Thread runInThread = (Thread)runnable;
    309             runInThread.start(); // async by nature
    310         } else if(runVariant == PROCEED_IN_CURRENT_THREAD) {
    311             // run the Runnable code (whether Thread object or not) in
    312             // whatever the current thread of the calling function is
    313             runnable.run(); // synchronous by nature of runable code running on current thread
    314         }
    315         } else { // If we want the EDT changes to GLI active and we're in the Dispatch Thread
     304        // Run it as before the EDT changes to GLI: one of 2 ways as specified
     305        if(runVariant == RUN_IN_THREAD_PARAM_WITH_START) {
     306        // start off the param thread to run the runnable in thread of param
     307        // instead of whatever the current thread of the calling function is
     308        Thread runInThread = (Thread)runnable;
     309        // TODO: warning when runnable is not the event dispatch thread
     310        runInThread.start(); // async by nature     
     311        } else if(runVariant == PROCEED_IN_CURRENT_THREAD) {
     312        // run the Runnable code (whether Thread object or not) in
     313        // whatever the current thread of the calling function is
     314        runnable.run(); // synchronous by nature of runable code running on current thread
     315        }       
     316       
     317    } else { // We want the EDT changes to GLI to be active, meaning we *want* to run
     318        // the Runnable code in the Event Dispatch Thread, not in any other Threads
     319
     320        if (EventQueue.isDispatchThread()) {
     321        // We're already in the Dispatch Thread.
    316322        // So just run the Runnable code in the Dispatch thread, regardless of how GLI
    317323        // used run it. Specifically, don't call start() on any Thread param to run
    318324        // the code in the non-EDT thread param
    319         runnable.run();     
    320         }
    321        
    322     } else { // whether the Runnable is a new Thread or other Runnable object
    323         // whether GLI before EDT changes launched it with start() in its own Thread
    324         // or it was code run in whatever the current thread was, we run it on the
    325         // Dispatch Thread (Event Dispatch Thread, EDT)
    326         if(invokeAs == ASYNC) {
    327         SwingUtilities.invokeLater(runnable); // asynchronous
    328         } else {
    329         try {
    330             System.err.println("\tXXXXX SYNC.");
    331             SwingUtilities.invokeAndWait(runnable); // synchronous
    332         } catch(Exception e) {
    333             String message = "@@@ Exception during ";
    334             if(callerDescription != null && !callerDescription.equals("")) {
    335             message += callerDescription + " - ";
     325        runnable.run();
     326           
     327        } else { // whether the Runnable is a new Thread or other Runnable object
     328        // whether GLI before EDT changes launched it with start() in its own Thread
     329        // or it was code run in whatever the current thread was, we run it on the
     330        // Dispatch Thread (Event Dispatch Thread, EDT)
     331        if(invokeAs == ASYNC) {
     332            SwingUtilities.invokeLater(runnable); // asynchronous
     333        } else {
     334            try {
     335            SwingUtilities.invokeAndWait(runnable); // synchronous
     336            } catch(Exception e) {
     337            String message = "@@@ Exception during ";
     338            if(callerDescription != null && !callerDescription.equals("")) {
     339                message += callerDescription + " - ";
     340            }
     341            message += "invokeAndWait on EDT: ";
     342            System.err.println(message + e.getMessage());
    336343            }
    337             message += "invokeAndWait on EDT: ";
    338             System.err.println(message + e.getMessage());
    339344        }
    340345        }
Note: See TracChangeset for help on using the changeset viewer.