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
Modifier and TypeClassDescriptionprotected static final record
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<String,
DefaultHeaderChannelRegistry.MessageChannelWrapper> protected static final AtomicLong
protected final String
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionConstruct 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 long
boolean
protected void
onInit()
Subclasses may implement this for initialization logic.void
run()
void
Cancel the scheduled reap task and run immediately; then reschedule.final void
setReaperDelay
(long reaperDelay) Set the reaper delay.void
setRemoveOnGet
(boolean removeOnGet) Set to true to immediately remove the channel mapping whenchannelNameToChannel(String)
is invoked.final int
size()
void
start()
void
stop()
void
Methods 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:
size
in interfaceHeaderChannelRegistry
- 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 classIntegrationObjectSupport
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
stop
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-
channelToChannelName
Description copied from interface:HeaderChannelRegistry
Converts the channel to a name (String). If the channel is not aMessageChannel
, it is returned unchanged.- Specified by:
channelToChannelName
in interfaceHeaderChannelRegistry
- Parameters:
channel
- The channel.- Returns:
- The channel name, or the channel if it is not a MessageChannel.
-
channelToChannelName
Description copied from interface:HeaderChannelRegistry
Converts the channel to a name (String). If the channel is not aMessageChannel
, it is returned unchanged.- Specified by:
channelToChannelName
in 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:HeaderChannelRegistry
Converts the channel name back to aMessageChannel
(if it is registered).- Specified by:
channelNameToChannel
in 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:
runReaper
in interfaceHeaderChannelRegistry
-
run
public void run()
-