org.springframework.messaging.support

## Class AbstractMessageChannel

- java.lang.Object
- - org.springframework.messaging.support.AbstractMessageChannel

All Implemented Interfaces:
  org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, MessageChannel, InterceptableChannel

Direct Known Subclasses:
  AbstractSubscribableChannel

    public abstract class AbstractMessageChannel
    extends Object
    implements MessageChannel, InterceptableChannel, org.springframework.beans.factory.BeanNameAware

Abstract base class for `MessageChannel` implementations.

Since:
  4.0
Author:
  Rossen Stoyanchev

### Nested Class Summary

Nested Classes
`protected class` `AbstractMessageChannel.ChannelInterceptorChain` Assists with the invocation of the configured channel interceptors.

### Field Summary

Fields
`protected Log` `logger`

### Fields inherited from interface org.springframework.messaging.MessageChannel

`INDEFINITE_TIMEOUT`

### Constructor Summary

Constructors
Constructor and Description
`AbstractMessageChannel()`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`void` `addInterceptor(ChannelInterceptor interceptor)` Add a channel interceptor to the end of the list.
`void` `addInterceptor(int index, ChannelInterceptor interceptor)` Add a channel interceptor at the specified index.
`String` `getBeanName()` Return the bean name for this message channel.
`List<ChannelInterceptor>` `getInterceptors()` Return the list of configured interceptors.
`Log` `getLogger()` Return the currently configured Logger.
`boolean` `removeInterceptor(ChannelInterceptor interceptor)` Remove the given interceptor.
`ChannelInterceptor` `removeInterceptor(int index)` Remove the interceptor at the given index.
`boolean` `send(Message<?> message)` Send a `Message` to this channel.
`boolean` `send(Message<?> message, long timeout)` Send a message, blocking until either the message is accepted or the specified timeout period elapses.
`protected abstract boolean` `sendInternal(Message<?> message, long timeout)`
`void` `setBeanName(String name)` A message channel uses the bean name primarily for logging purposes.
`void` `setInterceptors(List<ChannelInterceptor> interceptors)` Set the list of channel interceptors clearing any existing interceptors.
`void` `setLogger(Log logger)` Set an alternative logger to use than the one based on the class name.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### logger

    protected Log logger

### Constructor Detail

#### AbstractMessageChannel

    public AbstractMessageChannel()

### Method Detail

#### setLogger

    public void setLogger(Log logger)

Set an alternative logger to use than the one based on the class name.

Parameters:
  `logger` - the logger to use
Since:
  5.1

#### getLogger

    public Log getLogger()

Return the currently configured Logger.

Since:
  5.1

#### setBeanName

    public void setBeanName(String name)

A message channel uses the bean name primarily for logging purposes.

Specified by:
  `setBeanName` in interface `org.springframework.beans.factory.BeanNameAware`

#### getBeanName

    public String getBeanName()

Return the bean name for this message channel.

#### setInterceptors

    public void setInterceptors(List<ChannelInterceptor> interceptors)

Description copied from interface: `InterceptableChannel`
Set the list of channel interceptors clearing any existing interceptors.

Specified by:
  `setInterceptors` in interface `InterceptableChannel`

#### addInterceptor

    public void addInterceptor(ChannelInterceptor interceptor)

Description copied from interface: `InterceptableChannel`
Add a channel interceptor to the end of the list.

Specified by:
  `addInterceptor` in interface `InterceptableChannel`

#### addInterceptor

    public void addInterceptor(int index,
                               ChannelInterceptor interceptor)

Description copied from interface: `InterceptableChannel`
Add a channel interceptor at the specified index.

Specified by:
  `addInterceptor` in interface `InterceptableChannel`

#### getInterceptors

    public List<ChannelInterceptor> getInterceptors()

Description copied from interface: `InterceptableChannel`
Return the list of configured interceptors.

Specified by:
  `getInterceptors` in interface `InterceptableChannel`

#### removeInterceptor

    public boolean removeInterceptor(ChannelInterceptor interceptor)

Description copied from interface: `InterceptableChannel`
Remove the given interceptor.

Specified by:
  `removeInterceptor` in interface `InterceptableChannel`

#### removeInterceptor

    public ChannelInterceptor removeInterceptor(int index)

Description copied from interface: `InterceptableChannel`
Remove the interceptor at the given index.

Specified by:
  `removeInterceptor` in interface `InterceptableChannel`

#### send

    public final boolean send(Message<?> message)

Description copied from interface: `MessageChannel`
Send a `Message` to this channel. If the message is sent successfully, the method returns `true`. If the message cannot be sent due to a non-fatal reason, the method returns `false`. The method may also throw a RuntimeException in case of non-recoverable errors.

This method may block indefinitely, depending on the implementation. To provide a maximum wait time, use `MessageChannel.send(Message, long)`.

Specified by:
  `send` in interface `MessageChannel`
Parameters:
  `message` - the message to send
Returns:
  whether or not the message was sent

#### send

    public final boolean send(Message<?> message,
                              long timeout)

Description copied from interface: `MessageChannel`
Send a message, blocking until either the message is accepted or the specified timeout period elapses.

Specified by:
  `send` in interface `MessageChannel`
Parameters:
  `message` - the message to send
  `timeout` - the timeout in milliseconds or `MessageChannel.INDEFINITE_TIMEOUT`
Returns:
  `true` if the message is sent, `false` if not including a timeout of an interrupt of the send

#### sendInternal

    protected abstract boolean sendInternal(Message<?> message,
                                            long timeout)

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`