Class DefaultHeaderChannelRegistry

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

public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport implements HeaderChannelRegistry, ManageableLifecycle, 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
Author:
Gary Russell, Artem Bilan, Trung Pham, Christian Tzolov
  • Field Details

  • Constructor Details

    • DefaultHeaderChannelRegistry

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

      public DefaultHeaderChannelRegistry(long reaperDelay)
      Construct 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 Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • stop

      public void stop(Runnable callback)
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle
    • channelToChannelName

      public @Nullable Object channelToChannelName(@Nullable 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

      public @Nullable Object channelToChannelName(@Nullable 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

      public @Nullable MessageChannel channelNameToChannel(@Nullable 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 Runnable
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface NamedComponent