in client/src/main/java/org/apache/qpid/client/AMQConnection.java [561:692]
private void makeConnection() throws QpidException
{
_connectionAttempted = true;
if(_clientName == null)
{
try
{
InetAddress addr = InetAddress.getLocalHost();
_clientName = addr.getHostName() + System.currentTimeMillis();
}
catch (UnknownHostException e)
{
_clientName = "UnknownHost" + UUID.randomUUID();
}
}
BrokerDetails brokerDetails = _failoverPolicy.getCurrentBrokerDetails();
BrokerDetails lastBrokerDetails = null;
boolean retryAllowed = true;
Exception connectionException = null;
while (!isConnected() && retryAllowed && brokerDetails != null)
{
lastBrokerDetails = brokerDetails;
ProtocolVersion pe = null;
try
{
pe = makeBrokerConnection(brokerDetails);
}
catch (Exception e)
{
if (_logger.isInfoEnabled())
{
_logger.info("Unable to connect to broker at " +
_failoverPolicy.getCurrentBrokerDetails(),
e);
}
connectionException = e;
}
if (pe != null)
{
// reset the delegate to the version returned by the
// broker
initDelegate(pe);
}
else if (!isConnected())
{
if(connectionException instanceof ConnectionRedirectException)
{
ConnectionRedirectException redirect = (ConnectionRedirectException) connectionException;
retryAllowed = true;
brokerDetails = new BrokerDetails(brokerDetails);
brokerDetails.setHost(redirect.getHost());
brokerDetails.setPort(redirect.getPort());
_protocolHandler.setStateManager(new AMQStateManager(_protocolHandler.getProtocolSession()));
}
else
{
if (repeatLastConnectAttempt(connectionException, brokerDetails))
{
brokerDetails = _failoverPolicy.getCurrentBrokerDetails();
}
else
{
retryAllowed = _failoverPolicy.failoverAllowed();
brokerDetails = _failoverPolicy.getNextBrokerDetails();
}
_protocolHandler.setStateManager(new AMQStateManager(_protocolHandler.getProtocolSession()));
}
}
}
verifyClientID();
if (_logger.isDebugEnabled())
{
_logger.debug("Are we connected:" + isConnected());
}
if (!isConnected())
{
if (_logger.isDebugEnabled())
{
_logger.debug("Last attempted ProtocolHandler Version:"+_protocolHandler.getProtocolVersion());
}
String message = null;
if (connectionException != null)
{
if (connectionException.getCause() != null)
{
message = connectionException.getCause().getMessage();
}
else
{
message = connectionException.getMessage();
}
}
if (message == null)
{
message = "Unable to Connect";
}
else if("".equals(message))
{
message = "Unable to Connect:" + connectionException.getClass();
}
for (Throwable th = connectionException; th != null; th = th.getCause())
{
if (th instanceof UnresolvedAddressException ||
th instanceof UnknownHostException)
{
throw new AMQUnresolvedAddressException
(message,
_failoverPolicy.getCurrentBrokerDetails().toString(),
connectionException);
}
}
throw new AMQConnectionFailureException(message, connectionException);
}
if (_logger.isDebugEnabled())
{
_logger.debug("Connected with ProtocolHandler Version:"+_protocolHandler.getProtocolVersion());
}
notifySuccessfulConnectAttempt(lastBrokerDetails);
_sessions.setMaxChannelID(_delegate.getMaxChannelID());
_sessions.setMinChannelID(_delegate.getMinChannelID());
}