Class QueueChannel
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
org.springframework.integration.channel.AbstractPollableChannel
org.springframework.integration.channel.QueueChannel
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,ExecutorChannelInterceptorAware
,QueueChannelOperations
,ExpressionCapable
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,TrackableComponent
,MessageChannel
,PollableChannel
,InterceptableChannel
- Direct Known Subclasses:
PriorityChannel
,RendezvousChannel
Simple implementation of a message channel. Each
Message
is placed in
a BlockingQueue
whose capacity may be specified upon construction.
The capacity must be a positive integer value. For a zero-capacity version
based upon a SynchronousQueue
, consider the
RendezvousChannel
.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.channel.AbstractMessageChannel
AbstractMessageChannel.ChannelInterceptorList
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.channel.AbstractMessageChannel
interceptors, meters
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.messaging.MessageChannel
INDEFINITE_TIMEOUT
-
Constructor Summary
ConstructorDescriptionCreate a channel with "unbounded" queue capacity.QueueChannel
(int capacity) Create a channel with the specified queue capacity.QueueChannel
(Queue<Message<?>> queue) Create a channel with the specified queue. -
Method Summary
Modifier and TypeMethodDescriptionclear()
Remove allMessages
from this channel.void
destroy()
protected Message<?>
doReceive
(long timeout) Subclasses must implement this method.protected boolean
Subclasses must implement this method.int
Obtain the current number of queuedMessages
in this channel.int
Obtain the remaining capacity of this channel.purge
(MessageSelector selector) Remove anyMessages
that are not accepted by the provided selector.void
registerMetricsCaptor
(MetricsCaptor metricsCaptor) Inject aMetricsCaptor
.Methods inherited from class org.springframework.integration.channel.AbstractPollableChannel
addInterceptor, addInterceptor, getIntegrationPatternType, hasExecutorInterceptors, receive, receive, removeInterceptor, removeInterceptor, setInterceptors
Methods inherited from class org.springframework.integration.channel.AbstractMessageChannel
getComponentType, getFullChannelName, getIChannelInterceptorList, getInterceptors, getMetricsCaptor, getOverrides, isLoggingEnabled, isObserved, onInit, registerObservationRegistry, send, send, setDatatypes, setLoggingEnabled, setMessageConverter, setObservationConvention, setShouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedType
Methods inherited from interface org.springframework.messaging.support.InterceptableChannel
getInterceptors
Methods inherited from interface org.springframework.messaging.MessageChannel
send, send
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
queueSemaphore
-
-
Constructor Details
-
QueueChannel
Create a channel with the specified queue.- Parameters:
queue
- The queue.
-
QueueChannel
public QueueChannel(int capacity) Create a channel with the specified queue capacity.- Parameters:
capacity
- The capacity.
-
QueueChannel
public QueueChannel()Create a channel with "unbounded" queue capacity. The actual capacity value isInteger.MAX_VALUE
. Note that a bounded queue is recommended, since an unbounded queue may lead to OutOfMemoryErrors.
-
-
Method Details
-
registerMetricsCaptor
Description copied from interface:IntegrationManagement
Inject aMetricsCaptor
. Ignored ifObservationRegistry
is provided.- Specified by:
registerMetricsCaptor
in interfaceIntegrationManagement
- Overrides:
registerMetricsCaptor
in classAbstractMessageChannel
- Parameters:
metricsCaptor
- the captor.- See Also:
-
doSend
Description copied from class:AbstractMessageChannel
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.- Specified by:
doSend
in classAbstractMessageChannel
- Parameters:
message
- The message.timeout
- The timeout.- Returns:
- true if the
send
was successful.
-
doReceive
Description copied from class:AbstractPollableChannel
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is empty (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either a message is available or the blocking thread is interrupted.- Specified by:
doReceive
in classAbstractPollableChannel
- Parameters:
timeout
- The timeout.- Returns:
- The message, or null.
-
clear
Description copied from interface:QueueChannelOperations
Remove allMessages
from this channel.- Specified by:
clear
in interfaceQueueChannelOperations
- Returns:
- The messages that were removed.
-
purge
Description copied from interface:QueueChannelOperations
Remove anyMessages
that are not accepted by the provided selector.- Specified by:
purge
in interfaceQueueChannelOperations
- Parameters:
selector
- The message selector.- Returns:
- The list of messages that were purged.
-
getQueueSize
public int getQueueSize()Description copied from interface:QueueChannelOperations
Obtain the current number of queuedMessages
in this channel.- Specified by:
getQueueSize
in interfaceQueueChannelOperations
- Returns:
- The current number of queued
Messages
in this channel.
-
getRemainingCapacity
public int getRemainingCapacity()Description copied from interface:QueueChannelOperations
Obtain the remaining capacity of this channel.- Specified by:
getRemainingCapacity
in interfaceQueueChannelOperations
- Returns:
- The remaining capacity of this channel.
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Specified by:
destroy
in interfaceIntegrationManagement
- Overrides:
destroy
in classAbstractMessageChannel
-