Ignore:
Timestamp:
2008-10-29T20:04:25+13:00 (15 years ago)
Author:
ak19
Message:
  1. Previously the GLI client and GLI applet used to have a problem that manifested very rarely and randomly: every so often, one of the gliserver Action commands would get stuck in an infinite wait loop. The current code, after running it about 50 times and not showing this problem anymore, seems to have fixed this. The changes made were to RemoteGreenstoneServer.performAction() where a wait() is now used instead of a timed wait() and the ActionQueue.java class where more methods are now synchronised and the infinite while loop in the Thread's run() method has been reorganised to check for any increase in the size of the action queue at the start. 2. An exit condition is now used instead of an infinite while loop in ActionQueue's run(), so that the loop is terminated when the user cancels or a connect exception occurs. This ends the thread (which is particularly necessary in Applets, else they keep consuming processor time). RemoteGreenstoneServer.performAction() checks for whether the ActionQueue thread has exited and if so GLI's Gatherer exits, otherwise performAction proceeds to add the next action to the queue as before.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java

    r17612 r17630  
    6666
    6767    public RemoteGreenstoneServer() {
     68    // Create the progress_bar first since ActionQueue uses it in its thread
     69    // (the thread will start immediately).
     70    progress_bar = new RemoteGreenstoneServer.ProgressBar();
    6871    remote_greenstone_server_action_queue = new ActionQueue();
    69     progress_bar = new RemoteGreenstoneServer.ProgressBar();
    7072    }
    7173
     
    230232    }
    231233    }
    232 
     234   
    233235
    234236    // ----------------------------------------------------------------------------------------------------
     
    240242    private String performAction(RemoteGreenstoneServerAction remote_greenstone_server_action)
    241243    {
     244    // Check for whether the queue thread stopped running because
     245    // the user cancelled out. If so, exit GLI.
     246    if(remote_greenstone_server_action_queue.hasExited()) {
     247        remote_greenstone_server_action_queue.clear();
     248        //remote_greenstone_server_action_queue = null;
     249        Gatherer.exit();
     250        return "";
     251    }
     252
    242253    // Add the action to the queue
    243254    remote_greenstone_server_action_queue.addAction(remote_greenstone_server_action);
     255    String threadName = Thread.currentThread().getName();
    244256
    245257    // If we're running in the GUI thread we must return immediately
    246258    // We cannot wait for the action to complete because this will block any GUI updates
    247259    if (SwingUtilities.isEventDispatchThread()) {
    248         System.err.println("WARNING: In event dispatch thread, returning immediately...");
     260        System.err.println(threadName
     261                   + "\tACTION QUEUED: In event dispatch thread, returning immediately...\n\t"
     262                   + remote_greenstone_server_action);
    249263        return null;
    250264    }
    251265
    252266    // Otherwise wait until the action is processed
    253     while (!remote_greenstone_server_action.processed) {
     267    try {
    254268        synchronized (remote_greenstone_server_action) {
    255         try {
     269        while(!remote_greenstone_server_action.processed) {
     270            //System.err.println("Waiting for action to complete...: " + remote_greenstone_server_action);
    256271            DebugStream.println("Waiting for action to complete...");
    257             remote_greenstone_server_action.wait(500);
     272            remote_greenstone_server_action.wait(); // wait to be notified when the action has been processed
    258273        }
    259         catch (InterruptedException exception) {}
    260         }
     274        }
     275    } catch (Exception e) {
     276        System.err.println("RemoteGreenstoneServer.performAction() - exception: " + e);
     277        e.printStackTrace();
    261278    }
    262279
     
    285302    }
    286303
    287 
    288     public void setAction(String action)
     304    /** synchronized to avoid conflicts since several threads access this */
     305    synchronized public void setAction(String action)
    289306    {
    290307        if (action != null) {
     
    310327    }
    311328   
    312     public RemoteGreenstoneServer.ProgressBar getProgressBar()
     329    /** synchronized to avoid conflicts since several threads access this */
     330    synchronized public RemoteGreenstoneServer.ProgressBar getProgressBar()
    313331    {
    314332    return progress_bar;
     
    327345        remote_greenstone_server_authentication = new RemoteGreenstoneServerAuthenticator().getAuthentication();
    328346    }
    329 
     347   
    330348
    331349    static private class RemoteGreenstoneServerAuthenticator
     
    366384        }
    367385        catch (Exception exception) {
     386        System.err.println("Exception occurred when authenticating the user: " + exception);
    368387        DebugStream.printStackTrace(exception);
    369388        }
Note: See TracChangeset for help on using the changeset viewer.