private MessageDispatcher getRequiredDispatcher() { MessageDispatcher dispatcher = getDispatcher(); Assert.state(dispatcher != null, "'dispatcher' must not be null"); return dispatcher; }
@Override public boolean subscribe(MessageHandler handler) { MessageDispatcher dispatcher = getRequiredDispatcher(); boolean added = dispatcher.addHandler(handler); adjustCounterIfNecessary(dispatcher, added ? 1 : 0); return added; }
@Override public void addInterceptor(int index, ChannelInterceptor interceptor) { super.addInterceptor(index, interceptor); if (interceptor instanceof ExecutorChannelInterceptor) { this.executorInterceptorsSize++; } }
@Override protected boolean doSend(Message<?> message, long timeout) { try { return getRequiredDispatcher().dispatch(message); } catch (MessageDispatchingException e) { String description = e.getMessage() + " for channel '" + this.getFullChannelName() + "'."; throw new MessageDeliveryException(message, description, e); } }
+ channel.getComponentName() + "' has " + "%d subscriber(s)."; channel.subscribe(handler1); assertEquals(1, channel.getSubscriberCount()); assertEquals(String.format(log, 1), logs.remove(0)); MessageHandler handler2 = mock(MessageHandler.class); channel.subscribe(handler2); assertEquals(2, channel.getSubscriberCount()); assertEquals(String.format(log, 2), logs.remove(0)); channel.unsubscribe(handler1); assertEquals(1, channel.getSubscriberCount()); assertEquals(String.format(log, 1), logs.remove(0)); channel.unsubscribe(handler1); assertEquals(1, channel.getSubscriberCount()); assertEquals(0, logs.size()); channel.unsubscribe(handler2); assertEquals(0, channel.getSubscriberCount()); assertEquals(String.format(log, 0), logs.remove(0)); verify(logger, times(4)).info(Mockito.anyString());
@Override public int getSubscriberCount() { return getRequiredDispatcher().getHandlerCount(); }
@Override public boolean removeInterceptor(ChannelInterceptor interceptor) { boolean removed = super.removeInterceptor(interceptor); if (removed && interceptor instanceof ExecutorChannelInterceptor) { this.executorInterceptorsSize--; } return removed; }
@Override protected void onInit() { super.onInit(); if (this.maxSubscribers == null) { Integer max = this.getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class); this.setMaxSubscribers(max); } }
@Override public void setInterceptors(List<ChannelInterceptor> interceptors) { super.setInterceptors(interceptors); for (ChannelInterceptor interceptor : interceptors) { if (interceptor instanceof ExecutorChannelInterceptor) { this.executorInterceptorsSize++; } } }
private void adjustCounterIfNecessary(MessageDispatcher dispatcher, int delta) { if (delta != 0) { if (logger.isInfoEnabled()) { logger.info("Channel '" + this.getFullChannelName() + "' has " + dispatcher.getHandlerCount() + " subscriber(s)."); } } }
private boolean isSubscribable(SubscribableChannel errorChannel) { if (errorChannel instanceof PublishSubscribeChannel) { return true; } return errorChannel instanceof AbstractSubscribableChannel ? ((AbstractSubscribableChannel)errorChannel).getSubscriberCount() == 0 : true; }
@Override protected boolean doSend(Message<?> message, long timeout) { try { return getRequiredDispatcher().dispatch(message); } catch (MessageDispatchingException e) { String description = e.getMessage() + " for channel '" + this.getFullChannelName() + "'."; throw new MessageDeliveryException(message, description, e); } }
public boolean subscribe(MessageHandler handler) { return this.getRequiredDispatcher().addHandler(handler); }
@Override public ChannelInterceptor removeInterceptor(int index) { ChannelInterceptor interceptor = super.removeInterceptor(index); if (interceptor instanceof ExecutorChannelInterceptor) { this.executorInterceptorsSize--; } return interceptor; }
@Override protected void onInit() { super.onInit(); if (this.maxSubscribers == null) { Integer max = this.getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class); this.setMaxSubscribers(max); } }
@Override public void setInterceptors(List<ChannelInterceptor> interceptors) { super.setInterceptors(interceptors); for (ChannelInterceptor interceptor : interceptors) { if (interceptor instanceof ExecutorChannelInterceptor) { this.executorInterceptorsSize++; } } }
private void adjustCounterIfNecessary(MessageDispatcher dispatcher, int delta) { if (delta != 0) { if (logger.isInfoEnabled()) { logger.info("Channel '" + this.getFullChannelName() + "' has " + dispatcher.getHandlerCount() + " subscriber(s)."); } } }
@Override public boolean unsubscribe(MessageHandler handle) { MessageDispatcher dispatcher = getRequiredDispatcher(); boolean removed = dispatcher.removeHandler(handle); this.adjustCounterIfNecessary(dispatcher, removed ? -1 : 0); return removed; }
@Override public int getSubscriberCount() { return getRequiredDispatcher().getHandlerCount(); }
private MessageDispatcher getRequiredDispatcher() { MessageDispatcher dispatcher = getDispatcher(); Assert.state(dispatcher != null, "'dispatcher' must not be null"); return dispatcher; }