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.ChannelInterceptorListNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
FieldsFields inherited from class org.springframework.integration.channel.AbstractMessageChannel
interceptors, metersFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.messaging.MessageChannel
INDEFINITE_TIMEOUT -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 allMessagesfrom this channel.voiddestroy()protected Message<?>doReceive(long timeout) Subclasses must implement this method.protected booleanSubclasses must implement this method.intObtain the current number of queuedMessagesin this channel.intObtain the remaining capacity of this channel.purge(MessageSelector selector) Remove anyMessagesthat are not accepted by the provided selector.voidregisterMetricsCaptor(MetricsCaptor metricsCaptor) Inject aMetricsCaptor.Methods inherited from class org.springframework.integration.channel.AbstractPollableChannel
addInterceptor, addInterceptor, getIntegrationPatternType, hasExecutorInterceptors, receive, receive, removeInterceptor, removeInterceptor, setInterceptorsMethods inherited from class org.springframework.integration.channel.AbstractMessageChannel
getComponentType, getFullChannelName, getIChannelInterceptorList, getInterceptors, getMetricsCaptor, getOverrides, isLoggingEnabled, onInit, send, send, setDatatypes, setLoggingEnabled, setMessageConverter, setShouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedTypeMethods inherited from interface org.springframework.messaging.support.InterceptableChannel
getInterceptorsMethods inherited from interface org.springframework.messaging.MessageChannel
send, sendMethods 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:IntegrationManagementInject aMetricsCaptor.- Specified by:
registerMetricsCaptorin interfaceIntegrationManagement- Overrides:
registerMetricsCaptorin classAbstractMessageChannel- Parameters:
metricsCaptor- the captor.
-
doSend
Description copied from class:AbstractMessageChannelSubclasses 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:
doSendin classAbstractMessageChannel- Parameters:
message- The message.timeout- The timeout.- Returns:
- true if the send was successful.
-
doReceive
Description copied from class:AbstractPollableChannelSubclasses 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:
doReceivein classAbstractPollableChannel- Parameters:
timeout- The timeout.- Returns:
- The message, or null.
-
clear
Description copied from interface:QueueChannelOperationsRemove allMessagesfrom this channel.- Specified by:
clearin interfaceQueueChannelOperations- Returns:
- The messages that were removed.
-
purge
Description copied from interface:QueueChannelOperationsRemove anyMessagesthat are not accepted by the provided selector.- Specified by:
purgein interfaceQueueChannelOperations- Parameters:
selector- The message selector.- Returns:
- The list of messages that were purged.
-
getQueueSize
public int getQueueSize()Description copied from interface:QueueChannelOperationsObtain the current number of queuedMessagesin this channel.- Specified by:
getQueueSizein interfaceQueueChannelOperations- Returns:
- The current number of queued
Messagesin this channel.
-
getRemainingCapacity
public int getRemainingCapacity()Description copied from interface:QueueChannelOperationsObtain the remaining capacity of this channel.- Specified by:
getRemainingCapacityin interfaceQueueChannelOperations- Returns:
- The remaining capacity of this channel.
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean- Specified by:
destroyin interfaceIntegrationManagement- Overrides:
destroyin classAbstractMessageChannel
-