public class MockSession extends Object implements javax.jms.Session, Serializable
Session.
Please note that this implementation does not
implement transaction isolation at the moment.
Messages are immediately sent. If acknowledge
mode is AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE,
the message will be automatically acknowledged,
otherwise, it will not be acknowledged. According
to JMS specification, the acknowledged mode must
be ignored for transacted sessions. This is currently
not implemented, i.e. transacted sessions behave like
sessions with acknowledge mode AUTO_ACKNOWLEDGE.
Messages are acknowledged even if the transaction is
rolled back. However, the framework keeps track if a
transaction is committed or rolled back, so you can test
this and rely on the container for the rest.
You can set a MessageListener directly to
the session. This is an application server internal feature
and not meant for application use in JMS.
This mock session dispatches any message of any
known Queue and Topic to the
distinguished MessageListener, if such
a MessageListener is registered.| Constructor and Description |
|---|
MockSession(MockConnection connection,
boolean transacted,
int acknowledgeMode) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSessionToQueue(javax.jms.Queue queue) |
void |
addSessionToTopic(javax.jms.Topic topic) |
void |
close() |
void |
commit() |
javax.jms.QueueBrowser |
createBrowser(javax.jms.Queue queue) |
javax.jms.QueueBrowser |
createBrowser(javax.jms.Queue queue,
String messageSelector) |
javax.jms.BytesMessage |
createBytesMessage() |
javax.jms.MessageConsumer |
createConsumer(javax.jms.Destination destination) |
javax.jms.MessageConsumer |
createConsumer(javax.jms.Destination destination,
String messageSelector) |
javax.jms.MessageConsumer |
createConsumer(javax.jms.Destination destination,
String messageSelector,
boolean noLocal) |
javax.jms.TopicSubscriber |
createDurableSubscriber(javax.jms.Topic topic,
String name) |
javax.jms.TopicSubscriber |
createDurableSubscriber(javax.jms.Topic topic,
String name,
String messageSelector,
boolean noLocal) |
javax.jms.MapMessage |
createMapMessage() |
javax.jms.Message |
createMessage() |
javax.jms.ObjectMessage |
createObjectMessage() |
javax.jms.ObjectMessage |
createObjectMessage(Serializable object) |
javax.jms.MessageProducer |
createProducer(javax.jms.Destination destination) |
protected javax.jms.MessageProducer |
createProducerForNullDestination() |
javax.jms.Queue |
createQueue(String name) |
javax.jms.StreamMessage |
createStreamMessage() |
javax.jms.TemporaryQueue |
createTemporaryQueue() |
javax.jms.TemporaryTopic |
createTemporaryTopic() |
javax.jms.TextMessage |
createTextMessage() |
javax.jms.TextMessage |
createTextMessage(String text) |
javax.jms.Topic |
createTopic(String name) |
int |
getAcknowledgeMode()
Note: Returns
0 if the session is transacted. |
protected MockConnection |
getConnection() |
GenericTransmissionManager |
getGenericTransmissionManager()
Returns the
GenericTransmissionManager. |
javax.jms.MessageListener |
getMessageListener() |
MessageManager |
getMessageManager()
Returns the
MessageManager for this session. |
int |
getNumberCommits()
Returns the number of commits.
|
int |
getNumberRollbacks()
Returns the number of rollbacks.
|
QueueTransmissionManager |
getQueueTransmissionManager()
Returns the
QueueTransmissionManager. |
MockTemporaryQueue |
getTemporaryQueue(int index)
Returns a
TemporaryQueue by its index. |
List |
getTemporaryQueueList()
Returns the list of temporary queues.
|
MockTemporaryTopic |
getTemporaryTopic(int index)
Returns a
TemporaryTopic by its index. |
List |
getTemporaryTopicList()
Returns the list of temporary topics.
|
TopicTransmissionManager |
getTopicTransmissionManager()
Returns the
TopicTransmissionManager. |
boolean |
getTransacted() |
TransmissionManagerWrapper |
getTransmissionManager()
Deprecated.
|
TransmissionManagerWrapper |
getTransmissionManagerWrapper()
Returns the
TransmissionManagerWrapper. |
boolean |
isAutoAcknowledge()
Returns if messages should be automatically acknowledged,
i.e.
|
boolean |
isClosed()
Returns if this session was closed.
|
boolean |
isCommitted()
Returns if the current transaction was committed.
|
boolean |
isRecovered()
Returns if this session was recovered.
|
boolean |
isRolledBack()
Returns if the current transaction was rolled back.
|
void |
recover() |
void |
rollback() |
void |
run() |
void |
setMessageListener(javax.jms.MessageListener messageListener) |
void |
unsubscribe(String name) |
public MockSession(MockConnection connection, boolean transacted, int acknowledgeMode)
public QueueTransmissionManager getQueueTransmissionManager()
QueueTransmissionManager.QueueTransmissionManagerpublic TopicTransmissionManager getTopicTransmissionManager()
TopicTransmissionManager.TopicTransmissionManagerpublic GenericTransmissionManager getGenericTransmissionManager()
GenericTransmissionManager.GenericTransmissionManagerpublic TransmissionManagerWrapper getTransmissionManager()
getTransmissionManagerWrapper()public TransmissionManagerWrapper getTransmissionManagerWrapper()
TransmissionManagerWrapper.TransmissionManagerWrapperpublic MessageManager getMessageManager()
MessageManager for this session.MessageManagerpublic List getTemporaryQueueList()
TemporaryQueue listpublic MockTemporaryQueue getTemporaryQueue(int index)
TemporaryQueue by its index. The
index represent the number of the queue. Returns null
if no such TemporaryQueue is present.index - the indexTemporaryQueuepublic List getTemporaryTopicList()
TemporaryTopic listpublic MockTemporaryTopic getTemporaryTopic(int index)
TemporaryTopic by its index. The
index represent the number of the topic. Returns null
if no such TemporaryTopic is present.index - the indexTemporaryTopicpublic boolean isClosed()
true if this session is closedpublic boolean isRecovered()
true if this session was recoveredpublic boolean isCommitted()
true if the transaction was committedpublic int getNumberCommits()
public boolean isRolledBack()
true if the transaction was rolled backpublic int getNumberRollbacks()
public boolean isAutoAcknowledge()
CLIENT_ACKNOWLEDGE.true if messages are automatically acknowledgedpublic int getAcknowledgeMode()
throws javax.jms.JMSException
0 if the session is transacted.
This method does not exist in JMS 1.0.2. In JMS 1.1 it
should return Session.SESSION_TRANSACTED
which is specified as 0. In order to avoid
different versions for JMS 1.0.2 and 1.1
(Session.SESSION_TRANSACTED does not
exist in 1.0.2) this method returns hardcoded 0,
if the session is transacted.getAcknowledgeMode in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic boolean getTransacted()
throws javax.jms.JMSException
getTransacted in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.BytesMessage createBytesMessage()
throws javax.jms.JMSException
createBytesMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MapMessage createMapMessage()
throws javax.jms.JMSException
createMapMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.Message createMessage()
throws javax.jms.JMSException
createMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.ObjectMessage createObjectMessage()
throws javax.jms.JMSException
createObjectMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.ObjectMessage createObjectMessage(Serializable object) throws javax.jms.JMSException
createObjectMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.StreamMessage createStreamMessage()
throws javax.jms.JMSException
createStreamMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TextMessage createTextMessage()
throws javax.jms.JMSException
createTextMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TextMessage createTextMessage(String text) throws javax.jms.JMSException
createTextMessage in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MessageListener getMessageListener()
throws javax.jms.JMSException
getMessageListener in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void setMessageListener(javax.jms.MessageListener messageListener)
throws javax.jms.JMSException
setMessageListener in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void run()
public void commit()
throws javax.jms.JMSException
commit in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void rollback()
throws javax.jms.JMSException
rollback in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void close()
throws javax.jms.JMSException
close in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void recover()
throws javax.jms.JMSException
recover in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic void unsubscribe(String name) throws javax.jms.JMSException
unsubscribe in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.Queue createQueue(String name) throws javax.jms.JMSException
createQueue in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TemporaryQueue createTemporaryQueue()
throws javax.jms.JMSException
createTemporaryQueue in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.Topic createTopic(String name) throws javax.jms.JMSException
createTopic in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TemporaryTopic createTemporaryTopic()
throws javax.jms.JMSException
createTemporaryTopic in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination)
throws javax.jms.JMSException
createConsumer in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination,
String messageSelector)
throws javax.jms.JMSException
createConsumer in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MessageConsumer createConsumer(javax.jms.Destination destination,
String messageSelector,
boolean noLocal)
throws javax.jms.JMSException
createConsumer in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.MessageProducer createProducer(javax.jms.Destination destination)
throws javax.jms.JMSException
createProducer in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue)
throws javax.jms.JMSException
createBrowser in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.QueueBrowser createBrowser(javax.jms.Queue queue,
String messageSelector)
throws javax.jms.JMSException
createBrowser in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic,
String name)
throws javax.jms.JMSException
createDurableSubscriber in interface javax.jms.Sessionjavax.jms.JMSExceptionpublic javax.jms.TopicSubscriber createDurableSubscriber(javax.jms.Topic topic,
String name,
String messageSelector,
boolean noLocal)
throws javax.jms.JMSException
createDurableSubscriber in interface javax.jms.Sessionjavax.jms.JMSExceptionprotected MockConnection getConnection()
public void addSessionToQueue(javax.jms.Queue queue)
public void addSessionToTopic(javax.jms.Topic topic)
protected javax.jms.MessageProducer createProducerForNullDestination()
Copyright © 2003–2020. All rights reserved.