/** * Create a ServerLocator which creates session factories using a static list of transportConfigurations, the ServerLocator is not updated automatically * as the cluster topology changes, and no HA backup information is propagated to the client * * @param transportConfigurations * @return the ServerLocator */ public static ServerLocator createServerLocatorWithoutHA(TransportConfiguration... transportConfigurations) { return new ServerLocatorImpl(false, transportConfigurations); }
private ClientSessionFactoryInternal connect(final boolean skipWarnings) throws ActiveMQException { ClientSessionFactoryInternal returnFactory = null; synchronized (this) { // static list of initial connectors if (getNumInitialConnectors() > 0 && discoveryGroup == null) { returnFactory = (ClientSessionFactoryInternal) staticConnector.connect(skipWarnings); } } if (returnFactory != null) { addFactory(returnFactory); return returnFactory; } else { // wait for discovery group to get the list of initial connectors return (ClientSessionFactoryInternal) createSessionFactory(); } }
@Override public ClientSessionFactory createSessionFactory(final TransportConfiguration transportConfiguration) throws Exception { assertOpen(); initialize(); ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this, transportConfiguration, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); addToConnecting(factory); try { try { factory.connect(reconnectAttempts, failoverOnInitialConnection); } catch (ActiveMQException e1) { //we need to make sure is closed just for garbage collection factory.close(); throw e1; } addFactory(factory); return factory; } finally { removeFromConnecting(factory); } }
@Override public ClientSessionFactory createSessionFactory() throws ActiveMQException { assertOpen(); initialize(); flushTopology(); if (this.getNumInitialConnectors() == 0 && discoveryGroup != null) { retry = false; TransportConfiguration tc = selectConnector(); if (tc == null) { throw ActiveMQClientMessageBundle.BUNDLE.noTCForSessionFactory(); factory = new ClientSessionFactoryImpl(this, tc, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); try { addToConnecting(factory); factory.connect(initialConnectAttempts, failoverOnInitialConnection); } finally { removeFromConnecting(factory); throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); if (topologyArray == null && attempts == this.getNumInitialConnectors()) { throw ActiveMQClientMessageBundle.BUNDLE.cannotConnectToServers(); addFactory(factory);
@Override public synchronized void initialize() throws ActiveMQException { if (state == STATE.INITIALIZED) return; synchronized (stateGuard) { if (state == STATE.CLOSING) throw new ActiveMQIllegalStateException(); try { state = STATE.INITIALIZED; latch = new CountDownLatch(1); setThreadPools(); topology.setExecutor(new OrderedExecutor(threadPool)); instantiateLoadBalancingPolicy(); if (discoveryGroupConfiguration != null) { discoveryGroup = createDiscoveryGroup(nodeID, discoveryGroupConfiguration); discoveryGroup.registerListener(this); discoveryGroup.start(); } } catch (Exception e) { state = null; throw ActiveMQClientMessageBundle.BUNDLE.failedToInitialiseSessionFactory(e); } } }
@Override public ServerLocatorImpl setConfirmationWindowSize(final int confirmationWindowSize) { checkWrite(); this.confirmationWindowSize = confirmationWindowSize; return this; }
@Override public void close() { doClose(true); }
@Override protected void finalize() throws Throwable { if (finalizeCheck) { close(); } super.finalize(); }
private void addToConnecting(ClientSessionFactoryInternal factory) { synchronized (connectingFactories) { assertOpen(); connectingFactories.add(factory); } }
@Override public ClientSessionFactoryInternal connect() throws ActiveMQException { return connect(false); }
@Test public void controlWithDifferentConnector() throws Exception { try (ServerLocatorImpl locator = (ServerLocatorImpl) createInVMNonHALocator()) { locator.setProtocolManagerFactory(ActiveMQServerSideProtocolManagerFactory.getInstance(locator)); ClusterController controller = new ClusterController(getServer(0), getServer(0).getScheduledPool()); ClusterControl clusterControl = controller.connectToNodeInCluster((ClientSessionFactoryInternal) locator.createSessionFactory()); clusterControl.authorize(); } }
@Override public ClientSessionFactory createSessionFactory(String nodeID) throws Exception { TopologyMember topologyMember = topology.getMember(nodeID); if (logger.isTraceEnabled()) { logger.trace("Creating connection factory towards " + nodeID + " = " + topologyMember + ", topology=" + topology.describe()); } if (topologyMember == null) { return null; } if (topologyMember.getLive() != null) { ClientSessionFactoryInternal factory = (ClientSessionFactoryInternal) createSessionFactory(topologyMember.getLive()); if (topologyMember.getBackup() != null) { factory.setBackupConnector(topologyMember.getLive(), topologyMember.getBackup()); } return factory; } if (topologyMember.getLive() == null && topologyMember.getBackup() != null) { // This shouldn't happen, however I wanted this to consider all possible cases ClientSessionFactoryInternal factory = (ClientSessionFactoryInternal) createSessionFactory(topologyMember.getBackup()); return factory; } // it shouldn't happen return null; }
@Override public ServerLocatorInternal createServerLocator() { if (tcConfigs != null && tcConfigs.length > 0) { if (logger.isDebugEnabled()) { logger.debug(ClusterConnectionImpl.this + "Creating a serverLocator for " + Arrays.toString(tcConfigs)); } ServerLocatorImpl locator = new ServerLocatorImpl(topology, true, tcConfigs); locator.setClusterConnection(true); return locator; } return null; }
@Override public ClientSessionFactory createSessionFactory(final TransportConfiguration transportConfiguration, int reconnectAttempts, boolean failoverOnInitialConnection) throws Exception { assertOpen(); initialize(); ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this, transportConfiguration, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); addToConnecting(factory); try { try { factory.connect(reconnectAttempts, failoverOnInitialConnection); } catch (ActiveMQException e1) { //we need to make sure is closed just for garbage collection factory.close(); throw e1; } addFactory(factory); return factory; } finally { removeFromConnecting(factory); } }
@Override public synchronized void initialize() throws ActiveMQException { if (state == STATE.INITIALIZED) return; synchronized (stateGuard) { if (state == STATE.CLOSING) throw new ActiveMQIllegalStateException(); try { state = STATE.INITIALIZED; latch = new CountDownLatch(1); setThreadPools(); topology.setExecutor(new OrderedExecutor(threadPool)); instantiateLoadBalancingPolicy(); if (discoveryGroupConfiguration != null) { discoveryGroup = createDiscoveryGroup(nodeID, discoveryGroupConfiguration); discoveryGroup.registerListener(this); discoveryGroup.start(); } } catch (Exception e) { state = null; throw ActiveMQClientMessageBundle.BUNDLE.failedToInitialiseSessionFactory(e); } } }
@Override public ServerLocatorImpl setProducerMaxRate(final int producerMaxRate) { checkWrite(); this.producerMaxRate = producerMaxRate; return this; }
@Override public void cleanup() { doClose(false); }