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,
xa,
autoCommitSends,
autoCommitAcks,
preAcknowledge,
blockOnAcknowledge,
autoGroup,
ackBatchSize,
consumerWindowSize,
consumerMaxRate,
confWindowSize,
producerWindowSize,
producerMaxRate,
blockOnNonDurableSend,
blockOnDurableSend,
cacheLargeMessageClient,
minLargeMessageSize,
initialMessagePacketSize,
groupID,
theConnection,
response.getServerVersion(),
sessionChannel,
orderedExecutorFactory.getExecutor());
sessions.add(session);
ChannelHandler handler = new ClientSessionPacketHandler(session, sessionChannel);
sessionChannel.setHandler(handler);
return new DelegatingSession(session);
}
catch (Throwable t)
{
if (lock != null)
{
lock.unlock();
lock = null;
}
if (t instanceof HornetQException)
{
throw (HornetQException)t;
}
else
{
HornetQException me = new HornetQException(HornetQException.INTERNAL_ERROR,
"Failed to create session", t);
throw me;
}
}