org.springframework.messaging.support

## Class AbstractMessageChannel

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

- All Implemented Interfaces:
    Aware, BeanNameAware, MessageChannel
  Direct Known Subclasses:
    AbstractSubscribableChannel

      public abstract class AbstractMessageChannel
      extends Object
      implements MessageChannel, BeanNameAware

  Abstract base class for `MessageChannel` implementations.
  Since:
    4.0
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addInterceptor(ChannelInterceptor interceptor)` Add a channel interceptor to the end of the list.
    `String` | `getBeanName()`
    `protected org.springframework.messaging.support.ChannelInterceptorChain` | `getInterceptorChain()` Exposes the interceptor list for subclasses.
    `List<ChannelInterceptor>` | `getInterceptors()` Return a read-only list of the configured interceptors.
    `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)` Set the name of the bean in the bean factory that created this bean.
    `void` | `setInterceptors(List<ChannelInterceptor> interceptors)` Set the list of channel interceptors.
    `String` | `toString()`

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

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

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### AbstractMessageChannel

          public AbstractMessageChannel()

  - ### Method Detail

    - #### setBeanName

          public void setBeanName(String name)

      Set the name of the bean in the bean factory that created this bean.

      Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method.

      Used primarily for logging purposes.

      Specified by:
        `setBeanName` in interface `BeanNameAware`
      Parameters:
        `name` - the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the `BeanFactoryUtils.originalBeanName(String)` method to extract the original bean name (without suffix), if desired.

    - #### getBeanName

          public String getBeanName()

      Returns:
        the name for this channel.

    - #### setInterceptors

          public void setInterceptors(List<ChannelInterceptor> interceptors)

      Set the list of channel interceptors. This will clear any existing interceptors.

    - #### addInterceptor

          public void addInterceptor(ChannelInterceptor interceptor)

      Add a channel interceptor to the end of the list.

    - #### getInterceptors

          public List<ChannelInterceptor> getInterceptors()

      Return a read-only list of the configured interceptors.

    - #### getInterceptorChain

          protected org.springframework.messaging.support.ChannelInterceptorChain getInterceptorChain()

      Exposes the interceptor list for subclasses.

    - #### 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`