Class DefaultHeaderChannelRegistry

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.DefaultHeaderChannelRegistry
All Implemented Interfaces:
java.lang.Runnable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, ExpressionCapable, HeaderChannelRegistry, NamedComponent, ManageableLifecycle

public class DefaultHeaderChannelRegistry
extends IntegrationObjectSupport
implements HeaderChannelRegistry, ManageableLifecycle, java.lang.Runnable
Converts a channel to a name, retaining a reference to the channel keyed by the name. Allows a downstream BeanFactoryChannelResolver to find the channel by name in the event that the flow serialized the message at some point. Channels are expired after a configurable delay (60 seconds by default). The actual average expiry time will be 1.5x the delay.
Since:
3.0
  • Field Details

    • id

      protected static final java.util.concurrent.atomic.AtomicLong id
    • channels

      protected final java.util.Map<java.lang.String,​org.springframework.integration.channel.DefaultHeaderChannelRegistry.MessageChannelWrapper> channels
    • uuid

      protected final java.lang.String uuid
  • Constructor Details

    • DefaultHeaderChannelRegistry

      public DefaultHeaderChannelRegistry()
      Constructs a registry with the default delay for channel expiry.
    • DefaultHeaderChannelRegistry

      public DefaultHeaderChannelRegistry​(long reaperDelay)
      Constructs a registry with the provided delay (milliseconds) for channel expiry.
      Parameters:
      reaperDelay - the delay in milliseconds.
  • Method Details

    • setReaperDelay

      public final void setReaperDelay​(long reaperDelay)
      Set the reaper delay.
      Parameters:
      reaperDelay - the delay in milliseconds.
    • getReaperDelay

      public final long getReaperDelay()
    • setRemoveOnGet

      public void setRemoveOnGet​(boolean removeOnGet)
      Set to true to immediately remove the channel mapping when channelNameToChannel(String) is invoked.
      Parameters:
      removeOnGet - true to remove immediately, default false.
      Since:
      4.1
    • size

      public final int size()
      Specified by:
      size in interface HeaderChannelRegistry
      Returns:
      the current size of the registry
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class IntegrationObjectSupport
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • stop

      public void stop​(java.lang.Runnable callback)
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle
    • channelToChannelName

      @Nullable public java.lang.Object channelToChannelName​(@Nullable java.lang.Object channel)
      Description copied from interface: HeaderChannelRegistry
      Converts the channel to a name (String). If the channel is not a MessageChannel, it is returned unchanged.
      Specified by:
      channelToChannelName in interface HeaderChannelRegistry
      Parameters:
      channel - The channel.
      Returns:
      The channel name, or the channel if it is not a MessageChannel.
    • channelToChannelName

      @Nullable public java.lang.Object channelToChannelName​(@Nullable java.lang.Object channel, long timeToLive)
      Description copied from interface: HeaderChannelRegistry
      Converts the channel to a name (String). If the channel is not a MessageChannel, it is returned unchanged.
      Specified by:
      channelToChannelName in interface HeaderChannelRegistry
      Parameters:
      channel - The channel.
      timeToLive - How long (ms) at a minimum, the channel mapping should remain in the registry.
      Returns:
      The channel name, or the channel if it is not a MessageChannel.
    • channelNameToChannel

      @Nullable public org.springframework.messaging.MessageChannel channelNameToChannel​(@Nullable java.lang.String name)
      Description copied from interface: HeaderChannelRegistry
      Converts the channel name back to a MessageChannel (if it is registered).
      Specified by:
      channelNameToChannel in interface HeaderChannelRegistry
      Parameters:
      name - The name of the channel.
      Returns:
      The channel, or null if there is no channel registered with the name.
    • runReaper

      public void runReaper()
      Cancel the scheduled reap task and run immediately; then reschedule.
      Specified by:
      runReaper in interface HeaderChannelRegistry
    • run

      public void run()
      Specified by:
      run in interface java.lang.Runnable