Changeset 24505 for main/trunk/gli/src


Ignore:
Timestamp:
2011-08-27T19:47:40+12:00 (13 years ago)
Author:
ak19
Message:

Still part of the changes for introducing the --mode=gli flag that's passed to the GS2 server so that we can merge the two cfg files glisite and llssite. 1. Bugfix: need to trim the mode parameter read in the from the file, because some whitespace was left at the end of it. 2. Now the url property in the config file is also to be prefixed with the mode, so that GLI's LocalLibraryServer can work out whether GLI launched the GSI or whether it was launched independently (outside GLI).

File:
1 edited

Legend:

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

    r24499 r24505  
    1 /**
    21/**
    32 *############################################################################
     
    237236        return true;
    238237    } else if(llssite_cfg_file.isIndependentGSI()) {
    239         // there is a url, it's not pending, and it is llssite.cfg: meaning GSI has started up
     238        // There is already a url and it's not pending: meaning the server
     239        // has started up and that GSI was launched outside of GLI
    240240        running = true;
    241241        return true;   
     
    254254        // If it is already running then set the Greenstone web server address and we're done
    255255        // E.g. if previously GLI was not properly shut down, the URL property (signifying
    256         // the server is still running) would still be in the glisite_cfg file.
     256        // the server is still running) would still be in the config file.
    257257        try {
    258258        Configuration.library_url = new URL(url);
     
    582582        }
    583583    }
    584     else { // NO URL in current ConfigFile, check the other configfile for a URL
    585         // to see if the server was restarted using that file.
    586         // Otherwise need to restart the server again with GLIsite.cfg
    587         llssite_cfg_file.save(); // save the configfile, because we may be reloading another
    588 
    589         if(llssite_cfg_file.usingLLS_configFile()) { // if a GSI is already using llssite_cfg, this would have loaded it in
     584    else { // NO URL in current mode of configFile, try other mode (e.g. "gli.url")
     585           
     586        if(llssite_cfg_file.usingGSImode()) { // if a GSI is already using llssite_cfg, this would have loaded it in
    590587        url = llssite_cfg_file.getURL(); //if(isURLPending()) {
    591588        if(url.equals(LLSSiteConfig.URL_PENDING)) {
     
    597594        } else {
    598595        // else we try using the glisite configfile
    599         llssite_cfg_file.useGLISiteCfg(local_library_server_file);
     596        llssite_cfg_file.useGLImode();
    600597            //llssite_cfg_file.set();
    601        
     598               
    602599        // since we're going to restart the server, make sure to reset all
    603600        // the client socket and its writer (for communicating with the web server)
     
    657654    private File configFile;
    658655
    659     private File llssite_cfg;
    660     private File glisite_cfg;
    661656    private String autoenter_initial;
    662657    private String start_browser_initial;
    663658
    664659    private long lastModified = 0;
    665    
     660    private boolean isIndependentGSI;
     661   
    666662    static final private String GLI_PREFIX = "gli";
    667663    static final private String GSI_AUTOENTER = "autoenter";
     
    670666    static final private String ENTERLIB = "enterlib";
    671667    static final private String FALSE = "0";
    672     static final private String GLISITE_CFG = "glisite.cfg";
    673668    static final private String GSDL = "greenstone"; // httpprefix is no longer /gsdl but /greenstone
    674669    static final private String LLSSITE_CFG = "llssite.cfg";
     
    680675    static final private String GSI_STARTBROWSER = "start_browser";
    681676    static final private String TRUE = "1";
    682     static final private String URL = "url";
     677    static final private String URL = GLI_PREFIX+"."+"url";
     678    static final private String GSI_URL = "url";
    683679    static final private String COLLECTHOME = "collecthome";
    684680    static final private String GLIMODE = "--mode="+GLI_PREFIX;
     
    689685    public LLSSiteConfig(File server_exe) {
    690686        debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath());
    691        
    692         llssite_cfg = new File(server_exe.getParentFile(), LLSSITE_CFG);
    693         glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG);
    694 
    695         configFile = null;
     687       
     688        configFile = new File(server_exe.getParentFile(), LLSSITE_CFG);
     689        if(!configFile.exists()) { // create it from the template
     690            File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in");
     691       
     692            // need to generate llssite_cfg from llssite_cfg_in
     693            if(llssite_cfg_in.exists()) {
     694                copyConfigFile(llssite_cfg_in, configFile, true);   // adjust for gli
     695            }
     696            else {
     697                debug("File llssite.cfg.in can't be found. Can't create llssite.cfg frrom llssite.cfg.in.");               
     698            }
     699        }           
     700       
     701        // use the config file now
     702        if(configFile.exists()) {
     703            // first test if server was started independently of GLI
     704            // if so, the config file we'd be using would be llssite.cfg
     705            if(!usingGSImode()) { // if we were using llssite_cfg, this would have loaded it in
     706                // else we try using the glisite configfile
     707                useGLImode();
     708            }
     709           
     710        } else {
     711            System.err.println("**** ERROR. Configfile is null.");             
     712            configFile = null;
     713        }
    696714
    697715        autoenter_initial = null;
    698716        start_browser_initial = null;
    699        
    700         // first test if server was started independently of GLI
    701         // if so, the config file we'd be using would be llssite.cfg
    702         if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in
    703         // else we try using the glisite configfile
    704         useGLISiteCfg(server_exe);
    705         }
    706717       
    707718        // GS2. We're in the constructor, so we'll be running the LLS the first time
     
    733744
    734745    /** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */
    735     public void useGLISiteCfg(File server_exe)
     746    public void useGLImode()
    736747    {
    737         if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file
    738        
    739         File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in");
    740         File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in");
    741        
    742         // need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in
    743         if(glisite_cfg_in.exists()) {
    744             copyConfigFile(glisite_cfg_in, glisite_cfg, false);   
    745         }
    746         else if(llssite_cfg_in.exists()) {
    747             copyConfigFile(llssite_cfg_in, glisite_cfg_in, true); // adjust for glisite.cfg
    748             copyConfigFile(glisite_cfg_in, glisite_cfg, false);   
    749         }
    750         else if(llssite_cfg.exists()) {
    751             copyConfigFile(llssite_cfg, glisite_cfg, true);        // adjust for glisite.cfg
    752         }
    753         else {
    754             debug("Neither the file glisite.cfg nor llssite.cfg can be found!");
    755         }
    756         }
    757         // use the config file now
    758         if(glisite_cfg.exists()) {
    759         configFile = glisite_cfg;
    760         load(false); // force reload
    761         lastModified = configFile.lastModified();
    762         }
     748        isIndependentGSI = false;
     749        load(true); // reload if modified
    763750    }
    764751
     
    770757     * and, if so, it would have loaded in the llssite_cfg configFile.
    771758     */
    772     public boolean usingLLS_configFile() {
    773         if(!llssite_cfg.exists()) {
    774         return false;
    775         }
    776 
    777         // Now to check if the configfile contains the URL line
    778         configFile = llssite_cfg;
     759    public boolean usingGSImode() {
     760        // Now to check if the configfile contains the GSI_URL line     
    779761        load(false); // force load
    780 
     762        isIndependentGSI = true;
    781763        if(getURL() == null) {
    782         configFile = null;
    783         clear(); // we're not using llssite_cfg, so clear the values we just read
    784         return false;
     764            isIndependentGSI = false;
     765            return false;
    785766        }
    786767
     
    797778     * In such a case, GLI would be using llssite_cfg. */
    798779    public boolean isIndependentGSI() {
    799         return (configFile == llssite_cfg);
     780        return isIndependentGSI;
    800781    }
    801782
     
    832813
    833814    public String getURL() {
     815        String urlPropertyName = isIndependentGSI() ? GSI_URL : URL;
    834816        // URL is made from url and portnumber
    835         String url = (String) get(URL);
     817        String url = (String) get(urlPropertyName);
    836818
    837819        // server interface is already up, independent of GLI
     
    928910        }
    929911        else {
     912        String urlPropertyName = isIndependentGSI() ? GSI_URL : URL;
    930913        debug("Restore Initial Settings");
    931914        put(AUTOENTER, autoenter_initial);
    932915        put(STARTBROWSER, start_browser_initial);
    933         remove(URL);
     916        remove(urlPropertyName);
    934917        save();
    935918        }
     
    956939
    957940    private void save() {
    958         //debug("Save: " + llssite_cfg.getAbsolutePath());
    959941        debug("Save: " + configFile.getAbsolutePath());
    960942        try {
    961         //BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false));
    962943        BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false));
    963944        for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
     
    968949            out.write('=');
    969950           
    970             // if the server is using llssite.cfg, don't overwrite its default
     951            // if the GSI was launched outside of GLI, don't overwrite its default
    971952            // autoenter and startbrowser values
    972             if(configFile == llssite_cfg && (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) {
     953            if(isIndependentGSI && (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) {
    973954                if(key == GSI_AUTOENTER) {
    974955                out.write(autoenter_initial, 0, autoenter_initial.length());
     
    994975        // dest_cfg file should not yet exist
    995976        // If setToGliSiteDefaults is true, then GLIsite.cfg's default configuration
    996         // is applied to concerned lines: autoenter=1, and startbrowser=0
     977        // is applied to concerned lines: gli.autoenter=1, and gli.startbrowser=0
    997978
    998979        try {
Note: See TracChangeset for help on using the changeset viewer.