Changeset 19544

Show
Ignore:
Timestamp:
20.05.2009 18:50:16 (10 years ago)
Author:
ak19
Message:

Put back and corrected the GLI code that was recently reverted for dealing with a GSI that's started independently of GLI (via gs2-server.sh) and which has started the server or not yet autoentered the library. Now it works for Linux.

Location:
gli/trunk/src/org/greenstone/gatherer
Files:
3 modified

Legend:

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

    r19513 r19544  
    367367 
    368368        // Check that we now know the Greenstone library URL, since we need this for previewing collections 
     369        // It is not necessary if an independent GSI was launched and the user hasn't pressed Enter Library yet 
    369370        DebugStream.println("Configuration.library_url = " + Configuration.library_url); 
    370         if (Configuration.library_url == null) { 
     371        if (Configuration.library_url == null && !LocalLibraryServer.isURLPending()) { 
    371372        missingEXEC();  
    372373        } 
  • gli/trunk/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java

    r19513 r19544  
    140140    static public boolean isRunning() 
    141141    { 
    142     if (!running) return false; 
     142    if (!running) return false; // if the url is pending, then running would also be false (server not started up yet) 
     143 
    143144    llssite_cfg_file.load(true); 
    144     if (llssite_cfg_file.getURL() == null)  return false; 
     145    String url = llssite_cfg_file.getURL(); 
     146    if (url == null) return false; 
     147     
     148    // Called by Gatherer to check whether we need to stop the server. 
     149    // if the url is pending, then the GSI hasn't started the server up yet 
     150    // Already covered in !running 
     151    //if (url.equals(LLSSiteConfig.URL_PENDING)) return false; 
     152 
    145153    return true; 
    146154    } 
     
    184192 
    185193    llssite_cfg_file = new LLSSiteConfig(local_library_server_file); 
    186      
     194         
     195    // If the user launched the GSI independent of GLI, but user has not pressed 
     196    // Enter Library yet, then we will obtain the previewURL later. 
     197    if(LocalLibraryServer.isURLPending()) { 
     198        // running is still false when the URL is pending because only GSI is running, not the server 
     199        return; 
     200    } else if(llssite_cfg_file.isIndependentGSI()) { 
     201        // there is a url, it's not pending, and it is llssite.cfg: meaning GSI has started up 
     202        return;      
     203    } 
     204 
    187205    // Spawn local library server process 
    188206    String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file); 
     
    215233    // Wait until program has started 
    216234    try { 
    217         testServerRunning(); // will set running = true when the server is up and running successfully 
     235        testServerRunning(); // will set running = true when the server is up and running successfully       
    218236    } catch (IOException bad_url_connection) { 
    219237        try { 
     
    236254    static public void stop() 
    237255    { 
    238     if (running == false) { 
     256    if (!running) { 
     257        // also the case if the URL is pending in an independently launched GSI 
     258        return; 
     259    } 
     260 
     261    // don't (can't) shutdown the GSI/server if it was launched independent of GLI 
     262    if(llssite_cfg_file.isIndependentGSI()) { 
    239263        return; 
    240264    } 
     
    255279    llssite_cfg_file.load(false); 
    256280    int attempt_count = 0; 
    257     while (llssite_cfg_file.getURL() != null) { 
     281    String url = llssite_cfg_file.getURL(); 
     282    while (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) { // if pending, the server is already stopped (not running) 
    258283        new OneSecondWait();  // Wait one second (give or take) 
    259284        llssite_cfg_file.load(false); 
     
    269294        attempt_count = 0; 
    270295        } 
     296        // read the url again to see if it's updated 
     297        url = llssite_cfg_file.getURL(); 
    271298    } 
    272299 
     
    275302 
    276303    // If the local server is still running then our changed values will get overwritten. 
    277     if (llssite_cfg_file.getURL() != null) { 
     304    url = llssite_cfg_file.getURL(); 
     305    if (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) { 
    278306        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.QuitManual"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
    279307    } 
     
    346374    } 
    347375 
     376    /** Returns true if we're waiting on the user to click on Enter Library button 
     377     * in an independently launched GSI (one not launched by GLI). */ 
     378    static public boolean isURLPending() { 
     379    /*if(Configuration.library_url != null) { 
     380        System.err.println("**** Configuration.library_url: " + Configuration.library_url ); 
     381        return false; // don't need to do anything as we already have the url 
     382        }*/ 
     383 
     384    llssite_cfg_file.load(true); // don't force reload, load only if modified 
     385 
     386    String url = llssite_cfg_file.getURL(); 
     387 
     388    if(url != null) { 
     389        if(url.equals(LLSSiteConfig.URL_PENDING)) { 
     390        running = false; // imagine if they restarted an external GSI 
     391        return true;  
     392        } else { 
     393        // a valid URL at last 
     394        try { 
     395            Configuration.library_url = new URL(url); 
     396            running = true; 
     397        } 
     398        catch (MalformedURLException exception) { 
     399            exception.printStackTrace(); 
     400            DebugStream.printStackTrace(exception); 
     401        } 
     402        return false; 
     403        } 
     404    } 
     405 
     406    // If either the URL is null--which means no independent GSI (Greenstone server interface 
     407    // app) was launched--or if the 'URL' doesn't say it's pending, then we're not waiting 
     408    return false; 
     409    } 
     410 
    348411    static public void checkServerRunning() { 
    349     if (!running) return; // don't worry about it if its not supposed to be running  
     412    if (!running) return; // don't worry about it if it's not supposed to be running  
    350413    llssite_cfg_file.load(true); // don't force reload, load only if modified 
    351  
     414     
    352415    String url = llssite_cfg_file.getURL(); 
    353416    if(url != null) { 
     
    357420        catch (MalformedURLException exception) { 
    358421        DebugStream.printStackTrace(exception); 
     422        exception.printStackTrace(); 
    359423        } 
    360424    } else { 
    361425        // need to restart the server again 
    362         llssite_cfg_file.set(); 
    363  
     426  
     427        // if we were running an independently launched GSI before, but the GSI has been 
     428        // exited, it would need to be relaunched, but from within GLI (dependent) this time. 
     429        if(llssite_cfg_file.isIndependentGSI()) { 
     430        // first save the current configFile (llssite.cfg), then set to use glisite.cfg 
     431        llssite_cfg_file.save(); 
     432        llssite_cfg_file.relaunchAsDependentGSI(local_library_server_file); 
     433        } else { 
     434        // We were using glisite.cfg before, don't need to swap config files 
     435        llssite_cfg_file.set(); 
     436        } 
    364437        // Spawn local library server process 
    365438        String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file); 
     
    391464 
    392465    static public class LLSSiteConfig 
    393     extends LinkedHashMap { 
     466    extends LinkedHashMap  
     467    { 
     468    private File configFile; 
     469 
    394470    private File llssite_cfg; 
    395471    private File glisite_cfg; 
     
    414490    static final private String URL = "url"; 
    415491 
     492    static final public String URL_PENDING = "URL_pending"; 
     493 
    416494    public LLSSiteConfig(File server_exe) { 
    417495        debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath()); 
     
    420498        glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG); 
    421499 
    422         File configFile = null; 
     500        configFile = null; 
     501 
     502        autoenter_initial = null; 
     503        start_browser_initial = null; 
     504         
     505        // first test if server was started independently of GLI 
     506        // if so, the config file we'd be using would be llssite.cfg 
     507        if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in 
     508        // else we try using the glisite configfile 
     509        useGLISiteCfg(server_exe); 
     510        } 
     511 
     512        if(configFile != null && configFile.exists()) { 
     513        System.err.println("Using configfile: " + configFile); 
     514        lastModified = configFile.lastModified(); 
     515        } 
     516    } 
     517 
     518    /** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */ 
     519    public void useGLISiteCfg(File server_exe) { 
    423520        if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file 
    424  
     521         
    425522        File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in"); 
    426523        File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in"); 
    427  
     524         
    428525        // need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in 
    429526        if(glisite_cfg_in.exists()) { 
     
    441538        } 
    442539        } 
    443  
     540        // use the config file now 
    444541        if(glisite_cfg.exists()) { 
    445542        configFile = glisite_cfg; 
     543        load(false); // force reload 
    446544        }  
    447  
    448         autoenter_initial = null; 
    449         start_browser_initial = null; 
    450         if(configFile != null) { 
     545    } 
     546 
     547    /** Tests whether the server interface is up, running independently of GLI 
     548     * If so, we don't need to launch the server interface. 
     549     * The server interface may not have started up the server itself though 
     550     * (in which case the server URL would be URL_PENDING). 
     551     * This method returns true if the server interface has already started 
     552     * and, if so, it would have loaded in the llssite_cfg configFile. 
     553     */ 
     554    private boolean usingLLS_configFile() { 
     555        if(!llssite_cfg.exists()) { 
     556        return false; 
     557        } 
     558 
     559        // check if the configfile contains the URL line 
     560        configFile = llssite_cfg; 
     561        load(false); // force load 
     562 
     563        if(getURL() == null) { 
     564        configFile = null; 
     565        clear(); // we're not using llssite_cfg, so clear the values we just read 
     566        return false; 
     567        } 
     568 
     569        //System.err.println("***** we're using llssite_configfile, url:" + getURL()); 
     570        return true; 
     571    } 
     572     
     573    /** @return true if GSI was started up independently and outside of GLI.  
     574     * In such a case, GLI would be using llssite_cfg. */ 
     575    public boolean isIndependentGSI() { 
     576        return (configFile == llssite_cfg); 
     577    } 
     578 
     579    /** Call this when an independently launched GSI server has been stopped 
     580     * (one using llssite_cfg) and GLI needs to next launch another server. 
     581     * In such a case, since GLI itself is relaunching the GSI, we use glisite_cfg. 
     582    */ 
     583    public void relaunchAsDependentGSI(File server_exe) { 
     584        useGLISiteCfg(server_exe); 
     585    } 
     586 
     587    public boolean exists() { 
     588        return configFile.exists(); 
     589    } 
     590 
     591    public String getLocalHostURL() { 
     592        StringBuffer url = new StringBuffer(LOCAL_HOST); 
     593        url.append(COLON); 
     594        url.append((String)get(PORTNUMBER)); 
     595        String enterlib = (String)get(ENTERLIB); 
     596        if(enterlib == null || enterlib.length() == 0) { 
     597        // Use the default /gsdl and hope for the best. 
     598        url.append(SEPARATOR); 
     599        url.append(GSDL); 
     600        } 
     601        else { 
     602        if(!enterlib.startsWith(SEPARATOR)) { 
     603            url.append(SEPARATOR); 
     604        } 
     605        url.append(enterlib); 
     606        } 
     607        enterlib = null; 
     608        debug("Found Local Library Address: " + url.toString()); 
     609        return url.toString(); 
     610    } 
     611 
     612    /** @return the cmd-line parameter for the configfile used to launch 
     613     * the server through GLI: --config <glisite.cfg/llssite.cfg file path>. */ 
     614    public String getSiteConfigFilename() { 
     615        return SPECIFIC_CONFIG + configFile.getAbsolutePath(); 
     616    } 
     617 
     618    public String getURL() { 
     619        // URL is made from url and portnumber 
     620        String url = (String) get(URL); 
     621 
     622        // server interface is already up, independent of GLI 
     623        // but it has not started the server (hence URL is pending)  
     624        if(url != null && url.equals(URL_PENDING)) { 
     625        return url; 
     626        } 
     627 
     628        if(!Utility.isWindows()) { 
     629        return url; 
     630        } 
     631 
     632        if(url != null) { 
     633        StringBuffer temp = new StringBuffer(url); 
     634        temp.append(COLON); 
     635        temp.append((String)get(PORTNUMBER)); 
     636        String enterlib = (String)get(ENTERLIB); 
     637        if(enterlib == null || enterlib.length() == 0) { 
     638            // Use the default /greenstone prefix and hope for the best. 
     639            temp.append(SEPARATOR); 
     640            temp.append(GSDL); 
     641        } 
     642        else { 
     643            if(!enterlib.startsWith(SEPARATOR)) { 
     644            temp.append(SEPARATOR); 
     645            } 
     646            temp.append(enterlib); 
     647        } 
     648        enterlib = null; 
     649        url = temp.toString(); 
     650        } 
     651        debug("Found Local Library Address: " + url); 
     652        return url; 
     653    } 
     654 
     655    public boolean isModified() { 
     656        return (lastModified != configFile.lastModified()); 
     657    } 
     658 
     659    public void load(boolean reloadOnlyIfModified) {         
     660 
     661        if(configFile == null) { 
     662        debug(configFile.getAbsolutePath() + " cannot be found!"); 
     663        } 
     664 
     665        if(isModified()) { 
     666        lastModified = configFile.lastModified(); 
     667        } else if(reloadOnlyIfModified) { 
     668        return; // asked to reload only if modified. Don't reload since not modified 
     669        } 
     670 
     671        if(configFile.exists()) { 
    451672        debug("Load: " + configFile.getAbsolutePath()); 
    452673        clear(); 
     
    473694        } 
    474695        } 
    475  
    476         if(glisite_cfg.exists()) { 
    477         lastModified = glisite_cfg.lastModified(); 
    478         } 
    479     } 
    480      
    481     public boolean exists() { 
    482         return llssite_cfg.exists(); 
    483     } 
    484  
    485     public String getLocalHostURL() { 
    486         StringBuffer url = new StringBuffer(LOCAL_HOST); 
    487         url.append(COLON); 
    488         url.append((String)get(PORTNUMBER)); 
    489         String enterlib = (String)get(ENTERLIB); 
    490         if(enterlib == null || enterlib.length() == 0) { 
    491         // Use the default /gsdl and hope for the best. 
    492         url.append(SEPARATOR); 
    493         url.append(GSDL); 
    494         } 
    495696        else { 
    496         if(!enterlib.startsWith(SEPARATOR)) { 
    497             url.append(SEPARATOR); 
    498         } 
    499         url.append(enterlib); 
    500         } 
    501         enterlib = null; 
    502         debug("Found Local Library Address: " + url.toString()); 
    503         return url.toString(); 
    504     } 
    505  
    506     public String getSiteConfigFilename() { 
    507         return SPECIFIC_CONFIG + glisite_cfg.getAbsolutePath(); 
    508     } 
    509  
    510     public String getURL() { 
    511         // URL is made from url and portnumber 
    512         String url = (String) get(URL); 
    513  
    514         if(!Utility.isWindows()) { 
    515         return url; 
    516         } 
    517  
    518         if(url != null) { 
    519         StringBuffer temp = new StringBuffer(url); 
    520         temp.append(COLON); 
    521         temp.append((String)get(PORTNUMBER)); 
    522         String enterlib = (String)get(ENTERLIB); 
    523         if(enterlib == null || enterlib.length() == 0) { 
    524             // Use the default /gsdl and hope for the best. 
    525             temp.append(SEPARATOR); 
    526             temp.append(GSDL); 
    527         } 
    528         else { 
    529             if(!enterlib.startsWith(SEPARATOR)) { 
    530             temp.append(SEPARATOR); 
    531             } 
    532             temp.append(enterlib); 
    533         } 
    534         enterlib = null; 
    535         url = temp.toString(); 
    536         } 
    537         debug("Found Local Library Address: " + url); 
    538         return url; 
    539     } 
    540  
    541     public boolean isModified() { 
    542         return (lastModified != glisite_cfg.lastModified()); 
    543     } 
    544  
    545     public void load(boolean reloadOnlyIfModified) {         
    546  
    547         if(isModified()) { 
    548         lastModified = glisite_cfg.lastModified(); 
    549         } else if(reloadOnlyIfModified) { 
    550         return; // asked to reload only if modified. Don't reload since not modified 
    551         } 
    552  
    553         if(glisite_cfg.exists()) { 
    554         debug("Load: " + glisite_cfg.getAbsolutePath()); 
    555         clear(); 
    556         try { 
    557             BufferedReader in = new BufferedReader(new FileReader(glisite_cfg)); 
    558             String line = null; 
    559             while((line = in.readLine()) != null) { 
    560             String key = null; 
    561             String value = null; 
    562             int index = -1; 
    563             if((index = line.indexOf("=")) != -1 && line.length() >= index + 1) { 
    564                 key = line.substring(0, index); 
    565                 value = line.substring(index + 1); 
    566             } 
    567             else { 
    568                 key = line; 
    569             } 
    570             put(key, value); 
    571             } 
    572             in.close(); 
    573         } 
    574         catch (Exception error) { 
    575             error.printStackTrace(); 
    576         } 
    577         } 
    578         else { 
    579         debug("No glisite.cfg file can be found!"); 
     697        debug(configFile.getAbsolutePath() + " cannot be found!"); 
    580698        } 
    581699    } 
     
    583701    /** Restore the autoenter value to its initial value, and remove url if present. */ 
    584702    public void restore() { 
    585         if(glisite_cfg != null) { 
     703        if(configFile != null) { 
    586704        // Delete the file 
    587         glisite_cfg.delete(); 
     705        configFile.delete(); 
    588706        } 
    589707        else { 
     
    617735    private void save() { 
    618736        //debug("Save: " + llssite_cfg.getAbsolutePath()); 
    619         debug("Save: " + glisite_cfg.getAbsolutePath()); 
     737        debug("Save: " + configFile.getAbsolutePath()); 
    620738        try { 
    621739        //BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false)); 
    622         BufferedWriter out = new BufferedWriter(new FileWriter(glisite_cfg, false)); 
     740        BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false)); 
    623741        for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { 
    624742            String key = (String) keys.next(); 
     
    627745            if(value != null) { 
    628746            out.write('='); 
    629             out.write(value, 0, value.length()); 
     747             
     748            // if the server is using llssite.cfg, don't overwrite its default 
     749            // autoenter and startbrowser values 
     750            if(configFile == llssite_cfg && (key == AUTOENTER || key == STARTBROWSER)) { 
     751                if(key == AUTOENTER) { 
     752                out.write(autoenter_initial, 0, autoenter_initial.length()); 
     753                } else { // STARTBROWSER 
     754                out.write(start_browser_initial, 0, start_browser_initial.length()); 
     755                } 
     756             } else { 
     757                 out.write(value, 0, value.length()); 
     758            } 
    630759            } 
    631760            out.newLine(); 
  • gli/trunk/src/org/greenstone/gatherer/gui/PreviewButton.java

    r19513 r19544  
    3535import javax.swing.*; 
    3636import org.greenstone.gatherer.Configuration; 
     37import org.greenstone.gatherer.Dictionary; 
    3738import org.greenstone.gatherer.Gatherer; 
    3839import org.greenstone.gatherer.collection.CollectionManager; 
     
    134135        Gatherer.c_man.saveCollection(); 
    135136         
    136         configureHomeURL(); 
     137        if(LocalLibraryServer.isURLPending()) { 
     138        // Remind the user to press Enter Library, and return from this method 
     139        JOptionPane.showMessageDialog(Gatherer.g_man, 
     140                          Dictionary.get("General.LLS_Not_Started"),  
     141                          Dictionary.get("General.LLS_Not_Started_Title"), 
     142                          JOptionPane.ERROR_MESSAGE); 
     143        return; 
     144         
     145        } else { 
     146        configureHomeURL(); 
     147        } 
    137148         
    138149        if (Gatherer.GS3) {