@Test(timeout = 60000) public void testPooledSessionStatsTwoSessions() throws Exception { JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection(); assertEquals(0, connection.getNumActiveSessions()); Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); assertEquals(2, connection.getNumActiveSessions()); session1.close(); assertEquals(1, connection.getNumActiveSessions()); session2.close(); assertEquals(0, connection.getNumActiveSessions()); assertEquals(2, connection.getNumtIdleSessions()); assertEquals(2, connection.getNumSessions()); connection.close(); }
@Override public void close() throws JMSException { if (ignoreClose) { return; } if (closed.compareAndSet(false, true)) { boolean invalidate = false; try { getInternalSession().setMessageListener(null); for (MessageConsumer consumer : consumers) { consumer.close(); } for (QueueBrowser browser : browsers) { browser.close(); } for (MessageProducer producer : producers) { producer.close(); } consumers.clear(); producers.clear(); browsers.clear(); if (transactional && !isXa) { try { getInternalSession().rollback(); } catch (JMSException e) { invalidate = true; LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e); } } } catch (JMSException ex) { invalidate = true; LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex); } finally { consumers.clear(); browsers.clear(); for (JmsPoolSessionEventListener listener : this.sessionEventListeners) { listener.onSessionClosed(this); } sessionEventListeners.clear(); } if (invalidate) { if (sessionHolder != null) { try { sessionHolder.close(); } catch (JMSException e1) { LOG.trace("Ignoring exception on close as discarding session: " + e1, e1); } } try { sessionPool.invalidateObject(key, sessionHolder); } catch (Exception e) { LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e); } } else { try { sessionPool.returnObject(key, sessionHolder); } catch (Exception e) { javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString()); illegalStateException.initCause(e); throw illegalStateException; } } sessionHolder = null; } }
JmsPoolSession implements Session, TopicSession, QueueSession, XASession, AutoCloseable { @Override public void close() throws JMSException { if (ignoreClose) { return; } if (closed.compareAndSet(false, true)) { boolean invalidate = false; try { getInternalSession().setMessageListener(null); for (MessageConsumer consumer : consumers) { consumer.close(); } for (QueueBrowser browser : browsers) { browser.close(); } for (MessageProducer producer : producers) { producer.close(); } consumers.clear(); producers.clear(); browsers.clear(); if (transactional && !isXa) { try { getInternalSession().rollback(); } catch (JMSException e) { invalidate = true; LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e); } } } catch (JMSException ex) { invalidate = true; LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex); } finally { consumers.clear(); browsers.clear(); for (JmsPoolSessionEventListener listener : this.sessionEventListeners) { listener.onSessionClosed(this); } sessionEventListeners.clear(); } if (invalidate) { if (sessionHolder != null) { try { sessionHolder.close(); } catch (JMSException e1) { LOG.trace("Ignoring exception on close as discarding session: " + e1, e1); } } try { sessionPool.invalidateObject(key, sessionHolder); } catch (Exception e) { LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e); } } else { try { sessionPool.returnObject(key, sessionHolder); } catch (Exception e) { javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString()); illegalStateException.initCause(e); throw illegalStateException; } } sessionHolder = null; } } }
JmsPoolSession implements Session, TopicSession, QueueSession, XASession, AutoCloseable { @Override public void close() throws JMSException { if (ignoreClose) { return; } if (closed.compareAndSet(false, true)) { boolean invalidate = false; try { getInternalSession().setMessageListener(null); for (MessageConsumer consumer : consumers) { consumer.close(); } for (QueueBrowser browser : browsers) { browser.close(); } for (MessageProducer producer : producers) { producer.close(); } consumers.clear(); producers.clear(); browsers.clear(); if (transactional && !isXa) { try { getInternalSession().rollback(); } catch (JMSException e) { invalidate = true; LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e); } } } catch (JMSException ex) { invalidate = true; LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex); } finally { consumers.clear(); browsers.clear(); for (JmsPoolSessionEventListener listener : this.sessionEventListeners) { listener.onSessionClosed(this); } sessionEventListeners.clear(); } if (invalidate) { if (sessionHolder != null) { try { sessionHolder.close(); } catch (JMSException e1) { LOG.trace("Ignoring exception on close as discarding session: " + e1, e1); } } try { sessionPool.invalidateObject(key, sessionHolder); } catch (Exception e) { LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e); } } else { try { sessionPool.returnObject(key, sessionHolder); } catch (Exception e) { javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString()); illegalStateException.initCause(e); throw illegalStateException; } } sessionHolder = null; } } JmsPoolSession(PooledSessionKey key, PooledSessionHolder sessionHolder, KeyedObjectPool<PooledSessionKey, PooledSessionHolder> sessionPool, boolean transactional); }
JmsPoolSession implements Session, TopicSession, QueueSession, XASession, AutoCloseable { @Override public void close() throws JMSException { if (ignoreClose) { return; } if (closed.compareAndSet(false, true)) { boolean invalidate = false; try { getInternalSession().setMessageListener(null); for (MessageConsumer consumer : consumers) { consumer.close(); } for (QueueBrowser browser : browsers) { browser.close(); } for (MessageProducer producer : producers) { producer.close(); } consumers.clear(); producers.clear(); browsers.clear(); if (transactional && !isXa) { try { getInternalSession().rollback(); } catch (JMSException e) { invalidate = true; LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e); } } } catch (JMSException ex) { invalidate = true; LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex); } finally { consumers.clear(); browsers.clear(); for (JmsPoolSessionEventListener listener : this.sessionEventListeners) { listener.onSessionClosed(this); } sessionEventListeners.clear(); } if (invalidate) { if (sessionHolder != null) { try { sessionHolder.close(); } catch (JMSException e1) { LOG.trace("Ignoring exception on close as discarding session: " + e1, e1); } } try { sessionPool.invalidateObject(key, sessionHolder); } catch (Exception e) { LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e); } } else { try { sessionPool.returnObject(key, sessionHolder); } catch (Exception e) { javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString()); illegalStateException.initCause(e); throw illegalStateException; } } sessionHolder = null; } } JmsPoolSession(PooledSessionKey key, PooledSessionHolder sessionHolder, KeyedObjectPool<PooledSessionKey, PooledSessionHolder> sessionPool, boolean transactional); @Override void close(); @Override TemporaryQueue createTemporaryQueue(); @Override TemporaryTopic createTemporaryTopic(); @Override Queue createQueue(String s); @Override Topic createTopic(String s); @Override BytesMessage createBytesMessage(); @Override MapMessage createMapMessage(); @Override Message createMessage(); @Override ObjectMessage createObjectMessage(); @Override ObjectMessage createObjectMessage(Serializable serializable); @Override StreamMessage createStreamMessage(); @Override TextMessage createTextMessage(); @Override TextMessage createTextMessage(String s); @Override void unsubscribe(String s); @Override int getAcknowledgeMode(); @Override boolean getTransacted(); @Override void recover(); @Override void commit(); @Override void rollback(); @Override XAResource getXAResource(); @Override Session getSession(); @Override MessageListener getMessageListener(); @Override void setMessageListener(MessageListener messageListener); @Override void run(); @Override QueueBrowser createBrowser(Queue queue); @Override QueueBrowser createBrowser(Queue queue, String selector); @Override MessageConsumer createConsumer(Destination destination); @Override MessageConsumer createConsumer(Destination destination, String selector); @Override MessageConsumer createConsumer(Destination destination, String selector, boolean noLocal); @Override TopicSubscriber createDurableSubscriber(Topic topic, String selector); @Override TopicSubscriber createDurableSubscriber(Topic topic, String name, String selector, boolean noLocal); @Override TopicSubscriber createSubscriber(Topic topic); @Override TopicSubscriber createSubscriber(Topic topic, String selector, boolean local); @Override QueueReceiver createReceiver(Queue queue); @Override QueueReceiver createReceiver(Queue queue, String selector); @Override MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName); @Override MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector); @Override MessageConsumer createDurableConsumer(Topic topic, String name); @Override MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal); @Override MessageConsumer createSharedDurableConsumer(Topic topic, String name); @Override MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector); @Override MessageProducer createProducer(Destination destination); @Override QueueSender createSender(Queue queue); @Override TopicPublisher createPublisher(Topic topic); void addSessionEventListener(JmsPoolSessionEventListener listener); Session getInternalSession(); void setIsXa(boolean isXa); boolean isIgnoreClose(); void setIgnoreClose(boolean ignoreClose); @Override String toString(); }
JmsPoolSession implements Session, TopicSession, QueueSession, XASession, AutoCloseable { @Override public void close() throws JMSException { if (ignoreClose) { return; } if (closed.compareAndSet(false, true)) { boolean invalidate = false; try { getInternalSession().setMessageListener(null); for (MessageConsumer consumer : consumers) { consumer.close(); } for (QueueBrowser browser : browsers) { browser.close(); } for (MessageProducer producer : producers) { producer.close(); } consumers.clear(); producers.clear(); browsers.clear(); if (transactional && !isXa) { try { getInternalSession().rollback(); } catch (JMSException e) { invalidate = true; LOG.warn("Caught exception trying rollback() when putting session back into the pool, will invalidate. " + e, e); } } } catch (JMSException ex) { invalidate = true; LOG.warn("Caught exception trying close() when putting session back into the pool, will invalidate. " + ex, ex); } finally { consumers.clear(); browsers.clear(); for (JmsPoolSessionEventListener listener : this.sessionEventListeners) { listener.onSessionClosed(this); } sessionEventListeners.clear(); } if (invalidate) { if (sessionHolder != null) { try { sessionHolder.close(); } catch (JMSException e1) { LOG.trace("Ignoring exception on close as discarding session: " + e1, e1); } } try { sessionPool.invalidateObject(key, sessionHolder); } catch (Exception e) { LOG.trace("Ignoring exception on invalidateObject as discarding session: " + e, e); } } else { try { sessionPool.returnObject(key, sessionHolder); } catch (Exception e) { javax.jms.IllegalStateException illegalStateException = new javax.jms.IllegalStateException(e.toString()); illegalStateException.initCause(e); throw illegalStateException; } } sessionHolder = null; } } JmsPoolSession(PooledSessionKey key, PooledSessionHolder sessionHolder, KeyedObjectPool<PooledSessionKey, PooledSessionHolder> sessionPool, boolean transactional); @Override void close(); @Override TemporaryQueue createTemporaryQueue(); @Override TemporaryTopic createTemporaryTopic(); @Override Queue createQueue(String s); @Override Topic createTopic(String s); @Override BytesMessage createBytesMessage(); @Override MapMessage createMapMessage(); @Override Message createMessage(); @Override ObjectMessage createObjectMessage(); @Override ObjectMessage createObjectMessage(Serializable serializable); @Override StreamMessage createStreamMessage(); @Override TextMessage createTextMessage(); @Override TextMessage createTextMessage(String s); @Override void unsubscribe(String s); @Override int getAcknowledgeMode(); @Override boolean getTransacted(); @Override void recover(); @Override void commit(); @Override void rollback(); @Override XAResource getXAResource(); @Override Session getSession(); @Override MessageListener getMessageListener(); @Override void setMessageListener(MessageListener messageListener); @Override void run(); @Override QueueBrowser createBrowser(Queue queue); @Override QueueBrowser createBrowser(Queue queue, String selector); @Override MessageConsumer createConsumer(Destination destination); @Override MessageConsumer createConsumer(Destination destination, String selector); @Override MessageConsumer createConsumer(Destination destination, String selector, boolean noLocal); @Override TopicSubscriber createDurableSubscriber(Topic topic, String selector); @Override TopicSubscriber createDurableSubscriber(Topic topic, String name, String selector, boolean noLocal); @Override TopicSubscriber createSubscriber(Topic topic); @Override TopicSubscriber createSubscriber(Topic topic, String selector, boolean local); @Override QueueReceiver createReceiver(Queue queue); @Override QueueReceiver createReceiver(Queue queue, String selector); @Override MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName); @Override MessageConsumer createSharedConsumer(Topic topic, String sharedSubscriptionName, String messageSelector); @Override MessageConsumer createDurableConsumer(Topic topic, String name); @Override MessageConsumer createDurableConsumer(Topic topic, String name, String messageSelector, boolean noLocal); @Override MessageConsumer createSharedDurableConsumer(Topic topic, String name); @Override MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector); @Override MessageProducer createProducer(Destination destination); @Override QueueSender createSender(Queue queue); @Override TopicPublisher createPublisher(Topic topic); void addSessionEventListener(JmsPoolSessionEventListener listener); Session getInternalSession(); void setIsXa(boolean isXa); boolean isIgnoreClose(); void setIgnoreClose(boolean ignoreClose); @Override String toString();  }