001    package com.mockrunner.mock.jms;
002    
003    import javax.jms.ConnectionConsumer;
004    import javax.jms.JMSException;
005    import javax.jms.ServerSessionPool;
006    
007    /**
008     * Mock implementation of JMS <code>ConnectionConsumer</code>.
009     */
010    public class MockConnectionConsumer implements ConnectionConsumer
011    {
012        private MockConnection connection;
013        private ServerSessionPool sessionPool;
014        private boolean closed;
015        
016        public MockConnectionConsumer(MockConnection connection, ServerSessionPool serverSessionPool)
017        {
018            this.connection = connection;
019            closed = false;
020            sessionPool = serverSessionPool;
021            if(null == sessionPool)
022            {
023                sessionPool = new MockServerSessionPool(connection);
024            }
025        }
026        
027        /**
028         * Returns if this connection consumer was closed.
029         * @return <code>true</code> if this connection consumer is closed
030         */
031        public boolean isClosed()
032        {
033            return closed;
034        }
035        
036        public void setServerSessionPool(ServerSessionPool serverSessionPool)
037        {
038            sessionPool = serverSessionPool;
039        }
040        
041        public ServerSessionPool getServerSessionPool() throws JMSException
042        {
043            connection.throwJMSException();
044            return sessionPool;
045        }
046    
047        public void close() throws JMSException
048        {
049            connection.throwJMSException();
050            closed = true;
051        }
052    }