boolean retry = false;
do
{
Version clientVersion = VersionLoader.getVersion();
CoreRemotingConnection theConnection = null;
Lock lock = null;
try
{
Channel channel1;
synchronized (failoverLock)
{
theConnection = getConnectionWithRetry(reconnectAttempts);
if (theConnection == null)
{
if (exitLoop)
{
return null;
}
if (failoverOnInitialConnection && backupConnectorFactory != null)
{
// Try and connect to the backup
log.warn("Server is not available to make initial connection to. Will " + "try backup server instead.");
connectorFactory = backupConnectorFactory;
transportParams = backupTransportParams;
backupConnectorFactory = null;
backupTransportParams = null;
theConnection = getConnectionWithRetry(reconnectAttempts);
}
if (exitLoop)
{
return null;
}
if (theConnection == null)
{
throw new HornetQException(HornetQException.NOT_CONNECTED,
"Unable to connect to server using configuration " + connectorConfig);
}
}
channel1 = theConnection.getChannel(1, -1);
// Lock it - this must be done while the failoverLock is held
channel1.getLock().lock();
lock = channel1.getLock();
} // We can now release the failoverLock
// We now set a flag saying createSession is executing
synchronized (exitLock)
{
inCreateSession = true;
}
long sessionChannelID = theConnection.generateChannelID();
Packet request = new CreateSessionMessage(name,
sessionChannelID,
clientVersion.getIncrementingVersion(),
username,
password,
minLargeMessageSize,
xa,
autoCommitSends,
autoCommitAcks,
preAcknowledge,
confWindowSize,
null);
Packet pResponse;
try
{
pResponse = channel1.sendBlocking(request);
}
catch (HornetQException e)
{
if (e.getCode() == HornetQException.INCOMPATIBLE_CLIENT_SERVER_VERSIONS)
{
theConnection.destroy();
}
if (e.getCode() == HornetQException.UNBLOCKED)
{
// This means the thread was blocked on create session and failover unblocked it
// so failover could occur
retry = true;
continue;
}
else
{
throw e;
}
}
CreateSessionResponseMessage response = (CreateSessionResponseMessage)pResponse;
Channel sessionChannel = theConnection.getChannel(sessionChannelID, confWindowSize);
ClientSessionInternal session = new ClientSessionImpl(this,
name,
username,
password,