Package com.swiftmq.swiftlet.queue
Class MessageProcessor
java.lang.Object
com.swiftmq.swiftlet.queue.MessageProcessor
Abstract MessageProcessor to register at a
The MessageProcessor can be used in bulk mode. That is, the
MessageProcessor implements
QueuePullTransaction
.
The QueuePullTransaction
registers it at the queue within the
transaction context. The MessageProcessor will be invoked when a message
is available in the queue and if it does match the selector, if specified.
The MessageProcessor can be used in bulk mode. That is, the
setBulkMode(true)
must be called and the bulk buffer has
to be created with ceateBulkBuffer(size)
. In bulk mode, the
method processMessages(n)
is called instead of
processMessage(messageEntry)
. The size of the bulk can be
limited by overwritin method getMaxBulkSize()
which returns
either -1 (unlimited) or the max size in bytes. The Queue Manager will
setCurrentBulkSize(n)
zu the size of all messages in the current bulk.
MessageProcessor implements
AsyncTask
for convenience. It is
highly recommended to implement the processing of the message inside the
run()
method and to dispatch this task in a thread pool within
processMessage()
to avoid blocking of other threads.- Author:
- IIT GmbH, Bremen/Germany, Copyright (c) 2000-2002, All Rights Reserved
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new MessageProcessor.protected
MessageProcessor
(Selector selector) Creates a new MessageProcessor with a selector.protected
MessageProcessor
(Selector selector, long timeout) Creates a new MessageProcessor with a selector and timeout. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
createBulkBuffer
(int bulkSize) Creates a new bulk buffer in the given sizeReturns the bulk bufferlong
Returns the current bulkReturns a short description of this task.Returns the dispatch token of the task.long
Returns the max bulk sizelong
int
Returns the registration id.long
Returns the registration time.Returns the selector.long
Returns the timeout.Returns the transaction id.int
Returns the viewId.boolean
Returns whether the message should be auto committedboolean
Returns whether this message processor runs in bulk modeabstract void
processException
(Exception exception) Process an exception.abstract void
processMessage
(MessageEntry messageEntry) Process a message.void
processMessages
(int numberMessages) Process messages in bulk mode.void
reset()
Reset the MessageProcessor to its initial state without the need to recreate it.void
run()
Implements the task logic.void
setAutoCommit
(boolean autoCommit) Sets whether the message should be auto committedprotected void
setBulkMode
(boolean bulkMode) Sets whether this message processor runs in bulk modevoid
setCurrentBulkSize
(long currentBulkSize) Sets the current bulk sizevoid
setReceiverId
(long receiverId) void
setRegistrationId
(int registrationId) Sets a registration id.void
setRegistrationTime
(long registrationTime) Sets a registration time.protected void
setTransactionId
(Object transactionId) Sets the transaction id.void
setViewId
(int viewId) Sets the view id.void
stop()
Stops this task.
-
Constructor Details
-
MessageProcessor
protected MessageProcessor()Creates a new MessageProcessor. -
MessageProcessor
Creates a new MessageProcessor with a selector.- Parameters:
selector
- selector.
-
MessageProcessor
Creates a new MessageProcessor with a selector and timeout. If a timeout occurs,processException()
is called and the exception will be aQueueTimeoutException
- Parameters:
selector
- selector.timeout
- timeout (0 = no timeout).- See Also:
-
-
Method Details
-
getReceiverId
public long getReceiverId() -
setReceiverId
public void setReceiverId(long receiverId) -
getTransactionId
Returns the transaction id.- Returns:
- transaction id.
-
setTransactionId
Sets the transaction id. Called from theQueuePullTransaction
- Parameters:
transactionId
- transaction id.
-
getRegistrationTime
public long getRegistrationTime()Returns the registration time.- Returns:
- registration time.
-
setRegistrationTime
public void setRegistrationTime(long registrationTime) Sets a registration time. Internal use for timeout processing.- Parameters:
registrationTime
- registration time.
-
getRegistrationId
public int getRegistrationId()Returns the registration id.- Returns:
- registration id.
-
setRegistrationId
public void setRegistrationId(int registrationId) Sets a registration id. Internal use.- Parameters:
registrationId
- registration id.
-
getSelector
Returns the selector.- Returns:
- selector.
-
getViewId
public int getViewId()Returns the viewId.- Returns:
- view Id.
-
setViewId
public void setViewId(int viewId) Sets the view id. Internal use.- Parameters:
viewId
- registration time.
-
getTimeout
public long getTimeout()Returns the timeout.- Returns:
- timeout.
-
isAutoCommit
public boolean isAutoCommit()Returns whether the message should be auto committed- Returns:
- auto commit.
-
setAutoCommit
public void setAutoCommit(boolean autoCommit) Sets whether the message should be auto committed- Parameters:
autoCommit
- auto commit.
-
isBulkMode
public boolean isBulkMode()Returns whether this message processor runs in bulk mode- Returns:
- bulk mode
-
setBulkMode
protected void setBulkMode(boolean bulkMode) Sets whether this message processor runs in bulk mode- Parameters:
bulkMode
- bulk mode
-
createBulkBuffer
protected void createBulkBuffer(int bulkSize) Creates a new bulk buffer in the given size- Parameters:
bulkSize
- bulk size
-
getBulkBuffer
Returns the bulk buffer- Returns:
- bulk buffer
-
getMaxBulkSize
public long getMaxBulkSize()Returns the max bulk size- Returns:
- max bulk size
-
getCurrentBulkSize
public long getCurrentBulkSize()Returns the current bulk- Returns:
- current bulk size
-
setCurrentBulkSize
public void setCurrentBulkSize(long currentBulkSize) Sets the current bulk size- Parameters:
currentBulkSize
- current bulk size
-
processMessages
public void processMessages(int numberMessages) Process messages in bulk mode. Called when messages are available and the selector matches, if specified. The queue first obtains the bulk buffer withgetBulkBuffer()
and fills it with message entries up to the buffer size. It then calls this method and passes the actual number of messages in the buffer. Use this method to store the message and dispatch the MessageProcessor to a thread pool. Implement the processing itself inside therun()
method.- Parameters:
numberMessages
- number Messages in bulk buffer.
-
processMessage
Process a message. Called when a message is available and the selector matches, if specified. Use this method to store the message and dispatch the MessageProcessor to a thread pool. Implement the processing itself inside therun()
method.- Parameters:
messageEntry
- message entry.
-
processException
Process an exception. A timeout is indicated by aQueueTimeoutException
.- Parameters:
exception
- exception.- See Also:
-
getDispatchToken
Description copied from interface:AsyncTask
Returns the dispatch token of the task. The dispatch token is the thread name, used for thread assignment in the router's configuration file. It is used to determine the pool by invokingdispatchTask
of the ThreadpoolSwiftlet directly to determine the pool.- Specified by:
getDispatchToken
in interfaceAsyncTask
- Returns:
- dispatch token.
-
getDescription
Description copied from interface:AsyncTask
Returns a short description of this task. Used for trace outputs.- Specified by:
getDescription
in interfaceAsyncTask
- Returns:
- description.
-
stop
public void stop()Description copied from interface:AsyncTask
Stops this task. This method doesn't stop the task's execution. It is implementation dependent in which state the task will turn. In most cases, the task does some clean up and returns 'false' onisValid()
to avoid execution. -
reset
public void reset()Reset the MessageProcessor to its initial state without the need to recreate it. -
run
public void run()Description copied from interface:AsyncTask
Implements the task logic. This method will be called when a task is executed from a pool thread.
-