Ignore:
Timestamp:
2009-05-13T13:55:59+12:00 (15 years ago)
Author:
ak19
Message:

Method isPortAvailable() now passed a boolean parameter telling it whether to run in silent mode or not. In the former, it will only print out real error messages instead of quasi-debug messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/util/PortFinder.java

    r18991 r19429  
    4747     *  @return the number of an available port.   
    4848     */
    49     public int findPortInRange() throws Exception {
     49    public int findPortInRange(boolean silent) throws Exception {   
    5050    try {
    5151        boolean foundFreePort = false;
    5252        for(int i = 0; i < PORT_BLOCK_SIZE; i++) {
    5353       
    54         if(isPortAvailable(nextFreePort)) {
     54        if(isPortAvailable(nextFreePort, silent)) {
    5555            foundFreePort = true;
    5656            break;
     
    108108
    109109    /** @return true if the portnum is available for use */
    110     public static boolean isPortAvailable(int portnum) {
     110    public static boolean isPortAvailable(int portnum, boolean silent) {
    111111    ServerSocket tmpSocket = null;
    112112    try {
    113113        tmpSocket = new ServerSocket(portnum);
    114114        tmpSocket.close();
    115         //System.err.println("Port " + portnum + " not yet in use.");
     115        if(!silent) {
     116        System.err.println("Port " + portnum + " not yet in use.");
     117        }
    116118        return true;
    117119       
     
    120122        // socket to a local address and port. Typically, the port is
    121123        // in use, or the requested local address could not be assigned."
    122         System.err.println("Port " + portnum + " already in use or can't be assigned.");
     124        if(!silent) {
     125        System.err.println("Port " + portnum + " already in use or can't be assigned.");
     126        }
    123127        tmpSocket = null;
    124128        return false;       
Note: See TracChangeset for help on using the changeset viewer.