Class AbstractMessageChannel
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
- All Implemented Interfaces:
Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,ExpressionCapable,IntegrationPattern,NamedComponent,IntegrationManagement,TrackableComponent,MessageChannel,InterceptableChannel
- Direct Known Subclasses:
AbstractAmqpChannel,AbstractJmsChannel,AbstractKafkaChannel,AbstractPollableChannel,AbstractSubscribableChannel,FluxMessageChannel,SubscribableRedisChannel,ZeroMqChannel
@IntegrationManagedResource public abstract class AbstractMessageChannel extends IntegrationObjectSupport implements MessageChannel, TrackableComponent, InterceptableChannel, IntegrationManagement, IntegrationPattern
Base class for
MessageChannel implementations providing common
properties such as the channel name. Also provides the common functionality
for sending and receiving Messages including the invocation
of any ChannelInterceptors.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractMessageChannel.ChannelInterceptorListA convenience wrapper class for the list of ChannelInterceptors.Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields Modifier and Type Field Description protected AbstractMessageChannel.ChannelInterceptorListinterceptorsprotected Set<MeterFacade>metersFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME -
Constructor Summary
Constructors Constructor Description AbstractMessageChannel() -
Method Summary
Modifier and Type Method Description voidaddInterceptor(int index, ChannelInterceptor interceptor)Add a channel interceptor to the specified index of the list.voidaddInterceptor(ChannelInterceptor interceptor)Add a channel interceptor to the end of the list.voiddestroy()protected abstract booleandoSend(Message<?> message, long timeout)Subclasses must implement this method.StringgetComponentType()Subclasses may implement this method to provide component type information.StringgetFullChannelName()Returns the fully qualified channel name including the application context id, if available.protected AbstractMessageChannel.ChannelInterceptorListgetIChannelInterceptorList()Exposes the interceptor list instance for subclasses.IntegrationPatternTypegetIntegrationPatternType()Return a pattern type this component implements.List<ChannelInterceptor>getInterceptors()Return a read-only list of the configured interceptors.protected MetricsCaptorgetMetricsCaptor()IntegrationManagement.ManagementOverridesgetOverrides()Return the overrides.booleanisLoggingEnabled()Return whether logging is enabled.protected voidonInit()Subclasses may implement this for initialization logic.voidregisterMetricsCaptor(MetricsCaptor metricsCaptorToRegister)Inject aMetricsCaptor.ChannelInterceptorremoveInterceptor(int index)booleanremoveInterceptor(ChannelInterceptor interceptor)booleansend(Message<?> message)Send a message on this channel.booleansend(Message<?> messageArg, long timeout)Send a message on this channel.voidsetDatatypes(Class<?>... datatypes)Specify the Message payload datatype(s) supported by this channel.voidsetInterceptors(List<ChannelInterceptor> interceptors)Set the list of channel interceptors.voidsetLoggingEnabled(boolean loggingEnabled)Enable logging or not.voidsetMessageConverter(MessageConverter messageConverter)Specify theMessageConverterto use when trying to convert to one of this channel's supported datatypes (in order) for a Message whose payload does not already match.voidsetShouldTrack(boolean shouldTrack)Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedTypeMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
Constructor Details
-
AbstractMessageChannel
public AbstractMessageChannel()
-
-
Method Details
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classIntegrationObjectSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPatternReturn a pattern type this component implements.- Specified by:
getIntegrationPatternTypein interfaceIntegrationPattern- Returns:
- the
IntegrationPatternTypethis component implements.
-
setShouldTrack
public void setShouldTrack(boolean shouldTrack)- Specified by:
setShouldTrackin interfaceTrackableComponent
-
registerMetricsCaptor
Description copied from interface:IntegrationManagementInject aMetricsCaptor.- Specified by:
registerMetricsCaptorin interfaceIntegrationManagement- Parameters:
metricsCaptorToRegister- the captor.
-
getMetricsCaptor
-
isLoggingEnabled
public boolean isLoggingEnabled()Description copied from interface:IntegrationManagementReturn whether logging is enabled.- Specified by:
isLoggingEnabledin interfaceIntegrationManagement- Returns:
- true if enabled.
-
setLoggingEnabled
public void setLoggingEnabled(boolean loggingEnabled)Description copied from interface:IntegrationManagementEnable logging or not.- Specified by:
setLoggingEnabledin interfaceIntegrationManagement- Parameters:
loggingEnabled- dalse to disable.
-
setDatatypes
Specify the Message payload datatype(s) supported by this channel. If a payload type does not match directly, but the 'conversionService' is available, then type conversion will be attempted in the order of the elements provided in this array.If this property is not set explicitly, any Message payload type will be accepted.
- Parameters:
datatypes- The supported data types.- See Also:
setMessageConverter(MessageConverter)
-
setInterceptors
Set the list of channel interceptors. This will clear any existing interceptors.- Specified by:
setInterceptorsin interfaceInterceptableChannel- Parameters:
interceptors- The list of interceptors.
-
addInterceptor
Add a channel interceptor to the end of the list.- Specified by:
addInterceptorin interfaceInterceptableChannel- Parameters:
interceptor- The interceptor.
-
addInterceptor
Add a channel interceptor to the specified index of the list.- Specified by:
addInterceptorin interfaceInterceptableChannel- Parameters:
index- The index to add interceptor.interceptor- The interceptor.
-
setMessageConverter
Specify theMessageConverterto use when trying to convert to one of this channel's supported datatypes (in order) for a Message whose payload does not already match.Note: only the
MessageConverter.fromMessage(Message, Class)method is used. If the returned object is not aMessage, the inbound headers will be copied; if the returned object is aMessage, it is expected that the converter will have fully populated the headers; no further action is performed by the channel. Ifnullis returned, conversion to the next datatype (if any) will be attempted. Defaults to aDefaultDatatypeChannelMessageConverter.- Parameters:
messageConverter- The message converter.
-
getInterceptors
Return a read-only list of the configured interceptors.- Specified by:
getInterceptorsin interfaceInterceptableChannel
-
removeInterceptor
- Specified by:
removeInterceptorin interfaceInterceptableChannel
-
removeInterceptor
- Specified by:
removeInterceptorin interfaceInterceptableChannel
-
getIChannelInterceptorList
Exposes the interceptor list instance for subclasses.- Returns:
- The channel interceptor list.
-
getOverrides
Description copied from interface:IntegrationManagementReturn the overrides.- Specified by:
getOverridesin interfaceIntegrationManagement- Returns:
- the overrides.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
getFullChannelName
Returns the fully qualified channel name including the application context id, if available.- Returns:
- The name.
-
send
Send a message on this channel. If the channel is at capacity, this method will block until either space becomes available or the sending thread is interrupted.- Specified by:
sendin interfaceMessageChannel- Parameters:
message- the Message to send- Returns:
trueif the message is sent successfully orfalseif the sending thread is interrupted.
-
send
Send a message on this channel. If the channel is at capacity, this method will block until either the timeout occurs or the sending thread is interrupted. If the specified timeout is 0, the method will return immediately. If less than zero, it will block indefinitely (seesend(Message)).- Specified by:
sendin interfaceMessageChannel- Parameters:
messageArg- the Message to sendtimeout- the timeout in milliseconds- Returns:
trueif the message is sent successfully,falseif the message cannot be sent within the allotted time or the sending thread is interrupted.
-
doSend
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.- Parameters:
message- The message.timeout- The timeout.- Returns:
- true if the send was successful.
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean- Specified by:
destroyin interfaceIntegrationManagement
-