git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1152747 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2011-08-01 11:46:50 +00:00
parent 70997eeaf9
commit be37064a17
2 changed files with 21 additions and 3 deletions

View File

@ -723,6 +723,15 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
}
}
/**
* Checks if the session is closed.
*
* @return true if the session is closed, false otherwise.
*/
public boolean isClosed() {
return closed;
}
/**
* Stops message delivery in this session, and restarts message delivery
* with the oldest unacknowledged message.

View File

@ -23,13 +23,17 @@ import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Session;
import org.apache.activemq.ActiveMQSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A simple pool of JMS Session objects intended for use by Queue browsers.
*
*
*/
public class SessionPool {
private static final Logger LOG = LoggerFactory.getLogger(SessionPool.class);
private ConnectionFactory connectionFactory;
private Connection connection;
private LinkedList<Session> sessions = new LinkedList<Session>();
@ -78,8 +82,10 @@ public class SessionPool {
Session answer = null;
synchronized (sessions) {
if (sessions.isEmpty()) {
LOG.trace("Creating a new session.");
answer = createSession();
} else {
LOG.trace("Serving session from the pool.");
answer = sessions.removeLast();
}
}
@ -87,10 +93,13 @@ public class SessionPool {
}
public void returnSession(Session session) {
if (session != null) {
if (session != null && !((ActiveMQSession) session).isClosed()) {
synchronized (sessions) {
LOG.trace("Returning session to the pool.");
sessions.add(session);
}
} else {
LOG.debug("Session closed or null, not returning to the pool.");
}
}