in client/src/main/java/org/apache/qpid/client/AMQProtocolHandler.java [170:254]
public void closed()
{
if (_connection.isClosed())
{
_logger.debug("Session closed called by client");
}
else
{
// Use local variable to keep flag whether fail-over allowed or not,
// in order to execute AMQConnection#exceptionRecievedout out of synchronization block,
// otherwise it might deadlock with failover mutex
boolean failoverNotAllowed = false;
boolean failedWithoutConnecting = false;
Throwable initialConnectionException = null;
synchronized (this)
{
if (_logger.isDebugEnabled())
{
_logger.debug("Session closed called with failover state " + _failoverState);
}
// reconnetablility was introduced here so as not to disturb the client as they have made their intentions
// known through the policy settings.
if (_failoverState == FailoverState.NOT_STARTED)
{
// close the sender
try
{
_sender.close();
}
catch (Exception e)
{
_logger.warn("Exception occurred on closing the sender", e);
}
if (_connection.failoverAllowed())
{
_failoverState = FailoverState.IN_PROGRESS;
_logger.debug("FAILOVER STARTING");
startFailoverThread();
}
else if (_connection.isConnected())
{
failoverNotAllowed = true;
if (_logger.isDebugEnabled())
{
_logger.debug("Failover not allowed by policy:" + _connection.getFailoverPolicy());
}
}
else
{
failedWithoutConnecting = true;
initialConnectionException = _initialConnectionException;
_logger.debug("We are in process of establishing the initial connection");
}
_initialConnectionException = null;
}
else
{
_logger.debug("Not starting the failover thread as state currently " + _failoverState);
}
}
if (failoverNotAllowed)
{
_connection.closed(new AMQDisconnectedException(
"Server closed connection and reconnection not permitted.", _stateManager.getLastException()));
}
else if(failedWithoutConnecting)
{
if(initialConnectionException == null)
{
initialConnectionException = _stateManager.getLastException();
}
String message = initialConnectionException == null ? "" : initialConnectionException.getMessage();
_connection.exceptionReceived(new QpidException(
"Connection could not be established: " + message, initialConnectionException));
}
}
if (_logger.isDebugEnabled())
{
_logger.debug("Protocol Session [" + this + "] closed");
}
}