Changeset 19513


Ignore:
Timestamp:
2009-05-18T16:10:45+12:00 (15 years ago)
Author:
ak19
Message:

Reverting to before recent commits for working with independently launched GSI (which wrote out URL_pending to llssite.cfg file)

Location:
gli/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/classes/dictionary.properties

    r19504 r19513  
    618618General.Edit:Edit Value
    619619General.Error:Error
    620 General.LLS_Not_Started:You've launched the Greenstone server, but not pressed its Enter Library button yet.\nOnce you've done this, press Preview Collection in the Librarian Interface again to view the collection.
    621 General.LLS_Not_Started_Title:Local Library Server not started yet.
    622620General.No:No
    623621General.NotSunJava:Java vendor: {0}\nNote that the Librarian Interface has been developed and tested with Java from Sun Microsystems.
  • gli/trunk/src/org/greenstone/gatherer/Gatherer.java

    r19506 r19513  
    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
    370369        DebugStream.println("Configuration.library_url = " + Configuration.library_url);
    371         if (Configuration.library_url == null && !LocalLibraryServer.isURLPending()) {
     370        if (Configuration.library_url == null) {
    372371        missingEXEC();
    373372        }
  • gli/trunk/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java

    r19508 r19513  
    140140    static public boolean isRunning()
    141141    {
    142     if (!running) return false; // if the url is pending, then running would also be false (server not started up yet)
    143 
     142    if (!running) return false;
    144143    llssite_cfg_file.load(true);
    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 
     144    if (llssite_cfg_file.getURL() == null)  return false;
    153145    return true;
    154146    }
     
    192184
    193185    llssite_cfg_file = new LLSSiteConfig(local_library_server_file);
    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     }
    201 
     186   
    202187    // Spawn local library server process
    203188    String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file);
     
    251236    static public void stop()
    252237    {
    253     if (!running) {
    254         // also the case if the URL is pending in an independently launched GSI
    255         return;
    256     }
    257 
    258     // don't (can't) shutdown the GSI/server if it was launched independent of GLI
    259     if(llssite_cfg_file.isIndependentGSI()) {
    260         System.err.println("**** EXITING. Config file exists: " + llssite_cfg_file.exists());
     238    if (running == false) {
    261239        return;
    262240    }
     
    277255    llssite_cfg_file.load(false);
    278256    int attempt_count = 0;
    279     String url = llssite_cfg_file.getURL();
    280     while (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) { // if pending, the server is already stopped (not running)
     257    while (llssite_cfg_file.getURL() != null) {
    281258        new OneSecondWait();  // Wait one second (give or take)
    282259        llssite_cfg_file.load(false);
     
    292269        attempt_count = 0;
    293270        }
    294         // read the url again to see if it's updated
    295         url = llssite_cfg_file.getURL();
    296271    }
    297272
     
    300275
    301276    // If the local server is still running then our changed values will get overwritten.
    302     url = llssite_cfg_file.getURL();
    303     if (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) {
     277    if (llssite_cfg_file.getURL() != null) {
    304278        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.QuitManual"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    305279    }
     
    372346    }
    373347
    374     /** Returns true if we're waiting on the user to click on Enter Library button
    375      * in an independently launched GSI (one not launched by GLI). */
    376     static public boolean isURLPending() {
    377     if(Configuration.library_url != null) {
    378         return false; // don't need to do anything as  we already have the url
    379     }
    380 
     348    static public void checkServerRunning() {
     349    if (!running) return; // don't worry about it if its not supposed to be running
    381350    llssite_cfg_file.load(true); // don't force reload, load only if modified
    382351
    383     String url = llssite_cfg_file.getURL();
    384     System.err.println("**** url is: " + url);
    385 
    386     if(url != null) {
    387         if(url.equals(LLSSiteConfig.URL_PENDING)) {
    388         running = false; // imagine if they restarted an external GSI
    389         return true;
    390         } else {
    391         // a valid URL at last
    392         try {
    393             Configuration.library_url = new URL(url);
    394             System.err.println("**** set the config.library url to: " + Configuration.library_url);
    395             running = true;
    396         }
    397         catch (MalformedURLException exception) {
    398             exception.printStackTrace();
    399             DebugStream.printStackTrace(exception);
    400         }
    401         return false;
    402         }
    403     }
    404 
    405     // If either the URL is null--which means no independent GSI (Greenstone server interface
    406     // app) was launched--or if the 'URL' doesn't say it's pending, then we're not waiting
    407     return false;
    408     }
    409 
    410     static public void checkServerRunning() {
    411     if (!running) return; // don't worry about it if it's not supposed to be running
    412     llssite_cfg_file.load(true); // don't force reload, load only if modified
    413    
    414352    String url = llssite_cfg_file.getURL();
    415353    if(url != null) {
     
    422360    } else {
    423361        // need to restart the server again
    424  
    425         // if we were running an independently launched GSI before, but the GSI has been
    426         // exited, it would need to be relaunched, but from within GLI (dependent) this time.
    427         if(llssite_cfg_file.isIndependentGSI()) {
    428         // first save the current configFile (llssite.cfg), then set to use glisite.cfg
    429         llssite_cfg_file.save();
    430         llssite_cfg_file.relaunchAsDependentGSI(local_library_server_file);
    431         } else {
    432         // We were using glisite.cfg before, don't need to swap config files
    433         llssite_cfg_file.set();
    434         }
     362        llssite_cfg_file.set();
     363
    435364        // Spawn local library server process
    436365        String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file);
     
    462391
    463392    static public class LLSSiteConfig
    464     extends LinkedHashMap
    465     {
    466     private File configFile;
    467 
     393    extends LinkedHashMap {
    468394    private File llssite_cfg;
    469395    private File glisite_cfg;
     
    488414    static final private String URL = "url";
    489415
    490     static final public String URL_PENDING = "URL_pending";
    491 
    492416    public LLSSiteConfig(File server_exe) {
    493417        debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath());
     
    496420        glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG);
    497421
    498         configFile = null;
    499 
    500         autoenter_initial = null;
    501         start_browser_initial = null;
    502        
    503         // first test if server was started independently of GLI
    504         // if so, the config file we'd be using would be llssite.cfg
    505         if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in
    506         // else we try using the glisite configfile
    507         useGLISiteCfg(server_exe);
    508         }
    509 
    510         if(configFile != null && configFile.exists()) {
    511         lastModified = configFile.lastModified();
    512         }
    513     }
    514 
    515     /** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */
    516     public void useGLISiteCfg(File server_exe) {
     422        File configFile = null;
    517423        if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file
    518        
     424
    519425        File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in");
    520426        File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in");
    521        
     427
    522428        // need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in
    523429        if(glisite_cfg_in.exists()) {
     
    535441        }
    536442        }
    537         // use the config file now
     443
    538444        if(glisite_cfg.exists()) {
    539445        configFile = glisite_cfg;
    540         load(false); // force reload
    541446        }
    542     }
    543 
    544     /** Tests whether the server interface is up, running independently of GLI
    545      * If so, we don't need to launch the server interface.
    546      * The server interface may not have started up the server itself though
    547      * (in which case the server URL would be URL_PENDING).
    548      * This method returns true if the server interface has already started
    549      * and, if so, it would have loaded in the llssite_cfg configFile.
    550      */
    551     private boolean usingLLS_configFile() {
    552         if(!llssite_cfg.exists()) {
    553         return false;
    554         }
    555 
    556         // check if the configfile contains the URL line
    557         configFile = llssite_cfg;
    558         load(false); // force load
    559 
    560         if(getURL() == null) {
    561         configFile = null;
    562         clear(); // we're not using llssite_cfg, so clear the values we just read
    563         return false;
    564         }
    565 
    566         System.err.println("***** we're using llssite_configfile");
    567         return true;
    568     }
    569    
    570     /** @return true if GSI was started up independently and outside of GLI.
    571      * In such a case, GLI would be using llssite_cfg. */
    572     public boolean isIndependentGSI() {
    573         return (configFile == llssite_cfg);
    574     }
    575 
    576     /** Call this when an independently launched GSI server has been stopped
    577      * (one using llssite_cfg) and GLI needs to next launch another server.
    578      * In such a case, since GLI itself is relaunching the GSI, we use glisite_cfg.
    579     */
    580     public void relaunchAsDependentGSI(File server_exe) {
    581         useGLISiteCfg(server_exe);
    582     }
    583 
    584     public boolean exists() {
    585         return configFile.exists();
    586     }
    587 
    588     public String getLocalHostURL() {
    589         StringBuffer url = new StringBuffer(LOCAL_HOST);
    590         url.append(COLON);
    591         url.append((String)get(PORTNUMBER));
    592         String enterlib = (String)get(ENTERLIB);
    593         if(enterlib == null || enterlib.length() == 0) {
    594         // Use the default /gsdl and hope for the best.
    595         url.append(SEPARATOR);
    596         url.append(GSDL);
    597         }
    598         else {
    599         if(!enterlib.startsWith(SEPARATOR)) {
    600             url.append(SEPARATOR);
    601         }
    602         url.append(enterlib);
    603         }
    604         enterlib = null;
    605         debug("Found Local Library Address: " + url.toString());
    606         return url.toString();
    607     }
    608 
    609     /** @return the cmd-line parameter for the configfile used to launch
    610      * the server through GLI: --config <glisite.cfg/llssite.cfg file path>. */
    611     public String getSiteConfigFilename() {
    612         return SPECIFIC_CONFIG + configFile.getAbsolutePath();
    613     }
    614 
    615     public String getURL() {
    616         // URL is made from url and portnumber
    617         String url = (String) get(URL);
    618 
    619         // server interface is already up, independent of GLI
    620         // but it has not started the server (hence URL is pending)
    621         if(url != null && url.equals(URL_PENDING)) {
    622         return url;
    623         }
    624 
    625         if(!Utility.isWindows()) {
    626         return url;
    627         }
    628 
    629         if(url != null) {
    630         StringBuffer temp = new StringBuffer(url);
    631         temp.append(COLON);
    632         temp.append((String)get(PORTNUMBER));
    633         String enterlib = (String)get(ENTERLIB);
    634         if(enterlib == null || enterlib.length() == 0) {
    635             // Use the default /greenstone prefix and hope for the best.
    636             temp.append(SEPARATOR);
    637             temp.append(GSDL);
    638         }
    639         else {
    640             if(!enterlib.startsWith(SEPARATOR)) {
    641             temp.append(SEPARATOR);
    642             }
    643             temp.append(enterlib);
    644         }
    645         enterlib = null;
    646         url = temp.toString();
    647         }
    648         debug("Found Local Library Address: " + url);
    649         return url;
    650     }
    651 
    652     public boolean isModified() {
    653         return (lastModified != configFile.lastModified());
    654     }
    655 
    656     public void load(boolean reloadOnlyIfModified) {       
    657 
    658         if(configFile == null) {
    659         debug(configFile.getAbsolutePath() + " cannot be found!");
    660         }
    661 
    662         if(isModified()) {
    663         lastModified = configFile.lastModified();
    664         } else if(reloadOnlyIfModified) {
    665         return; // asked to reload only if modified. Don't reload since not modified
    666         }
    667 
    668         if(configFile.exists()) {
     447
     448        autoenter_initial = null;
     449        start_browser_initial = null;
     450        if(configFile != null) {
    669451        debug("Load: " + configFile.getAbsolutePath());
    670452        clear();
     
    691473        }
    692474        }
     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        }
    693495        else {
    694         debug(configFile.getAbsolutePath() + " cannot be found!");
     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!");
    695580        }
    696581    }
     
    698583    /** Restore the autoenter value to its initial value, and remove url if present. */
    699584    public void restore() {
    700         if(configFile != null) {
     585        if(glisite_cfg != null) {
    701586        // Delete the file
    702         configFile.delete();
     587        glisite_cfg.delete();
    703588        }
    704589        else {
     
    732617    private void save() {
    733618        //debug("Save: " + llssite_cfg.getAbsolutePath());
    734         debug("Save: " + configFile.getAbsolutePath());
     619        debug("Save: " + glisite_cfg.getAbsolutePath());
    735620        try {
    736621        //BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false));
    737         BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false));
     622        BufferedWriter out = new BufferedWriter(new FileWriter(glisite_cfg, false));
    738623        for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
    739624            String key = (String) keys.next();
     
    742627            if(value != null) {
    743628            out.write('=');
    744            
    745             // if the server is using llssite.cfg, don't overwrite its default
    746             // autoenter and startbrowser values
    747             if(configFile == llssite_cfg && (key == AUTOENTER || key == STARTBROWSER)) {
    748                 if(key == AUTOENTER) {
    749                 out.write(autoenter_initial, 0, autoenter_initial.length());
    750                 } else { // STARTBROWSER
    751                 out.write(start_browser_initial, 0, start_browser_initial.length());
    752                 }
    753              } else {
    754                  out.write(value, 0, value.length());
    755             }
     629            out.write(value, 0, value.length());
    756630            }
    757631            out.newLine();
  • gli/trunk/src/org/greenstone/gatherer/gui/PreviewButton.java

    r19507 r19513  
    3535import javax.swing.*;
    3636import org.greenstone.gatherer.Configuration;
    37 import org.greenstone.gatherer.Dictionary;
    3837import org.greenstone.gatherer.Gatherer;
    3938import org.greenstone.gatherer.collection.CollectionManager;
     
    135134        Gatherer.c_man.saveCollection();
    136135       
    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         }
     136        configureHomeURL();
    148137       
    149138        if (Gatherer.GS3) {
Note: See TracChangeset for help on using the changeset viewer.