Changeset 19428

Show
Ignore:
Timestamp:
13.05.2009 13:52:42 (10 years ago)
Author:
ak19
Message:

Made Server2.java run PortFinder?.isPortAvailable() check in new silent mode that only displays real error messages instead of the quasi-debug messages.

Location:
greenstone3/trunk/src/java/org/greenstone/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/PortFinder.java

    r18992 r19428  
    2828    this( PORTS_RESERVED+1, (MAX_PORT - PORTS_RESERVED) ); 
    2929    } 
    30          
     30 
    3131    public PortFinder(int base, int blocksize) { 
    3232    PORT_BASE = base; 
     
    4646     *  @return the number of an available port.     
    4747     */ 
    48     public int findPortInRange() throws Exception {  
     48    public int findPortInRange(boolean silent) throws Exception {    
    4949    try { 
    5050        boolean foundFreePort = false; 
    5151        for(int i = 0; i < PORT_BLOCK_SIZE; i++) { 
    5252         
    53         if(isPortAvailable(nextFreePort)) { 
     53        if(isPortAvailable(nextFreePort, silent)) { 
    5454            foundFreePort = true; 
    5555            break; 
     
    107107 
    108108    /** @return true if the portnum is available for use */ 
    109     public static boolean isPortAvailable(int portnum) { 
     109    public static boolean isPortAvailable(int portnum, boolean silent) { 
    110110    ServerSocket tmpSocket = null; 
    111111    try { 
    112112        tmpSocket = new ServerSocket(portnum); 
    113113        tmpSocket.close(); 
    114         //System.err.println("Port " + portnum + " not yet in use."); 
     114        if(!silent) { 
     115        System.err.println("Port " + portnum + " not yet in use."); 
     116        } 
    115117        return true; 
    116118         
     
    119121        // socket to a local address and port. Typically, the port is  
    120122        // in use, or the requested local address could not be assigned." 
    121         System.err.println("Port " + portnum + " already in use or can't be assigned."); 
     123        if(!silent) { 
     124        System.err.println("Port " + portnum + " already in use or can't be assigned."); 
     125        } 
    122126        tmpSocket = null; 
    123127        return false;        
  • greenstone3/trunk/src/java/org/greenstone/server/Server2.java

    r19241 r19428  
    211211    try { 
    212212        int portNum = Integer.parseInt(port); 
    213          
    214         if(!PortFinder.isPortAvailable(portNum)) { 
     213        boolean silent = true; 
     214        if(!PortFinder.isPortAvailable(portNum, silent)) { 
    215215         
    216216        PortFinder portFinder = new PortFinder(portDefault, 101); 
    217         portNum = portFinder.findPortInRange(); 
     217        portNum = portFinder.findPortInRange(silent); 
    218218        port = (portNum == -1) ? Integer.toString(portDefault) : Integer.toString(portNum); 
    219219        config_properties.setProperty("portnumber", port); // store the correct port