Ignore:
Timestamp:
2009-05-13T13:52:42+12:00 (15 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.

File:
1 edited

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;       
Note: See TracChangeset for help on using the changeset viewer.