|
Lines 11-16
Link Here
|
| 11 |
package org.eclipse.ecf.provider.generic; |
11 |
package org.eclipse.ecf.provider.generic; |
| 12 |
|
12 |
|
| 13 |
import java.io.IOException; |
13 |
import java.io.IOException; |
|
|
14 |
import java.net.BindException; |
| 14 |
import java.net.ServerSocket; |
15 |
import java.net.ServerSocket; |
| 15 |
import java.util.*; |
16 |
import java.util.*; |
| 16 |
import org.eclipse.core.runtime.*; |
17 |
import org.eclipse.core.runtime.*; |
|
Lines 152-158
public class GenericContainerInstantiator implements IContainerInstantiator, IRe
Link Here
|
| 152 |
newID = getIDFromArg(args[0]); |
153 |
newID = getIDFromArg(args[0]); |
| 153 |
} |
154 |
} |
| 154 |
if (newID == null) { |
155 |
if (newID == null) { |
| 155 |
int defaultPort = getFreePort(); |
156 |
int defaultPort = TCPServerSOContainer.DEFAULT_PORT; |
|
|
157 |
boolean useFallbackPort = TCPServerSOContainer.DEFAULT_FALLBACK_PORT; |
| 158 |
if (useFallbackPort && !defaultPortIsFree(defaultPort)) { |
| 159 |
defaultPort = getFreePort(); |
| 160 |
} |
| 156 |
newID = IDFactory.getDefault().createStringID(TCPServerSOContainer.DEFAULT_PROTOCOL + "://" + TCPServerSOContainer.DEFAULT_HOST + ":" + defaultPort + TCPServerSOContainer.DEFAULT_NAME);//$NON-NLS-1$ //$NON-NLS-2$ |
161 |
newID = IDFactory.getDefault().createStringID(TCPServerSOContainer.DEFAULT_PROTOCOL + "://" + TCPServerSOContainer.DEFAULT_HOST + ":" + defaultPort + TCPServerSOContainer.DEFAULT_NAME);//$NON-NLS-1$ //$NON-NLS-2$ |
| 157 |
} |
162 |
} |
| 158 |
if (ka == null) |
163 |
if (ka == null) |
|
Lines 160-165
public class GenericContainerInstantiator implements IContainerInstantiator, IRe
Link Here
|
| 160 |
return new GenericContainerArgs(newID, ka); |
165 |
return new GenericContainerArgs(newID, ka); |
| 161 |
} |
166 |
} |
| 162 |
|
167 |
|
|
|
168 |
private boolean defaultPortIsFree(int defaultPort) { |
| 169 |
ServerSocket ss = null; |
| 170 |
try { |
| 171 |
ss = new ServerSocket(defaultPort); |
| 172 |
ss.close(); |
| 173 |
} catch (BindException e) { |
| 174 |
return false; |
| 175 |
} catch (IOException e) { |
| 176 |
return false; |
| 177 |
} finally { |
| 178 |
if (ss != null) |
| 179 |
try { |
| 180 |
ss.close(); |
| 181 |
} catch (IOException e) { |
| 182 |
throw new IDCreateException(e); |
| 183 |
} |
| 184 |
} |
| 185 |
return true; |
| 186 |
} |
| 187 |
|
| 163 |
/** |
188 |
/** |
| 164 |
* @return a free socket port |
189 |
* @return a free socket port |
| 165 |
*/ |
190 |
*/ |