- Timestamp:
- 2009-05-13T13:52:42+12:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/server/PortFinder.java
r18992 r19428 28 28 this( PORTS_RESERVED+1, (MAX_PORT - PORTS_RESERVED) ); 29 29 } 30 30 31 31 public PortFinder(int base, int blocksize) { 32 32 PORT_BASE = base; … … 46 46 * @return the number of an available port. 47 47 */ 48 public int findPortInRange( ) throws Exception {48 public int findPortInRange(boolean silent) throws Exception { 49 49 try { 50 50 boolean foundFreePort = false; 51 51 for(int i = 0; i < PORT_BLOCK_SIZE; i++) { 52 52 53 if(isPortAvailable(nextFreePort )) {53 if(isPortAvailable(nextFreePort, silent)) { 54 54 foundFreePort = true; 55 55 break; … … 107 107 108 108 /** @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) { 110 110 ServerSocket tmpSocket = null; 111 111 try { 112 112 tmpSocket = new ServerSocket(portnum); 113 113 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 } 115 117 return true; 116 118 … … 119 121 // socket to a local address and port. Typically, the port is 120 122 // 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 } 122 126 tmpSocket = null; 123 127 return false;
Note:
See TracChangeset
for help on using the changeset viewer.