Changeset 24207

Show
Ignore:
Timestamp:
28.06.2011 17:07:42 (9 years ago)
Author:
ak19
Message:

Part 1 of 2 commits for ticket 766 (the other commits will be in GS2): the GSI settings dialog now provides the ability to freeze the port number.

Location:
main/trunk/greenstone3
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/build.properties.in

    r23849 r24207  
    2626# does running the server automatically start up Tomcat and a browser 
    2727server.auto.start=false 
     28# if set to true, won't try other ports if the specified port is not available 
     29server.keep.port=false 
    2830# default servlet to start with 
    2931server.default.servlet=/library 
  • main/trunk/greenstone3/resources/java/server.properties

    r20948 r24207  
    1818ServerSettings.Title=Server settings 
    1919ServerSettings.Auto_Start=Enter the library automatically 
     20ServerSettings.Keep_Port=Do not modify port 
    2021ServerSettings.OK=OK 
    2122ServerSettings.Cancel=Cancel 
  • main/trunk/greenstone3/src/java/org/greenstone/server/BaseProperty.java

    r22054 r24207  
    66    public final String GSDL_VERSION; 
    77    public final String AUTOSTART; 
     8    public final String KEEPPORT; 
    89    public final String START_BROWSER; 
    910 
     
    2122    public final String SERVER_SETTINGS; 
    2223     
    23     protected BaseProperty(String version, String web_port, String autostart, String startbrowser)  
     24    protected BaseProperty(String version, String web_port, String autostart, String startbrowser, String keepport)  
    2425    { 
    2526    // property names 
     
    3132    AUTOSTART = autostart; 
    3233    START_BROWSER = startbrowser; 
     34    KEEPPORT = keepport; 
    3335    } 
    3436 
  • main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java

    r22085 r24207  
    2121 
    2222    protected JCheckBox autoEnter; 
     23    protected JCheckBox keepPortToggle; 
    2324 
    2425    protected JSpinner portNumber_spinner = null; 
     
    3132    protected int portNum = DEFPORT; 
    3233    protected boolean autoStart = false; 
     34    protected boolean keepPort = false; 
    3335    protected String browserPath = ""; 
    3436    protected boolean useDefaultBrowser = true; 
     
    6769    } 
    6870 
     71    String keep_port_str = server.config_properties.getProperty(BaseServer.Property.KEEPPORT).trim(); 
     72    if (keep_port_str.equals("true") || keep_port_str.equals("1")) { 
     73        this.keepPort = true; 
     74    } else { 
     75        this.keepPort = false; 
     76    } 
     77 
     78 
    6979    setTitle(server.dictionary.get("ServerSettings.Title")); 
    7080    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 
     
    7686 
    7787    autoEnter = new JCheckBox(server.dictionary.get("ServerSettings.Auto_Start")); 
     88    keepPortToggle = new JCheckBox(server.dictionary.get("ServerSettings.Keep_Port")); 
    7889     
    7990    if (autoStart) { 
     
    8394    } 
    8495    autoEnter.setBackground(bg_color); 
     96 
     97    if(keepPort) { 
     98        keepPortToggle.setSelected(true); 
     99    } else { 
     100        keepPortToggle.setSelected(false); 
     101    } 
     102    keepPortToggle.setBackground(bg_color); 
    85103 
    86104 
     
    107125    port_panel.setBackground(bg_color); 
    108126 
    109     JPanel top_panel = new JPanel(new GridLayout(2,1)); 
     127    JPanel top_panel = new JPanel(new GridLayout(3,1)); 
    110128    top_panel.add(port_panel); 
     129    top_panel.add(keepPortToggle); 
    111130    top_panel.add(autoEnter); 
    112131 
     
    227246                has_changed = true; 
    228247        } 
     248        if (keepPort != keepPortToggle.isSelected()) { 
     249                has_changed = true; 
     250        } 
     251 
    229252 
    230253        // call subclass' onSave method, which may indicate (further) changes, 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java

    r23251 r24207  
    2626import org.greenstone.server.BaseServer; 
    2727import org.greenstone.server.BaseProperty; 
     28 
    2829 
    2930public class Server2 extends BaseServer  
     
    287288        suffix = httpprefix + suffix; 
    288289    } 
    289      
     290 
    290291    libraryURL = "http://" + host + ":" + port + suffix; 
    291292    } 
     
    297298    // first choice is port 80, second choice starts at 8282 
    298299    String port = config_properties.getProperty("portnumber", "80"); 
     300    String keepport = config_properties.getProperty("keepport", "0"); // default is to not try to keep the same port 
     301 
    299302    int portDefault = 8282; 
    300303    try { 
     
    302305        boolean verbose = true; 
    303306        if(!PortFinder.isPortAvailable(portNum, verbose)) { // first time, print any Port Unavailable messages 
    304          
    305         PortFinder portFinder = new PortFinder(portDefault, 101); 
    306         // Search for a free port silently from now on--don't want more 
    307         // messages saying that a port could not be found... 
    308         portNum = portFinder.findPortInRange(!verbose); 
    309          
    310         if (portNum == -1) { 
    311             // If we've still not found a free port, do we try the default port again? 
    312             System.err.println("No free port found. Going to try on " + portDefault + " anyway."); 
    313             port = Integer.toString(portDefault); 
     307        if(keepport.equals("1")) { 
     308            String errorMsg = "Unable to run the Greenstone server on port " + port + ". It may already be in use."; 
     309            System.err.println("\n******************"); 
     310            logger_.error(errorMsg); 
     311            System.err.println("If you wish to try another port, go to File > Settings of the Greenstone Server interface and either change the port number or untick the \"Do Not Modify Port\" option there. Then press the \"Enter Library\" button."); 
     312            System.err.println("******************\n"); 
    314313        } else { 
    315             port = Integer.toString(portNum); 
    316         } 
    317         config_properties.setProperty("portnumber", port); // store the correct port 
    318  
    319         // write this updated port to the config file, since the configure target uses the file to run 
    320         ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 
    321         ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 
    322         scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 
    323         scriptReadWrite.writeOutFile(config_properties_file, fileLines); 
    324  
    325         configure_required_ = true; 
    326         System.err.println("Running server on port " + port + "."); 
     314 
     315            PortFinder portFinder = new PortFinder(portDefault, 101); 
     316            // Search for a free port silently from now on--don't want more 
     317            // messages saying that a port could not be found... 
     318            portNum = portFinder.findPortInRange(!verbose); 
     319             
     320            if (portNum == -1) { 
     321            // If we've still not found a free port, do we try the default port again? 
     322            System.err.println("No free port found. Going to try on " + portDefault + " anyway."); 
     323            port = Integer.toString(portDefault); 
     324            } else { 
     325            port = Integer.toString(portNum); 
     326            } 
     327            config_properties.setProperty("portnumber", port); // store the correct port 
     328             
     329            // write this updated port to the config file, since the configure target uses the file to run 
     330            ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 
     331            ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 
     332            scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 
     333            scriptReadWrite.writeOutFile(config_properties_file, fileLines); 
     334             
     335            configure_required_ = true; 
     336            System.err.println("Running server on port " + port + "."); 
     337        } 
    327338        }     
    328339    } catch (Exception e) { 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2Property.java

    r18868 r24207  
    99    // Initialising customised final variables  
    1010    // Version number, WEB_PORT 
    11     super("2", "portnumber", "autoenter", "start_browser"); 
     11    super("2", "portnumber", "autoenter", "start_browser", "keepport"); 
    1212    } 
    1313 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2Settings.java

    r23251 r24207  
    109109        newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
    110110    } 
     111    boolean keep_port = keepPortToggle.isSelected(); 
     112    if(keepPort != keep_port) { 
     113        String newKeepPort = keep_port ? "1" : "0"; 
     114        newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort); 
     115    } 
    111116 
    112117    // external access - onSave() would have updated this value 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server3Property.java

    r18868 r24207  
    1010    // Version number, WEB_PORT, autoenter, startbrowser 
    1111    // For GS3, the last two are controlled by the same property 
    12     super("3", "tomcat.port", "server.auto.start", "server.auto.start"); 
     12    super("3", "tomcat.port", "server.auto.start", "server.auto.start", "server.keep.port"); 
    1313    } 
    1414 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server3Settings.java

    r22085 r24207  
    9393    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
    9494 
     95    String newKeepPort = (new Boolean(keepPortToggle.isSelected())).toString(); 
     96    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort); 
     97 
    9598    String newServletDef = (String) servlet_combobox.getSelectedItem(); 
    9699    newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.DEFAULT_SERVLET, (String) url_mappings.get(newServletDef));