@Override protected AbstractDispatcher createDispatcher() { UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher(); unicastingDispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy()); return unicastingDispatcher; }
/** * Specify the maximum number of subscribers supported by the * channel's dispatcher. * * @param maxSubscribers The maximum number of subscribers allowed. */ public void setMaxSubscribers(int maxSubscribers) { this.maxSubscribers = maxSubscribers; this.dispatcher.setMaxSubscribers(maxSubscribers); }
/** * Create a DirectChannel with a {@link LoadBalancingStrategy}. The * strategy <em>must not</em> be null. * * @param loadBalancingStrategy The load balancing strategy implementation. */ public DirectChannel(LoadBalancingStrategy loadBalancingStrategy) { this.dispatcher.setLoadBalancingStrategy(loadBalancingStrategy); }
private void configureDispatcher(boolean isPubSub) { if (isPubSub) { BroadcastingDispatcher broadcastingDispatcher = new BroadcastingDispatcher(true); broadcastingDispatcher.setBeanFactory(this.getBeanFactory()); this.dispatcher = broadcastingDispatcher; } else { UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher(); unicastingDispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy()); this.dispatcher = unicastingDispatcher; } if (this.maxSubscribers == null) { this.maxSubscribers = this.getIntegrationProperty(isPubSub ? IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS : IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class); } this.dispatcher.setMaxSubscribers(this.maxSubscribers); }
@Before public void setupDispatcher() { this.dispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy()); }
/** * Create an ExecutorChannel that delegates to the provided * {@link Executor} when dispatching Messages. * <p> * The Executor must not be null. * @param executor The executor. */ public ExecutorChannel(Executor executor) { this(executor, new RoundRobinLoadBalancingStrategy()); }
/** * Specify the maximum number of subscribers supported by the * channel's dispatcher (if it is an {@link AbstractDispatcher}). * @param maxSubscribers The maximum number of subscribers allowed. */ public void setMaxSubscribers(int maxSubscribers) { this.maxSubscribers = maxSubscribers; if (this.dispatcher != null) { this.dispatcher.setMaxSubscribers(this.maxSubscribers); } }
/** * Returns the iterator that will be used to loop over the handlers. * Delegates to a {@link LoadBalancingStrategy} if available. Otherwise, * it simply returns the Iterator for the existing handler List. */ private Iterator<MessageHandler> getHandlerIterator(Message<?> message) { if (this.loadBalancingStrategy != null) { return this.loadBalancingStrategy.getHandlerIterator(message, this.getHandlers()); } return this.getHandlers().iterator(); }
@Override public boolean subscribe(MessageHandler handler) { return this.dispatcher.addHandler(handler); }
@Override public boolean unsubscribe(MessageHandler handler) { return this.dispatcher.removeHandler(handler); }
/** * Specify whether the channel's dispatcher should have failover enabled. * By default, it will. Set this value to 'false' to disable it. * * @param failover The failover boolean. */ public void setFailover(boolean failover) { this.dispatcher.setFailover(failover); }
@Override public int getHandlerCount() { return this.handlers.size(); }
@Override public boolean subscribe(MessageHandler handler) { return this.dispatcher.addHandler(handler); }
@Override public boolean unsubscribe(MessageHandler handler) { return this.dispatcher.removeHandler(handler); }
/** * Returns an unmodifiable {@link Set} of this dispatcher's handlers. This * is provided for access by subclasses. * * @return The message handlers. */ protected Set<MessageHandler> getHandlers() { return this.handlers.asUnmodifiableSet(); }
/** * Specify the maximum number of subscribers supported by the * channel's dispatcher. * @param maxSubscribers The maximum number of subscribers allowed. */ public void setMaxSubscribers(int maxSubscribers) { this.maxSubscribers = maxSubscribers; this.dispatcher.setMaxSubscribers(maxSubscribers); }
/** * Will test addAll operation including the removal and adding an object in the concurrent environment */ @Test public void testConcurrentAll() { for (int i = 0; i < 1000; i++) { this.doConcurrentAll(); } } @SuppressWarnings("rawtypes")
@Before public void initialize() { dispatcher.setLoadBalancingStrategy(new RoundRobinLoadBalancingStrategy()); executor.setCorePoolSize(10); executor.setMaxPoolSize(10); executor.initialize(); }
/** * Create a channel with default {@link RoundRobinLoadBalancingStrategy} */ public DirectChannel() { this(new RoundRobinLoadBalancingStrategy()); }
/** * Specify the maximum number of subscribers supported by the * channel's dispatcher. * * @param maxSubscribers The maximum number of subscribers allowed. */ public void setMaxSubscribers(int maxSubscribers) { this.maxSubscribers = maxSubscribers; this.dispatcher.setMaxSubscribers(maxSubscribers); }