Class 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.
    • 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.
    • Constructor Detail

      • JMSConnectionMockupMQ

        protected JMSConnectionMockupMQ()
        Constructor. Does nothing, initConnection is used for setup.
    • 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 class JMSConnection
      • 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 class JMSConnection
        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 class JMSConnection
        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 interface javax.jms.ExceptionListener
        Specified by:
        onException in class JMSConnection
        Parameters:
        e - The exception to ignore :-)
      • 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 on
        id - 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
      • getQueueSession

        public javax.jms.QueueSession getQueueSession()
                                               throws javax.jms.JMSException
        Description copied from class: JMSConnection
        Provides a QueueSession instance. Functionality for retrieving a QueueSession object isen't available on the generic JMSConnectionFactory
        Specified by:
        getQueueSession in class JMSConnection
        Returns:
        A QueueSession object connected to the current JMS broker
        Throws:
        javax.jms.JMSException - Failure to retrieve the QueueBrowser JMS Browser