summaryrefslogtreecommitdiff
path: root/java/src/Ice/ConnectionI.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/Ice/ConnectionI.java')
-rw-r--r--java/src/Ice/ConnectionI.java106
1 files changed, 47 insertions, 59 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)
{