Class AbstractMessageChannel
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,ExpressionCapable,IntegrationPattern,NamedComponent,IntegrationManagement,TrackableComponent,org.springframework.messaging.MessageChannel,org.springframework.messaging.support.InterceptableChannel
- Direct Known Subclasses:
AbstractPollableChannel,AbstractSubscribableChannel,FluxMessageChannel
@IntegrationManagedResource public abstract class AbstractMessageChannel extends IntegrationObjectSupport implements org.springframework.messaging.MessageChannel, TrackableComponent, org.springframework.messaging.support.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.-
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 java.util.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, org.springframework.messaging.support.ChannelInterceptor interceptor)Add a channel interceptor to the specified index of the list.voidaddInterceptor(org.springframework.messaging.support.ChannelInterceptor interceptor)Add a channel interceptor to the end of the list.voiddestroy()protected abstract booleandoSend(org.springframework.messaging.Message<?> message, long timeout)Subclasses must implement this method.java.lang.StringgetComponentType()Subclasses may implement this method to provide component type information.java.lang.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.java.util.List<org.springframework.messaging.support.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 aMetricsCaptororg.springframework.messaging.support.ChannelInterceptorremoveInterceptor(int index)booleanremoveInterceptor(org.springframework.messaging.support.ChannelInterceptor interceptor)booleansend(org.springframework.messaging.Message<?> message)Send a message on this channel.booleansend(org.springframework.messaging.Message<?> messageArg, long timeout)Send a message on this channel.voidsetDatatypes(java.lang.Class<?>... datatypes)Specify the Message payload datatype(s) supported by this channel.voidsetInterceptors(java.util.List<org.springframework.messaging.support.ChannelInterceptor> interceptors)Set the list of channel interceptors.voidsetLoggingEnabled(boolean loggingEnabled)Enable logging or not.voidsetMessageConverter(org.springframework.messaging.converter.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
public java.lang.String 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
public void setDatatypes(java.lang.Class<?>... datatypes)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
public void setInterceptors(java.util.List<org.springframework.messaging.support.ChannelInterceptor> interceptors)Set the list of channel interceptors. This will clear any existing interceptors.- Specified by:
setInterceptorsin interfaceorg.springframework.messaging.support.InterceptableChannel- Parameters:
interceptors- The list of interceptors.
-
addInterceptor
public void addInterceptor(org.springframework.messaging.support.ChannelInterceptor interceptor)Add a channel interceptor to the end of the list.- Specified by:
addInterceptorin interfaceorg.springframework.messaging.support.InterceptableChannel- Parameters:
interceptor- The interceptor.
-
addInterceptor
public void addInterceptor(int index, org.springframework.messaging.support.ChannelInterceptor interceptor)Add a channel interceptor to the specified index of the list.- Specified by:
addInterceptorin interfaceorg.springframework.messaging.support.InterceptableChannel- Parameters:
index- The index to add interceptor.interceptor- The interceptor.
-
setMessageConverter
public void setMessageConverter(org.springframework.messaging.converter.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.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
public java.util.List<org.springframework.messaging.support.ChannelInterceptor> getInterceptors()Return a read-only list of the configured interceptors.- Specified by:
getInterceptorsin interfaceorg.springframework.messaging.support.InterceptableChannel
-
removeInterceptor
public boolean removeInterceptor(org.springframework.messaging.support.ChannelInterceptor interceptor)- Specified by:
removeInterceptorin interfaceorg.springframework.messaging.support.InterceptableChannel
-
removeInterceptor
@Nullable public org.springframework.messaging.support.ChannelInterceptor removeInterceptor(int index)- Specified by:
removeInterceptorin interfaceorg.springframework.messaging.support.InterceptableChannel
-
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
public java.lang.String getFullChannelName()Returns the fully qualified channel name including the application context id, if available.- Returns:
- The name.
-
send
public boolean send(org.springframework.messaging.Message<?> message)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 interfaceorg.springframework.messaging.MessageChannel- Parameters:
message- the Message to send- Returns:
trueif the message is sent successfully orfalseif the sending thread is interrupted.
-
send
public boolean send(org.springframework.messaging.Message<?> messageArg, long timeout)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 interfaceorg.springframework.messaging.MessageChannel- 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
protected abstract boolean doSend(org.springframework.messaging.Message<?> message, long timeout)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 interfaceorg.springframework.beans.factory.DisposableBean- Specified by:
destroyin interfaceIntegrationManagement
-