mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3430 - activemq web - session pool
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1152747 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
70997eeaf9
commit
be37064a17
|
@ -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
|
* Stops message delivery in this session, and restarts message delivery
|
||||||
* with the oldest unacknowledged message.
|
* with the oldest unacknowledged message.
|
||||||
|
|
|
@ -23,13 +23,17 @@ import javax.jms.ConnectionFactory;
|
||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.Session;
|
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.
|
* A simple pool of JMS Session objects intended for use by Queue browsers.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SessionPool {
|
public class SessionPool {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(SessionPool.class);
|
||||||
|
|
||||||
private ConnectionFactory connectionFactory;
|
private ConnectionFactory connectionFactory;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private LinkedList<Session> sessions = new LinkedList<Session>();
|
private LinkedList<Session> sessions = new LinkedList<Session>();
|
||||||
|
@ -78,8 +82,10 @@ public class SessionPool {
|
||||||
Session answer = null;
|
Session answer = null;
|
||||||
synchronized (sessions) {
|
synchronized (sessions) {
|
||||||
if (sessions.isEmpty()) {
|
if (sessions.isEmpty()) {
|
||||||
|
LOG.trace("Creating a new session.");
|
||||||
answer = createSession();
|
answer = createSession();
|
||||||
} else {
|
} else {
|
||||||
|
LOG.trace("Serving session from the pool.");
|
||||||
answer = sessions.removeLast();
|
answer = sessions.removeLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,10 +93,13 @@ public class SessionPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnSession(Session session) {
|
public void returnSession(Session session) {
|
||||||
if (session != null) {
|
if (session != null && !((ActiveMQSession) session).isClosed()) {
|
||||||
synchronized (sessions) {
|
synchronized (sessions) {
|
||||||
|
LOG.trace("Returning session to the pool.");
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
LOG.debug("Session closed or null, not returning to the pool.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue