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,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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final record -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<String,DefaultHeaderChannelRegistry.MessageChannelWrapper> protected static final AtomicLongprotected final StringFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a registry with the default delay for channel expiry.DefaultHeaderChannelRegistry(long reaperDelay) Construct a registry with the provided delay (milliseconds) for channel expiry. -
Method Summary
Modifier and TypeMethodDescriptionchannelNameToChannel(String name) Converts the channel name back to aMessageChannel(if it is registered).channelToChannelName(Object channel) Converts the channel to a name (String).channelToChannelName(Object channel, long timeToLive) Converts the channel to a name (String).final longbooleanprotected voidonInit()Subclasses may implement this for initialization logic.voidrun()voidCancel the scheduled reap task and run immediately; then reschedule.final voidsetReaperDelay(long reaperDelay) Set the reaper delay.voidsetRemoveOnGet(boolean removeOnGet) Set to true to immediately remove the channel mapping whenchannelNameToChannel(String)is invoked.final intsize()voidstart()voidstop()voidMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
-
Field Details
-
id
-
channels
-
uuid
-
-
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 whenchannelNameToChannel(String)is invoked.- Parameters:
removeOnGet- true to remove immediately, default false.- Since:
- 4.1
-
size
public final int size()- Specified by:
sizein interfaceHeaderChannelRegistry- Returns:
- the current size of the registry
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
start
public void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle
-
stop
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle
-
channelToChannelName
Description copied from interface:HeaderChannelRegistryConverts the channel to a name (String). If the channel is not aMessageChannel, it is returned unchanged.- Specified by:
channelToChannelNamein interfaceHeaderChannelRegistry- Parameters:
channel- The channel.- Returns:
- The channel name, or the channel if it is not a MessageChannel.
-
channelToChannelName
Description copied from interface:HeaderChannelRegistryConverts the channel to a name (String). If the channel is not aMessageChannel, it is returned unchanged.- Specified by:
channelToChannelNamein interfaceHeaderChannelRegistry- 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
Description copied from interface:HeaderChannelRegistryConverts the channel name back to aMessageChannel(if it is registered).- Specified by:
channelNameToChannelin interfaceHeaderChannelRegistry- 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:
runReaperin interfaceHeaderChannelRegistry
-
run
public void run()
-