Package dk.netarkivet.common.distribute
Class JMSConnectionMockupMQ
- java.lang.Object
-
- dk.netarkivet.common.distribute.JMSConnection
-
- dk.netarkivet.common.distribute.JMSConnectionMockupMQ
-
- All Implemented Interfaces:
CleanupIF
,javax.jms.ExceptionListener
public class JMSConnectionMockupMQ extends JMSConnection
A MockUp message queue, that generates a connection and destinations suitable for testing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JMSConnectionMockupMQ.CallOnMessageThread
protected static class
JMSConnectionMockupMQ.TestConnection
protected static class
JMSConnectionMockupMQ.TestConnectionFactory
protected static class
JMSConnectionMockupMQ.TestDestination
protected static class
JMSConnectionMockupMQ.TestMessageConsumer
protected static class
JMSConnectionMockupMQ.TestMessageProducer
static class
JMSConnectionMockupMQ.TestObjectMessage
protected static class
JMSConnectionMockupMQ.TestQueue
class
JMSConnectionMockupMQ.TestQueueBrowser
class
JMSConnectionMockupMQ.TestQueueReceiver
class
JMSConnectionMockupMQ.TestQueueSession
protected static class
JMSConnectionMockupMQ.TestSession
protected static class
JMSConnectionMockupMQ.TestTopic
-
Field Summary
Fields Modifier and Type Field Description protected Set<Thread>
concurrentTasksToComplete
A set of threads where onMessage has been called.protected Map<String,JMSConnectionMockupMQ.TestDestination>
destinations
A map from channelnames to destinations.-
Fields inherited from class dk.netarkivet.common.distribute.JMSConnection
closeHook, connection, connectionLock, CONSUMER_KEY_SEPARATOR, consumers, instance, listeners, producers, session
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JMSConnectionMockupMQ()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
Clean up singleton instance and internal statestatic void
clearTestQueues()
protected javax.jms.ConnectionFactory
getConnectionFactory()
Should be implemented according to a specific JMS broker.protected javax.jms.Destination
getDestination(String channelName)
Should be implemented according to a specific JMS broker.static JMSConnection
getInstance()
Get the singleton, and initialise it if it is new.List<javax.jms.MessageListener>
getListeners(ChannelID channel)
Returns a list of all MessageListeners listening to a particular channelstatic javax.jms.ObjectMessage
getObjectMessage(NetarkivetMessage nMsg)
Wrap a NetarkivetMessage into an ObjectMessagejavax.jms.QueueSession
getQueueSession()
Provides a QueueSession instance.protected void
initConnection()
Initializes the JMS connection.boolean
isSentToChannel(TestChecksumJob job, ChannelID channelID)
void
onException(javax.jms.JMSException e)
Does nothing.static void
updateMsgID(NetarkivetMessage msg, String id)
For testing purposes: Set the ID of a messagestatic void
useJMSConnectionMockupMQ()
void
waitForConcurrentTasksToFinish()
Waits until all threads where onMessage has been called have finished executing.-
Methods inherited from class dk.netarkivet.common.distribute.JMSConnection
createQueueBrowser, createQueueBrowser, getConsumerKey, reconnect, removeListener, reply, resend, send, sendMessage, setListener, unpack
-
-
-
-
Field Detail
-
concurrentTasksToComplete
protected final Set<Thread> concurrentTasksToComplete
A set of threads where onMessage has been called. This object is notified when all threads have finished executing.
-
destinations
protected Map<String,JMSConnectionMockupMQ.TestDestination> destinations
A map from channelnames to destinations.
-
-
Method Detail
-
getInstance
public static JMSConnection getInstance()
Get the singleton, and initialise it if it is new.- Returns:
- A JMSConnection
-
initConnection
protected void initConnection()
Description copied from class:JMSConnection
Initializes the JMS connection. Creates and starts connection and session. Adds a shutdown hook that closes down JMSConnection. Adds this object as ExceptionListener for the connection.- Overrides:
initConnection
in classJMSConnection
-
getConnectionFactory
protected javax.jms.ConnectionFactory getConnectionFactory() throws javax.jms.JMSException
Description copied from class:JMSConnection
Should be implemented according to a specific JMS broker.- Specified by:
getConnectionFactory
in classJMSConnection
- Returns:
- QueueConnectionFactory
- Throws:
javax.jms.JMSException
- If unable to get QueueConnectionFactory
-
getDestination
protected javax.jms.Destination getDestination(String channelName) throws javax.jms.JMSException
Description copied from class:JMSConnection
Should be implemented according to a specific JMS broker.- Specified by:
getDestination
in classJMSConnection
- Parameters:
channelName
- the name of the wanted Queue- Returns:
- The destination. Note that the implementation should make sure that this is a Queue or a Topic, as
required by the NetarchiveSuite design.
Channels.isTopic(String)
- Throws:
javax.jms.JMSException
- If unable to get a destination.
-
onException
public void onException(javax.jms.JMSException e)
Does nothing.- Specified by:
onException
in interfacejavax.jms.ExceptionListener
- Specified by:
onException
in classJMSConnection
- Parameters:
e
- The exception to ignore :-)
-
cleanup
public void cleanup()
Clean up singleton instance and internal state- Specified by:
cleanup
in interfaceCleanupIF
- Overrides:
cleanup
in classJMSConnection
-
waitForConcurrentTasksToFinish
public void waitForConcurrentTasksToFinish()
Waits until all threads where onMessage has been called have finished executing.
-
getObjectMessage
public static javax.jms.ObjectMessage getObjectMessage(NetarkivetMessage nMsg)
Wrap a NetarkivetMessage into an ObjectMessage- Parameters:
nMsg
- a NetarkivetMessage- Returns:
- an ObjectMessage
-
clearTestQueues
public static void clearTestQueues()
-
updateMsgID
public static void updateMsgID(NetarkivetMessage msg, String id)
For testing purposes: Set the ID of a message- Parameters:
msg
- The message to set the id onid
- the new id
-
useJMSConnectionMockupMQ
public static void useJMSConnectionMockupMQ()
-
getListeners
public List<javax.jms.MessageListener> getListeners(ChannelID channel)
Returns a list of all MessageListeners listening to a particular channel- Parameters:
channel
- The channel- Returns:
- list of listeners
-
isSentToChannel
public boolean isSentToChannel(TestChecksumJob job, ChannelID channelID)
-
getQueueSession
public javax.jms.QueueSession getQueueSession() throws javax.jms.JMSException
Description copied from class:JMSConnection
Provides a QueueSession instance. Functionality for retrieving aQueueSession
object isen't available on the genericJMSConnectionFactory
- Specified by:
getQueueSession
in classJMSConnection
- Returns:
- A
QueueSession
object connected to the current JMS broker - Throws:
javax.jms.JMSException
- Failure to retrieve theQueueBrowser
JMS Browser
-
-