diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/ConnectionI.java | 106 | ||||
-rw-r--r-- | java/src/IceInternal/DefaultsAndOverrides.java | 14 | ||||
-rw-r--r-- | java/src/IceInternal/PropertyNames.java | 3 |
3 files changed, 63 insertions, 60 deletions
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 88ff87fa40b..c91ff3a44e0 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -223,13 +223,12 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne waitUntilFinished() { // - // We wait indefinitely until connection closing has been - // initiated. We also wait indefinitely until all outstanding - // requests are completed. Otherwise we couldn't guarantee - // that there are no outstanding calls when deactivate() is - // called on the servant locators. + // We wait indefinitely until the connection is finished and all + // outstanding requests are completed. Otherwise we couldn't + // guarantee that there are no outstanding calls when deactivate() + // is called on the servant locators. // - while(_state < StateClosing || _dispatchCount > 0) + while(_state < StateFinished || _dispatchCount > 0) { try { @@ -240,55 +239,6 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne } } - // - // Now we must wait until close() has been called on the - // transceiver. - // - while(_state != StateFinished) - { - try - { - if(_state != StateClosed && _endpoint.timeout() >= 0) - { - long absoluteWaitTime = _stateTime + _endpoint.timeout(); - long waitTime = absoluteWaitTime - IceInternal.Time.currentMonotonicTimeMillis(); - - if(waitTime > 0) - { - // - // We must wait a bit longer until we close this - // connection. - // - wait(waitTime); - if(IceInternal.Time.currentMonotonicTimeMillis() >= absoluteWaitTime) - { - setState(StateClosed, new CloseTimeoutException()); - } - } - else - { - // - // We already waited long enough, so let's close this - // connection! - // - setState(StateClosed, new CloseTimeoutException()); - } - - // - // No return here, we must still wait until - // close() is called on the _transceiver. - // - } - else - { - wait(); - } - } - catch(InterruptedException ex) - { - } - } - assert(_state == StateFinished); // @@ -1145,7 +1095,9 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne synchronized(this) { assert(_state == StateClosed); - unscheduleTimeout(IceInternal.SocketOperation.Read | IceInternal.SocketOperation.Write); + unscheduleTimeout(IceInternal.SocketOperation.Read | + IceInternal.SocketOperation.Write | + IceInternal.SocketOperation.Connect); } // @@ -1221,10 +1173,14 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne { setState(StateClosed, new ConnectTimeoutException()); } - else if(_state <= StateClosing) + else if(_state < StateClosing) { setState(StateClosed, new TimeoutException()); } + else if(_state == StateClosing) + { + setState(StateClosed, new CloseTimeoutException()); + } } public String @@ -1242,7 +1198,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne public synchronized ConnectionInfo getInfo() { - if(_exception != null) + if(_state >= StateClosed) { throw (Ice.LocalException)_exception.fillInStackTrace(); } @@ -1647,7 +1603,15 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne os.writeByte(_compressionSupported ? (byte)1 : (byte)0); os.writeInt(IceInternal.Protocol.headerSize); // Message size. - sendMessage(new OutgoingMessage(os, false, false)); + if(sendMessage(new OutgoingMessage(os, false, false))) + { + // + // Schedule the close timeout to wait for the peer to close the connection. If + // the message was queued for sending, sendNextMessage will schedule the timeout + // once all messages were sent. + // + scheduleTimeout(IceInternal.SocketOperation.Write, closeTimeout()); + } // // The CloseConnection message should be sufficient. Closing the write @@ -1850,6 +1814,16 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne assert(_writeStream.isEmpty()); _threadPool.unregister(this, IceInternal.SocketOperation.Write); + + // + // If all the messages were sent and we are in the closing state, we schedule + // the close timeout to wait for the peer to close the connection. + // + if(_state == StateClosing) + { + scheduleTimeout(IceInternal.SocketOperation.Write, closeTimeout()); + } + return callbacks; } @@ -2268,6 +2242,20 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne } } + private int + closeTimeout() + { + IceInternal.DefaultsAndOverrides defaultsAndOverrides = _instance.defaultsAndOverrides(); + if(defaultsAndOverrides.overrideCloseTimeout) + { + return defaultsAndOverrides.overrideCloseTimeoutValue; + } + else + { + return _endpoint.timeout(); + } + } + private void warning(String msg, Exception ex) { diff --git a/java/src/IceInternal/DefaultsAndOverrides.java b/java/src/IceInternal/DefaultsAndOverrides.java index 026279274d1..c0ca6124917 100644 --- a/java/src/IceInternal/DefaultsAndOverrides.java +++ b/java/src/IceInternal/DefaultsAndOverrides.java @@ -51,6 +51,18 @@ public final class DefaultsAndOverrides overrideConnectTimeoutValue = -1; } + value = properties.getProperty("Ice.Override.CloseTimeout"); + if(value.length() > 0) + { + overrideCloseTimeout = true; + overrideCloseTimeoutValue = properties.getPropertyAsInt("Ice.Override.CloseTimeout"); + } + else + { + overrideCloseTimeout = false; + overrideCloseTimeoutValue = -1; + } + value = properties.getProperty("Ice.Override.Compress"); if(value.length() > 0) { @@ -116,6 +128,8 @@ public final class DefaultsAndOverrides final public int overrideTimeoutValue; final public boolean overrideConnectTimeout; final public int overrideConnectTimeoutValue; + final public boolean overrideCloseTimeout; + final public int overrideCloseTimeoutValue; final public boolean overrideCompress; final public boolean overrideCompressValue; final public boolean overrideSecure; diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java index 6a9ee4ce94d..be7a8d07239 100644 --- a/java/src/IceInternal/PropertyNames.java +++ b/java/src/IceInternal/PropertyNames.java @@ -8,7 +8,7 @@ // ********************************************************************** // -// Generated by makeprops.py from file ../config/PropertyNames.xml, Wed Oct 7 14:30:37 2009 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Mon Oct 12 16:01:09 2009 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -82,6 +82,7 @@ public final class PropertyNames new Property("Ice\\.MonitorConnections", false, null), new Property("Ice\\.Nohup", false, null), new Property("Ice\\.NullHandleAbort", false, null), + new Property("Ice\\.Override\\.CloseTimeout", false, null), new Property("Ice\\.Override\\.Compress", false, null), new Property("Ice\\.Override\\.ConnectTimeout", false, null), new Property("Ice\\.Override\\.Timeout", false, null), |