Source:
public ClientSessionFactory createSessionFactory() throws ActiveMQException { assertOpen(); initialize(); flushTopology(); if (this.getNumInitialConnectors() == 0 && discoveryGroup != null) { long timeout = clusterConnection ? 0 : discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout(); boolean ok = discoveryGroup.waitForBroadcast(timeout); if (!ok) { throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutInInitialBroadcast(); } } ClientSessionFactoryInternal factory = null; synchronized (this) { boolean retry; int attempts = 0; do { retry = false; TransportConfiguration tc = selectConnector(); if (tc == null) { throw ActiveMQClientMessageBundle.BUNDLE.noTCForSessionFactory(); } try { factory = new ClientSessionFactoryImpl(this, tc, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); try { addToConnecting(factory); factory.connect(1, false); } finally { removeFromConnecting(factory); } } catch (ActiveMQException e) { if (factory.waitForRetry(retryInterval)) { throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); } factory.close(); if (e.getType() == ActiveMQExceptionType.NOT_CONNECTED) { attempts++; int connectorsSize = getConnectorsSize(); int maxAttempts = initialConnectAttempts == 0 ? 1 : initialConnectAttempts; if (initialConnectAttempts >= 0 && attempts >= maxAttempts * connectorsSize) { throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); } retry = true; } else { throw e; } } } while (retry); } if (topology != null && !factory.waitForTopology(callTimeout, TimeUnit.MILLISECONDS)) { factory.cleanup(); throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutOnReceiveTopology(discoveryGroup); } addFactory(factory); return factory; }

Target:
public ClientSessionFactory createSessionFactory() throws ActiveMQException { assertOpen(); initialize(); flushTopology(); if (this.getNumInitialConnectors() == 0 && discoveryGroup != null) { long timeout = clusterConnection ? 0 : discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout(); boolean ok = discoveryGroup.waitForBroadcast(timeout); if (!ok) { throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutInInitialBroadcast(); } } ClientSessionFactoryInternal factory = null; synchronized (this) { boolean retry = true; int attempts = 0; while (retry && !isClosed()) { retry = false; TransportConfiguration tc = selectConnector(); if (tc == null) { throw ActiveMQClientMessageBundle.BUNDLE.noTCForSessionFactory(); } try { factory = new ClientSessionFactoryImpl(this, tc, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); try { addToConnecting(factory); factory.connect(1, false); } finally { removeFromConnecting(factory); } } catch (ActiveMQException e) { try { if (e.getType() == ActiveMQExceptionType.NOT_CONNECTED) { attempts++; int connectorsSize = getConnectorsSize(); int maxAttempts = initialConnectAttempts == 0 ? 1 : initialConnectAttempts; if (initialConnectAttempts >= 0 && attempts >= maxAttempts * connectorsSize) { throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); } if (factory.waitForRetry(retryInterval)) { throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); } retry = true; } else { throw e; } } finally { factory.close(); } } } } if (topology != null && !factory.waitForTopology(callTimeout, TimeUnit.MILLISECONDS)) { factory.cleanup(); throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutOnReceiveTopology(discoveryGroup); } addFactory(factory); return factory; }