[Swift-commit] cog r3522
swift at ci.uchicago.edu
swift at ci.uchicago.edu
Mon Nov 26 14:10:13 CST 2012
------------------------------------------------------------------------
r3522 | davidkelly999 | 2012-11-26 14:09:53 -0600 (Mon, 26 Nov 2012) | 2 lines
Avoid using duplicate ports with multiple coaster-service's running, bug #881
------------------------------------------------------------------------
Index: modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/CoasterPersistentService.java
===================================================================
--- modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/CoasterPersistentService.java (revision 3521)
+++ modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/CoasterPersistentService.java (working copy)
@@ -108,7 +108,7 @@
cred = new GlobusGSSCredentialImpl(gc, GSSCredential.INITIATE_AND_ACCEPT);
}
- int port = 1984;
+ int port = 0;
if (ap.hasValue("port")) {
if (ap.hasValue("portfile")) {
throw new ArgumentParserException("-portfile (-S) and -port are mutually exclusive");
Index: modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/LocalTCPService.java
===================================================================
--- modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/LocalTCPService.java (revision 3521)
+++ modules/provider-coaster/src/org/globus/cog/abstraction/coaster/service/LocalTCPService.java (working copy)
@@ -96,22 +96,41 @@
public ServiceContext getContext() {
return context;
}
-
- public void start() {
+
+ public boolean bindPort() {
try {
- channel = ServerSocketChannel.open();
- channel.configureBlocking(true);
- if(port == 0) {
- PortRange portRange = PortRange.getTcpInstance();
- if(portRange != null && portRange.isEnabled()) {
- synchronized(portRange) {
- port = portRange.getFreePort(port);
- portRange.setUsed(port);
- }
- }
+ channel.socket().bind(new InetSocketAddress(port));
+ return true;
+ }
+ catch (Exception e) {
+ return false;
+ }
+ }
+
+ public void start() throws IOException {
+ channel = ServerSocketChannel.open();
+ channel.configureBlocking(true);
+
+ /* When GLOBUS_TCP_PORT_RANGE is defined, find an acceptable port in that range */
+ String globusTCPPortRange = System.getenv("GLOBUS_TCP_PORT_RANGE");
+ String rangeValues[] = {"0", "0"};
+
+ if(globusTCPPortRange != null) {
+ rangeValues = globusTCPPortRange.split(",");
+ }
+
+ port = Integer.valueOf(rangeValues[0]);
+ while(!bindPort()) {
+ port++;
+ if(port > Integer.valueOf(rangeValues[1])) {
+ String msg = "Unable to find an available port";
+ if(globusTCPPortRange != null)
+ msg += " in the range of " + rangeValues[0] + " to " + rangeValues[1];
+ throw new IOException(msg);
}
- channel.socket().bind(new InetSocketAddress(port));
-
+ }
+
+ try {
if (serverThread == null) {
serverThread = new Thread(this);
serverThread.setDaemon(true);
More information about the Swift-commit
mailing list