Class WmClusterMessageConsumerImpl
- java.lang.Object
-
- com.webmethods.locks.Node
-
- com.webmethods.jms.impl.WmMessageConsumerImpl
-
- com.webmethods.jms.loadbalance.connection.WmClusterMessageConsumerImpl
-
- All Implemented Interfaces:
ReplyCb
,WmMessageConsumer
,javax.jms.MessageConsumer
- Direct Known Subclasses:
WmClusterQueueReceiverImpl
,WmClusterTopicSubscriberImpl
,WmClusterXAMessageConsumerImpl
,WmCompositeMessageConsumerImpl
public class WmClusterMessageConsumerImpl extends WmMessageConsumerImpl
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Set<WmSessionImpl>
_activeSessions
protected WmClusterConnectionImpl
_clusterConn
protected java.util.List<WmMessageConsumerImpl>
_consumers
protected WmConnectionFactoryImpl
_factory
protected java.util.concurrent.LinkedBlockingQueue<WmMessageImpl>
sharedQueue
protected java.util.concurrent.locks.ReentrantReadWriteLock
sharedReadWriteLock
-
Fields inherited from class com.webmethods.jms.impl.WmMessageConsumerImpl
_closed, _destination, _durableName, _filter, _logApi, _maxReceive, _messageListener, _messageQueue, _noLocal, _protocolHandler, _selector, _session, _sessionID, _suspendedTransactions
-
Fields inherited from class com.webmethods.locks.Node
_lockManager
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
WmClusterMessageConsumerImpl(WmSessionImpl session)
Default constructor called by subclasses.protected
WmClusterMessageConsumerImpl(WmSessionImpl session, WmDestinationImpl destination, java.lang.String selector, boolean noLocal)
protected
WmClusterMessageConsumerImpl(WmSessionImpl session, WmDestinationImpl destination, java.lang.String durableName, java.lang.String selector, boolean noLocal)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
acknowledge()
Acknowledge all messages in the acknowledge list.void
addActiveConsumerSession(WmSessionImpl session)
long
available()
Gets the number of messages on the Brokers available to the consumer.void
cancelRequestEvents()
Cancel the pending request for events.protected void
checkState()
protected void
checkSynchronous()
void
clear()
Clears all available messages to this cluster consumer from the Brokers.void
clearActiveConsumerSessions()
void
close()
Closes this cluster message consumer.void
commit(WmMessageImpl message)
Commits a transaction under which the message is received.javax.jms.MessageConsumer
createConsumer(WmSessionImpl oneSession)
Populates a consumer in each of the cluster's physical session.java.util.Set<WmSessionImpl>
getActiveConsumerSessions()
java.util.List<WmMessageConsumerImpl>
getConsumers()
javax.jms.MessageListener
getMessageListener()
Gets the cluster message consumer'sMessageListener
.java.util.Set<WmSessionImpl>
getTransactedSessions()
void
logClusterConsumers()
void
messageAcknowledge(WmMessageImpl message, boolean isUUIDPresent)
Acknowledges the message based upon the cluster session's acknowledgement mode for all the consumers.javax.jms.Message
receive()
Receives the next message produced for this message consumer.javax.jms.Message
receive(long timeout)
Receives the next message that arrives within the specified timeout interval.javax.jms.Message
receiveNoWait()
Receives the next message if one is immediately available.void
requestEvents(int max, boolean synchronous)
Issue a request for events to the Broker.void
requestEvents(java.lang.String[] brokerURLs, int max, boolean synchronous)
Deprecated.It will be used only if we support dynamic new Broker addition to connection, right now we just close and create new connectionvoid
setActiveConsumerSessions(java.util.Set<WmSessionImpl> sessions)
void
setMessageListener(javax.jms.MessageListener listener)
Sets the cluster message consumer'sMessageListener
.void
setMessageListener(javax.jms.MessageListener listener, boolean setonSession, WmSessionQueue queue)
void
setMessageQueue(WmConsumerQueue queue)
Added to change the implementation of the WmConsumerQueue to the WmConsumerQueueImpl in case of cluster consumersvoid
setTransactionID(long transactionID)
Set the current transaction ID.void
start()
Starts synchronous message delivery.void
startLocalTransaction()
Starts a local transaction.void
startLocalTransaction(java.lang.String[] brokerURLs)
Starts a local transaction.void
stop()
Stops synchronous message delivery.java.lang.String
toString()
-
Methods inherited from class com.webmethods.jms.impl.WmMessageConsumerImpl
addToPreAckList, autoAcknowledge, availableOnServer, clientAcknowledge, close, commit, createFilter, deliver, dupsOkAcknowledge, getClientAcknowledgeList, getDestination, getDurableName, getInputStream, getMaxReceive, getMessageQueue, getMessageSelector, getSession, getTransactionAckCount, isNoLocal, onMessage, onMessage, onReply, preAckClientList, preAcknowledge, removeMessage, removeMessageNoWait, removeMessageWithWait, requestEvents, requestEvents, rollback, setFilter, setMaxReceive, setTransactionID, setTransactionTimeout, stopAutoAcknowledger, transactedAcknowledge, transactionComplete
-
Methods inherited from class com.webmethods.locks.Node
getLockManager, getParent
-
-
-
-
Field Detail
-
_consumers
protected java.util.List<WmMessageConsumerImpl> _consumers
-
_activeSessions
protected java.util.Set<WmSessionImpl> _activeSessions
-
_clusterConn
protected WmClusterConnectionImpl _clusterConn
-
_factory
protected WmConnectionFactoryImpl _factory
-
sharedQueue
protected java.util.concurrent.LinkedBlockingQueue<WmMessageImpl> sharedQueue
-
sharedReadWriteLock
protected java.util.concurrent.locks.ReentrantReadWriteLock sharedReadWriteLock
-
-
Constructor Detail
-
WmClusterMessageConsumerImpl
protected WmClusterMessageConsumerImpl(WmSessionImpl session, WmDestinationImpl destination, java.lang.String selector, boolean noLocal) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
WmClusterMessageConsumerImpl
protected WmClusterMessageConsumerImpl(WmSessionImpl session, WmDestinationImpl destination, java.lang.String durableName, java.lang.String selector, boolean noLocal) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
WmClusterMessageConsumerImpl
protected WmClusterMessageConsumerImpl(WmSessionImpl session)
Default constructor called by subclasses.
-
-
Method Detail
-
start
public void start() throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Starts synchronous message delivery. Called byWmSessionImpl.start()
.- Overrides:
start
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
stop
public void stop() throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Stops synchronous message delivery. Called byWmSessionImpl.stop()
.- Overrides:
stop
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
createConsumer
public javax.jms.MessageConsumer createConsumer(WmSessionImpl oneSession) throws javax.jms.JMSException
Populates a consumer in each of the cluster's physical session.- Throws:
javax.jms.JMSException
-
receive
public javax.jms.Message receive() throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Receives the next message produced for this message consumer.This call blocks indefinitely until a message is produced or until this message consumer is closed.
If this
receive
is done within a transaction, the consumer retains the message until the transaction commits.- Specified by:
receive
in interfacejavax.jms.MessageConsumer
- Overrides:
receive
in classWmMessageConsumerImpl
- Returns:
- the next message produced for this message consumer, or null if this message consumer is concurrently closed
- Throws:
javax.jms.JMSException
- if the JMS provider fails to receive the next message due to some internal error.
-
receive
public javax.jms.Message receive(long timeout) throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Receives the next message that arrives within the specified timeout interval.This call blocks until a message arrives, the timeout expires, or this message consumer is closed. A
timeout
of zero never expires, and the call blocks indefinitely.- Specified by:
receive
in interfacejavax.jms.MessageConsumer
- Overrides:
receive
in classWmMessageConsumerImpl
- Parameters:
timeout
- the timeout value (in milliseconds)- Returns:
- the next message produced for this message consumer, or null if the timeout expires or this message consumer is concurrently closed
- Throws:
javax.jms.JMSException
- if the JMS provider fails to receive the next message due to some internal error.
-
receiveNoWait
public javax.jms.Message receiveNoWait() throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Receives the next message if one is immediately available.- Specified by:
receiveNoWait
in interfacejavax.jms.MessageConsumer
- Overrides:
receiveNoWait
in classWmMessageConsumerImpl
- Returns:
- the next message produced for this message consumer, or null if one is not available
- Throws:
javax.jms.JMSException
- if the JMS provider fails to receive the next message due to some internal error.
-
messageAcknowledge
public void messageAcknowledge(WmMessageImpl message, boolean isUUIDPresent) throws javax.jms.JMSException
Acknowledges the message based upon the cluster session's acknowledgement mode for all the consumers.- Parameters:
message
- the message to acknowledge- Throws:
javax.jms.JMSException
-
requestEvents
public void requestEvents(int max, boolean synchronous) throws javax.jms.JMSException
Issue a request for events to the Broker.- Overrides:
requestEvents
in classWmMessageConsumerImpl
- Parameters:
max
- maximum number of messages to receive from the Broker acknowledge mode, or -1 to acknowledge nothing- Throws:
javax.jms.JMSException
- if the request could not be sent
-
requestEvents
@Deprecated public void requestEvents(java.lang.String[] brokerURLs, int max, boolean synchronous) throws javax.jms.JMSException
Deprecated.It will be used only if we support dynamic new Broker addition to connection, right now we just close and create new connectionIssue a request for events to the Broker.- Parameters:
max
- maximum number of messages to receive from the Broker acknowledge mode, or -1 to acknowledge nothing- Throws:
javax.jms.JMSException
- if the request could not be sent
-
cancelRequestEvents
public void cancelRequestEvents() throws javax.jms.JMSException
Cancel the pending request for events.- Overrides:
cancelRequestEvents
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
- if the pending request cannot be canceled
-
getActiveConsumerSessions
public java.util.Set<WmSessionImpl> getActiveConsumerSessions()
-
setActiveConsumerSessions
public void setActiveConsumerSessions(java.util.Set<WmSessionImpl> sessions)
-
addActiveConsumerSession
public void addActiveConsumerSession(WmSessionImpl session)
-
clearActiveConsumerSessions
public void clearActiveConsumerSessions()
-
getConsumers
public java.util.List<WmMessageConsumerImpl> getConsumers()
-
getMessageListener
public javax.jms.MessageListener getMessageListener() throws javax.jms.JMSException
Gets the cluster message consumer'sMessageListener
.- Specified by:
getMessageListener
in interfacejavax.jms.MessageConsumer
- Overrides:
getMessageListener
in classWmMessageConsumerImpl
- Returns:
- the listener for the message consumer, or null if no listener is set
- Throws:
javax.jms.JMSException
- if the JMS provider fails to get the message listener due to some internal error.- See Also:
MessageConsumer.setMessageListener(javax.jms.MessageListener)
-
setMessageListener
public void setMessageListener(javax.jms.MessageListener listener) throws javax.jms.JMSException
Sets the cluster message consumer'sMessageListener
.Setting the message listener to null is the equivalent of unsetting the message listener for the message consumer.
The effect of calling
MessageConsumer.setMessageListener
while messages are being consumed by an existing listener or the consumer is being used to consume messages synchronously is undefined.- Specified by:
setMessageListener
in interfacejavax.jms.MessageConsumer
- Overrides:
setMessageListener
in classWmMessageConsumerImpl
- Parameters:
listener
- the listener to which the messages are to be delivered- Throws:
javax.jms.JMSException
- if the JMS provider fails to set the message listener due to some internal error.
-
setMessageListener
public void setMessageListener(javax.jms.MessageListener listener, boolean setonSession, WmSessionQueue queue)
- Overrides:
setMessageListener
in classWmMessageConsumerImpl
-
close
public void close() throws javax.jms.JMSException
Closes this cluster message consumer.- Specified by:
close
in interfacejavax.jms.MessageConsumer
- Specified by:
close
in interfaceWmMessageConsumer
- Overrides:
close
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
- if the JMS provider fails to close the consumer due to some internal error.
-
clear
public void clear() throws javax.jms.JMSException
Clears all available messages to this cluster consumer from the Brokers.- Specified by:
clear
in interfaceWmMessageConsumer
- Overrides:
clear
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
- if the JMS provider fails to clear the consumer's messages.
-
available
public long available() throws javax.jms.JMSException
Gets the number of messages on the Brokers available to the consumer. This is an approximate number in that some of the messages may be expired or don't match the consumer's message selector or are already pre-acknowledged.- Specified by:
available
in interfaceWmMessageConsumer
- Overrides:
available
in classWmMessageConsumerImpl
- Returns:
- the number of messages available to the consumer
- Throws:
javax.jms.JMSException
- if the JMS provider fails to get the number of available messages.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classWmMessageConsumerImpl
-
acknowledge
public void acknowledge() throws javax.jms.JMSException
Description copied from class:WmMessageConsumerImpl
Acknowledge all messages in the acknowledge list.- Overrides:
acknowledge
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
commit
public void commit(WmMessageImpl message) throws javax.jms.JMSException
Commits a transaction under which the message is received.- Overrides:
commit
in classWmMessageConsumerImpl
- Parameters:
message
-- Throws:
javax.jms.JMSException
-
startLocalTransaction
public void startLocalTransaction() throws javax.jms.JMSException
Starts a local transaction.- Overrides:
startLocalTransaction
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
startLocalTransaction
public void startLocalTransaction(java.lang.String[] brokerURLs) throws javax.jms.JMSException
Starts a local transaction. This method will start the transaction only on the broker URLs which have been specified through the parameters.- Throws:
javax.jms.JMSException
-
setTransactionID
public void setTransactionID(long transactionID) throws javax.jms.JMSException
Set the current transaction ID.- Overrides:
setTransactionID
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
checkState
protected void checkState() throws javax.jms.JMSException
- Overrides:
checkState
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
checkSynchronous
protected void checkSynchronous() throws javax.jms.JMSException
- Overrides:
checkSynchronous
in classWmMessageConsumerImpl
- Throws:
javax.jms.JMSException
-
getTransactedSessions
public java.util.Set<WmSessionImpl> getTransactedSessions()
-
setMessageQueue
public void setMessageQueue(WmConsumerQueue queue)
Added to change the implementation of the WmConsumerQueue to the WmConsumerQueueImpl in case of cluster consumers- Overrides:
setMessageQueue
in classWmMessageConsumerImpl
- Parameters:
queue
-
-
logClusterConsumers
public void logClusterConsumers()
-
-