public abstract class AbstractMessageChannel extends IntegrationObjectSupport implements MessageChannel, TrackableComponent, ChannelInterceptorAware
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
.Modifier and Type | Class and Description |
---|---|
protected class |
AbstractMessageChannel.ChannelInterceptorList
A convenience wrapper class for the list of ChannelInterceptors.
|
logger
INDEFINITE_TIMEOUT
Constructor and Description |
---|
AbstractMessageChannel() |
Modifier and Type | Method and Description |
---|---|
void |
addInterceptor(ChannelInterceptor interceptor)
Add a channel interceptor to the end of the list.
|
void |
addInterceptor(int index,
ChannelInterceptor interceptor)
Add a channel interceptor to the specified index of the list.
|
protected abstract boolean |
doSend(Message<?> message,
long timeout)
Subclasses must implement this method.
|
List<ChannelInterceptor> |
getChannelInterceptors()
Return a read-only list of the configured interceptors.
|
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
String |
getFullChannelName()
Returns the fully qualified channel name including the application context
id, if available.
|
protected AbstractMessageChannel.ChannelInterceptorList |
getInterceptors()
Exposes the interceptor list for subclasses.
|
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
boolean |
send(Message<?> message)
Send a message on this channel.
|
boolean |
send(Message<?> message,
long timeout)
Send a message on this channel.
|
void |
setConversionService(ConversionService conversionService)
Deprecated.
No longer used; see
DefaultDatatypeChannelMessageConverter . |
void |
setDatatypes(Class<?>... datatypes)
Specify the Message payload datatype(s) supported by this channel.
|
void |
setInterceptors(List<ChannelInterceptor> interceptors)
Set the list of channel interceptors.
|
void |
setMessageConverter(MessageConverter messageConverter)
Specify the
MessageConverter to use when trying to convert to
one of this channel's supported datatypes (in order) for a Message whose payload
does not already match. |
void |
setShouldTrack(boolean shouldTrack) |
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setMessageBuilderFactory, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class IntegrationObjectSupport
public void setShouldTrack(boolean shouldTrack)
setShouldTrack
in interface TrackableComponent
public void setDatatypes(Class<?>... datatypes)
If this property is not set explicitly, any Message payload type will be accepted.
datatypes
- The supported data types.setMessageConverter(MessageConverter)
public void setInterceptors(List<ChannelInterceptor> interceptors)
setInterceptors
in interface ChannelInterceptorAware
interceptors
- The list of interceptors.public void addInterceptor(ChannelInterceptor interceptor)
addInterceptor
in interface ChannelInterceptorAware
interceptor
- The interceptor.public void addInterceptor(int index, ChannelInterceptor interceptor)
addInterceptor
in interface ChannelInterceptorAware
index
- The index to add interceptor.interceptor
- The interceptor.@Deprecated public void setConversionService(ConversionService conversionService)
DefaultDatatypeChannelMessageConverter
.ConversionService
to use when trying to convert to
one of this channel's supported datatypes for a Message whose payload
does not already match. If this property is not set explicitly but
the channel is managed within a context, it will attempt to locate a
bean named "integrationConversionService" defined within that context.setConversionService
in class IntegrationObjectSupport
conversionService
- The conversion service.public void setMessageConverter(MessageConverter messageConverter)
MessageConverter
to 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 a Message
, the inbound
headers will be copied; if the returned object is a Message
, it is
expected that the converter will have fully populated the headers; no
further action is performed by the channel. If null
is returned,
conversion to the next datatype (if any) will be attempted.
Defaults to a DefaultDatatypeChannelMessageConverter
.
messageConverter
- The message converter.public List<ChannelInterceptor> getChannelInterceptors()
getChannelInterceptors
in interface ChannelInterceptorAware
protected AbstractMessageChannel.ChannelInterceptorList getInterceptors()
protected void onInit() throws Exception
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
Exception
- Any exception.public String getFullChannelName()
public final boolean send(Message<?> message)
send
in interface MessageChannel
message
- the Message to sendtrue
if the message is sent successfully or
false
if the sending thread is interrupted.public final boolean send(Message<?> message, long timeout)
send(Message)
).send
in interface MessageChannel
message
- the Message to sendtimeout
- the timeout in millisecondstrue
if the message is sent successfully,
false
if the message cannot be sent within the allotted
time or the sending thread is interrupted.protected abstract boolean doSend(Message<?> message, long timeout)
message
- The message.timeout
- The timeout.