public ClusterManager( final ExecutorFactory executorFactory, final HornetQServer server, final PostOffice postOffice, final ScheduledExecutorService scheduledExecutor, final ManagementService managementService, final Configuration configuration, final NodeManager nodeManager, final boolean backup, ExecutorService threadPool) { this.executorFactory = executorFactory; executor = executorFactory.getExecutor(); ; this.server = server; this.postOffice = postOffice; this.scheduledExecutor = scheduledExecutor; this.managementService = managementService; this.configuration = configuration; this.nodeManager = nodeManager; this.backup = backup; this.threadPool = threadPool; }
public ClusterManagerImpl( final ExecutorFactory executorFactory, final HornetQServer server, final PostOffice postOffice, final ScheduledExecutorService scheduledExecutor, final ManagementService managementService, final Configuration configuration, final UUID nodeUUID, final boolean backup, final boolean clustered) { if (nodeUUID == null) { throw new IllegalArgumentException("Node uuid is null"); } this.executorFactory = executorFactory; executor = executorFactory.getExecutor(); ; this.server = server; this.postOffice = postOffice; this.scheduledExecutor = scheduledExecutor; this.managementService = managementService; this.configuration = configuration; this.nodeUUID = nodeUUID; this.backup = backup; this.clustered = clustered; }
public static OperationContext getContext(final ExecutorFactory executorFactory) { OperationContext token = OperationContextImpl.threadLocalContext.get(); if (token == null) { if (executorFactory == null) { return null; } else { token = new OperationContextImpl(executorFactory.getExecutor()); OperationContextImpl.threadLocalContext.set(token); } } return token; }
public synchronized void deployBridge(final BridgeConfiguration config, final boolean start) throws Exception { if (config.getName() == null) { ClusterManagerImpl.log.warn( "Must specify a unique name for each bridge. This one will not be deployed."); return; } if (config.getQueueName() == null) { ClusterManagerImpl.log.warn( "Must specify a queue name for each bridge. This one will not be deployed."); return; } if (config.getForwardingAddress() == null) { ClusterManagerImpl.log.debug( "Forward address is not specified. Will use original message address instead"); } if (bridges.containsKey(config.getName())) { ClusterManagerImpl.log.warn( "There is already a bridge with name " + config.getName() + " deployed. This one will not be deployed."); return; } Transformer transformer = instantiateTransformer(config.getTransformerClassName()); Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName())); if (binding == null) { ClusterManagerImpl.log.warn( "No queue found with name " + config.getQueueName() + " bridge will not be deployed."); return; } Queue queue = (Queue) binding.getBindable(); ServerLocatorInternal serverLocator; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (discoveryGroupConfiguration == null) { ClusterManagerImpl.log.warn( "No discovery group configured with name '" + config.getDiscoveryGroupName() + "'. The bridge will not be deployed."); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration); } } else { TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors()); if (tcConfigs == null) { return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs); } } serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize()); // We are going to manually retry on the bridge in case of failure serverLocator.setReconnectAttempts(0); serverLocator.setInitialConnectAttempts(-1); serverLocator.setRetryInterval(config.getRetryInterval()); serverLocator.setMaxRetryInterval(config.getMaxRetryInterval()); serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier()); serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod()); serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection()); serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection()); serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize()); // disable flow control serverLocator.setProducerWindowSize(-1); // This will be set to 30s unless it's changed from embedded / testing // there is no reason to exception the config for this timeout // since the Bridge is supposed to be non-blocking and fast // We may expose this if we find a good use case serverLocator.setCallTimeout(config.getCallTimeout()); if (!config.isUseDuplicateDetection()) { log.debug( "Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously"); } clusterLocators.add(serverLocator); Bridge bridge = new BridgeImpl( serverLocator, config.getReconnectAttempts(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeUUID, new SimpleString(config.getName()), queue, executorFactory.getExecutor(), SimpleString.toSimpleString(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), !backup, server.getStorageManager()); bridges.put(config.getName(), bridge); managementService.registerBridge(bridge, config); if (start) { bridge.start(); } }
public synchronized void deployBridge(final BridgeConfiguration config) throws Exception { if (config.getName() == null) { HornetQServerLogger.LOGGER.bridgeNotUnique(); return; } if (config.getQueueName() == null) { HornetQServerLogger.LOGGER.bridgeNoQueue(config.getName()); return; } if (config.getForwardingAddress() == null) { HornetQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName()); } if (bridges.containsKey(config.getName())) { HornetQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName()); return; } Transformer transformer = instantiateTransformer(config.getTransformerClassName()); Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName())); if (binding == null) { HornetQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName()); return; } Queue queue = (Queue) binding.getBindable(); ServerLocatorInternal serverLocator; if (config.getDiscoveryGroupName() != null) { DiscoveryGroupConfiguration discoveryGroupConfiguration = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName()); if (discoveryGroupConfiguration == null) { HornetQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName()); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration); } } else { TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors()); if (tcConfigs == null) { HornetQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName()); return; } if (config.isHA()) { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs); } else { serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs); } } if (config.getForwardingAddress() != null) { AddressSettings addressConfig = configuration.getAddressesSettings().get(config.getForwardingAddress()); // The address config could be null on certain test cases or some Embedded environment if (addressConfig == null) { // We will certainly have this warning on testcases which is ok HornetQServerLogger.LOGGER.bridgeCantFindAddressConfig( config.getName(), config.getForwardingAddress()); } else { final int windowSize = config.getConfirmationWindowSize(); final long maxBytes = addressConfig.getMaxSizeBytes(); if (maxBytes != -1 && maxBytes < windowSize) { HornetQServerLogger.LOGGER.bridgeConfirmationWindowTooSmall( config.getName(), config.getForwardingAddress(), windowSize, maxBytes); } } } serverLocator.setIdentity("Bridge " + config.getName()); serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize()); // We are going to manually retry on the bridge in case of failure serverLocator.setReconnectAttempts(0); serverLocator.setInitialConnectAttempts(0); serverLocator.setRetryInterval(config.getRetryInterval()); serverLocator.setMaxRetryInterval(config.getMaxRetryInterval()); serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier()); serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod()); serverLocator.setConnectionTTL(config.getConnectionTTL()); serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection()); serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection()); serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize()); // disable flow control serverLocator.setProducerWindowSize(-1); // This will be set to 30s unless it's changed from embedded / testing // there is no reason to exception the config for this timeout // since the Bridge is supposed to be non-blocking and fast // We may expose this if we find a good use case serverLocator.setCallTimeout(config.getCallTimeout()); if (!config.isUseDuplicateDetection()) { HornetQServerLogger.LOGGER.debug( "Bridge " + config.getName() + " is configured to not use duplicate detecion, it will send messages synchronously"); } clusterLocators.add(serverLocator); Bridge bridge = new BridgeImpl( serverLocator, config.getReconnectAttempts(), config.getReconnectAttemptsOnSameNode(), config.getRetryInterval(), config.getRetryIntervalMultiplier(), config.getMaxRetryInterval(), nodeManager.getUUID(), new SimpleString(config.getName()), queue, executorFactory.getExecutor(), FilterImpl.createFilter(config.getFilterString()), SimpleString.toSimpleString(config.getForwardingAddress()), scheduledExecutor, transformer, config.isUseDuplicateDetection(), config.getUser(), config.getPassword(), !backup, server.getStorageManager()); bridges.put(config.getName(), bridge); managementService.registerBridge(bridge, config); bridge.start(); }
private void createNewRecord( final long eventUID, final String targetNodeID, final TransportConfiguration connector, final SimpleString queueName, final Queue queue, final boolean start) throws Exception { String nodeId; synchronized (this) { if (!started) { return; } if (serverLocator == null) { return; } nodeId = serverLocator.getNodeID(); } final ServerLocatorInternal targetLocator = new ServerLocatorImpl(topology, true, connector); targetLocator.setReconnectAttempts(0); targetLocator.setInitialConnectAttempts(0); targetLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod); targetLocator.setConnectionTTL(connectionTTL); targetLocator.setInitialConnectAttempts(0); targetLocator.setConfirmationWindowSize(confirmationWindowSize); targetLocator.setBlockOnDurableSend(!useDuplicateDetection); targetLocator.setBlockOnNonDurableSend(!useDuplicateDetection); targetLocator.setRetryInterval(retryInterval); targetLocator.setMaxRetryInterval(maxRetryInterval); targetLocator.setRetryIntervalMultiplier(retryIntervalMultiplier); targetLocator.setMinLargeMessageSize(minLargeMessageSize); // No producer flow control on the bridges, as we don't want to lock the queues targetLocator.setProducerWindowSize(-1); targetLocator.setAfterConnectionInternalListener(this); targetLocator.setNodeID(nodeId); targetLocator.setClusterTransportConfiguration( serverLocator.getClusterTransportConfiguration()); if (retryInterval > 0) { targetLocator.setRetryInterval(retryInterval); } targetLocator.disableFinalizeCheck(); targetLocator.addIncomingInterceptor( new IncomingInterceptorLookingForExceptionMessage(manager, executorFactory.getExecutor())); MessageFlowRecordImpl record = new MessageFlowRecordImpl( targetLocator, eventUID, targetNodeID, connector, queueName, queue); ClusterConnectionBridge bridge = new ClusterConnectionBridge( this, manager, targetLocator, serverLocator, reconnectAttempts, retryInterval, retryIntervalMultiplier, maxRetryInterval, nodeManager.getUUID(), record.getEventUID(), record.getTargetNodeID(), record.getQueueName(), record.getQueue(), executorFactory.getExecutor(), null, null, scheduledExecutor, null, useDuplicateDetection, clusterUser, clusterPassword, server.getStorageManager(), managementService.getManagementAddress(), managementService.getManagementNotificationAddress(), record, record.getConnector()); targetLocator.setIdentity( "(Cluster-connection-bridge::" + bridge.toString() + "::" + this.toString() + ")"); if (HornetQServerLogger.LOGGER.isDebugEnabled()) { HornetQServerLogger.LOGGER.debug( "creating record between " + this.connector + " and " + connector + bridge); } record.setBridge(bridge); records.put(targetNodeID, record); if (start) { bridge.start(); } }
/** * @param dg discovery group, notice if {@code null} this is a cluster which won't connect to * anyone, but that can still accept incoming connections. * @param clusterNotificationInterval */ public ClusterConnectionImpl( final ClusterManager manager, DiscoveryGroupConfiguration dg, final TransportConfiguration connector, final SimpleString name, final SimpleString address, final int minLargeMessageSize, final long clientFailureCheckPeriod, final long connectionTTL, final long retryInterval, final double retryIntervalMultiplier, final long maxRetryInterval, final int reconnectAttempts, final long callTimeout, final long callFailoverTimeout, final boolean useDuplicateDetection, final boolean routeWhenNoConsumers, final int confirmationWindowSize, final ExecutorFactory executorFactory, final HornetQServer server, final PostOffice postOffice, final ManagementService managementService, final ScheduledExecutorService scheduledExecutor, final int maxHops, final NodeManager nodeManager, final String clusterUser, final String clusterPassword, final boolean allowDirectConnectionsOnly, final long clusterNotificationInterval, final int clusterNotificationAttempts) throws Exception { this.nodeManager = nodeManager; this.connector = connector; this.name = name; this.address = address; this.clientFailureCheckPeriod = clientFailureCheckPeriod; this.connectionTTL = connectionTTL; this.retryInterval = retryInterval; this.retryIntervalMultiplier = retryIntervalMultiplier; this.maxRetryInterval = maxRetryInterval; this.minLargeMessageSize = minLargeMessageSize; this.reconnectAttempts = reconnectAttempts; this.callTimeout = callTimeout; this.callFailoverTimeout = callFailoverTimeout; this.useDuplicateDetection = useDuplicateDetection; this.routeWhenNoConsumers = routeWhenNoConsumers; this.confirmationWindowSize = confirmationWindowSize; this.executorFactory = executorFactory; this.clusterNotificationInterval = clusterNotificationInterval; this.clusterNotificationAttempts = clusterNotificationAttempts; this.executor = executorFactory.getExecutor(); this.topology.setExecutor(executor); this.server = server; this.postOffice = postOffice; this.managementService = managementService; this.scheduledExecutor = scheduledExecutor; this.maxHops = maxHops; this.clusterUser = clusterUser; this.clusterPassword = clusterPassword; this.allowDirectConnectionsOnly = allowDirectConnectionsOnly; clusterConnector = new DiscoveryClusterConnector(dg); this.manager = manager; }
/** * @param staticTranspConfigs notice if {@code null} this is a cluster which won't connect to * anyone, but that can still accept incoming connections. * @param clusterNotificationInterval */ public ClusterConnectionImpl( final ClusterManager manager, final TransportConfiguration[] staticTranspConfigs, final TransportConfiguration connector, final SimpleString name, final SimpleString address, final int minLargeMessageSize, final long clientFailureCheckPeriod, final long connectionTTL, final long retryInterval, final double retryIntervalMultiplier, final long maxRetryInterval, final int reconnectAttempts, final long callTimeout, final long callFailoverTimeout, final boolean useDuplicateDetection, final boolean routeWhenNoConsumers, final int confirmationWindowSize, final ExecutorFactory executorFactory, final HornetQServer server, final PostOffice postOffice, final ManagementService managementService, final ScheduledExecutorService scheduledExecutor, final int maxHops, final NodeManager nodeManager, final String clusterUser, final String clusterPassword, final boolean allowDirectConnectionsOnly, final long clusterNotificationInterval, final int clusterNotificationAttempts) throws Exception { this.nodeManager = nodeManager; this.connector = connector; this.name = name; this.address = address; this.clientFailureCheckPeriod = clientFailureCheckPeriod; this.connectionTTL = connectionTTL; this.retryInterval = retryInterval; this.retryIntervalMultiplier = retryIntervalMultiplier; this.maxRetryInterval = maxRetryInterval; this.reconnectAttempts = reconnectAttempts; this.useDuplicateDetection = useDuplicateDetection; this.routeWhenNoConsumers = routeWhenNoConsumers; this.confirmationWindowSize = confirmationWindowSize; this.executorFactory = executorFactory; this.clusterNotificationInterval = clusterNotificationInterval; this.clusterNotificationAttempts = clusterNotificationAttempts; this.executor = executorFactory.getExecutor(); this.topology.setExecutor(executor); this.server = server; this.postOffice = postOffice; this.managementService = managementService; this.scheduledExecutor = scheduledExecutor; this.maxHops = maxHops; this.clusterUser = clusterUser; this.clusterPassword = clusterPassword; this.allowDirectConnectionsOnly = allowDirectConnectionsOnly; this.manager = manager; this.callTimeout = callTimeout; this.callFailoverTimeout = callFailoverTimeout; this.minLargeMessageSize = minLargeMessageSize; clusterConnector = new StaticClusterConnector(staticTranspConfigs); if (staticTranspConfigs != null && staticTranspConfigs.length > 0) { // a cluster connection will connect to other nodes only if they are directly connected // through a static list of connectors or broadcasting using UDP. if (allowDirectConnectionsOnly) { allowableConnections.addAll(Arrays.asList(staticTranspConfigs)); } } }