jstrachan 01/08/28 05:02:59
Modified: messenger PROPOSAL.html README.txt STATUS.html
build.properties.sample build.xml
Added: messenger/src/java/org/apache/commons/messenger
SessionFactory.java ThreadLocalMessenger.java
Removed: messenger/src/java/org/apache/commons/messenger
PoolingMessenger.java
Log:
Removed dependency on Jakarta commons-pool. Now pooling is done via
java.lang.ThreadLocal to ensure that the same JMS Session is used by the same calling
thread for now. Also added SessionFactory for creating JMS Session objects from a
given JMS Connection or JMS ConnectionFactory.
Revision Changes Path
1.2 +0 -2 jakarta-commons-sandbox/messenger/PROPOSAL.html
Index: PROPOSAL.html
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/PROPOSAL.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PROPOSAL.html 2001/08/24 14:20:28 1.1
+++ PROPOSAL.html 2001/08/28 12:02:58 1.2
@@ -33,8 +33,6 @@
developing and executing unit tests, but this is of interest only to
developers of the component.
-Messenger also currently uses the Jakarta Commons Pool subproject.
-
<p>No external configuration files are utilized.</p>
<h3>(2) Initial Source of the Package</h3>
1.2 +1 -1 jakarta-commons-sandbox/messenger/README.txt
Index: README.txt
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/README.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- README.txt 2001/08/24 14:20:28 1.1
+++ README.txt 2001/08/28 12:02:58 1.2
@@ -18,7 +18,7 @@
build.properties, and modify to reflect
the location of the junit.jar on your computer.
-You will also need the Jakarta commons-pool.jar as well as jms.jar
+You will also need the JMS 1.0.2 jms.jar
Once you have Ant propertly installed, and the
build.properties file correctly reflects the location
1.2 +1 -3 jakarta-commons-sandbox/messenger/STATUS.html
Index: STATUS.html
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/STATUS.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- STATUS.html 2001/08/24 14:20:28 1.1
+++ STATUS.html 2001/08/28 12:02:58 1.2
@@ -7,7 +7,7 @@
<div align="center">
<h1>The Jakarta Commons <em>Messenger</em> Package</h1>
-$Id: STATUS.html,v 1.1 2001/08/24 14:20:28 jstrachan Exp $<br>
+$Id: STATUS.html,v 1.2 2001/08/28 12:02:58 jstrachan Exp $<br>
<a href="#Introduction">[Introduction]</a>
<a href="#Dependencies">[Dependencies]</a>
<a href="#Release Info">[Release Info]</a>
@@ -40,8 +40,6 @@
(Version 1.2 or later)</li>
<li><a href="http://java.sun.com/products/jms">JMS</a>
(Version 1.0.2b or later)</li>
-<li><a href="http://jakarta.apache.org/commons/pool.html">Jakarta Commons Pool</a>
- (Version 1.0 or later)</li>
<li><a href="http://www.junit.org">JUnit Testing Framework</a>
(Version 3.7 or later) - for unit tests only, not required
for deployment</li>
1.3 +0 -4 jakarta-commons-sandbox/messenger/build.properties.sample
Index: build.properties.sample
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.properties.sample,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.properties.sample 2001/08/24 15:37:13 1.2
+++ build.properties.sample 2001/08/28 12:02:58 1.3
@@ -3,7 +3,3 @@
# jms.jar
jms.jar=/java/jms/jms.jar
-
-# jakarta commons-pool.jar
-pool.jar=../../jakarta-commons/pool/dist/commons-pool.jar
-
1.3 +2 -2 jakarta-commons-sandbox/messenger/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/build.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- build.xml 2001/08/24 15:37:13 1.2
+++ build.xml 2001/08/28 12:02:58 1.3
@@ -1,4 +1,4 @@
-<!-- $Id: build.xml,v 1.2 2001/08/24 15:37:13 jstrachan Exp $ -->
+<!-- $Id: build.xml,v 1.3 2001/08/28 12:02:58 jstrachan Exp $ -->
<project name="messenger" default="test" basedir=".">
<!-- patternset describing files to be copied from the doc directory -->
@@ -42,7 +42,7 @@
<property name="cp" value=""/>
<!-- now combine the classpaths -->
- <property name="classpath"
value="${cp}:${jms.jar}:${pool.jar}:${junit.jar}"/>
+ <property name="classpath" value="${cp}:${jms.jar}:${junit.jar}"/>
<property name="name" value="messenger"/>
<property name="Name" value="Messenger"/>
1.1
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/SessionFactory.java
Index: SessionFactory.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
* $Id: SessionFactory.java,v 1.1 2001/08/28 12:02:58 jstrachan Exp $
*/
package org.apache.commons.messenger;
import java.io.Serializable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
/** <p><code>SessionFactory</code> is a Factory of JMS Session objects.
* It can be configured with a JMS Connection object to use or can use
* a JMS ConnectionFactory instance to create the JMS Connection lazily</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class SessionFactory {
/** The JMS connection used to create JMS sessions */
private Connection connection;
/** The JMS ConnectionFactory used to create JMS Connection instances */
private ConnectionFactory connectionFactory;
/** JMS acknowlege mode used on each session */
private int acknowlegeMode;
/** whether JMS sessions should be transacted */
private boolean transacted;
/** the optional username used when creating a new JMS connection via a JMS
ConnectionFactory */
private String username;
/** the optional password used when creating a new JMS connection via a JMS
ConnectionFactory */
private String password;
/** Creates a new Session instance */
public Session createSession() throws JMSException {
Connection connection = getConnection();
if ( connection instanceof TopicConnection ) {
TopicConnection topicConnection = (TopicConnection) connection;
return topicConnection.createTopicSession( isTransacted(),
getAcknowledgeMode() );
}
else {
QueueConnection queueConnection = (QueueConnection) connection;
return queueConnection.createQueueSession( isTransacted(),
getAcknowledgeMode() );
}
}
// Properties
//-------------------------------------------------------------------------
/** Returns the JMS connection used to create new sessions */
public Connection getConnection() throws JMSException {
if ( connection == null ) {
connection = createConnection();
}
return connection;
}
public void setConnection(Connection connection) {
this.connection = connection;
}
/** Returns the JMS ConnectionFactory used to create a new connection */
public ConnectionFactory getConnectionFactory() throws JMSException {
if ( connectionFactory == null ) {
connectionFactory = createConnectionFactory();
}
return connectionFactory;
}
public void setConnectionFactory(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
/** Returns true if sessions created by this factory should be transacted */
public boolean isTransacted() {
return transacted;
}
public void setTransacted(boolean transacted) {
this.transacted = transacted;
}
/** Returns the JMS acknowledge mode used by the JMS sessions created by this
session */
public int getAcknowledgeMode() {
return acknowlegeMode;
}
public void setAcknowledgeMode(int acknowlegeMode) {
this.acknowlegeMode = acknowlegeMode;
}
/** Returns the optional username used when creating a new JMS connection via a
JMS ConnectionFactory */
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
/** Returns the optional password used when creating a new JMS connection via a
JMS ConnectionFactory */
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
// Implementation methods
//-------------------------------------------------------------------------
/** Factory method used to create a connection */
protected Connection createConnection() throws JMSException {
ConnectionFactory factory = getConnectionFactory();
if ( factory == null ) {
throw new JMSException( "No ConnectionFactory configured. Cannot create
a JMS Session" );
}
if ( factory instanceof TopicConnectionFactory ) {
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory)
factory;
if ( username != null || password != null ) {
return topicConnectionFactory.createTopicConnection( username,
password );
}
else {
return topicConnectionFactory.createTopicConnection();
}
}
else {
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
factory;
if ( username != null || password != null ) {
return queueConnectionFactory.createQueueConnection( username,
password );
}
else {
return queueConnectionFactory.createQueueConnection();
}
}
}
/** Factory method used to create a connection factory.
* Derived classes may wish to use JNDI to load the ConnectionFactory
*/
protected ConnectionFactory createConnectionFactory() throws JMSException {
return null;
}
}
1.1
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ThreadLocalMessenger.java
Index: ThreadLocalMessenger.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
* $Id: ThreadLocalMessenger.java,v 1.1 2001/08/28 12:02:58 jstrachan Exp $
*/
package org.apache.commons.messenger;
import java.io.Serializable;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
/** <p><code>ThreadLocalMessenger</code> uses a {@link ThreadLocal} variable
* to keep the session information that should be used for a given thread.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class ThreadLocalMessenger extends MessengerSupport {
/** the session object for each thread */
private ThreadLocal sessionPool = new ThreadLocal();
/** The factory used to create each thread's JMS Session */
private SessionFactory sessionFactory;
public ThreadLocalMessenger() {
}
/** Returns the SessionFactory used to create new JMS sessions */
public SessionFactory getSessionFactory() throws JMSException {
if ( sessionFactory == null ) {
sessionFactory = createSessionFactory();
}
return sessionFactory;
}
/** Sets the SessionFactory used to create new JMS sessions */
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
// Implementation methods
//-------------------------------------------------------------------------
protected Session borrowSession() throws JMSException {
Session answer = (Session) sessionPool.get();
if ( answer == null ) {
answer = createSession();
sessionPool.set( answer );
}
return answer;
}
protected void returnSession(Session session) {
}
/** Factory method to create a new JMS Session */
protected Session createSession() throws JMSException {
return getSessionFactory().createSession();
}
/** Factory method to create a SessionFactory.
* Derived classes could override this method to create the SessionFactory
* from a well known place
*/
protected SessionFactory createSessionFactory() throws JMSException {
throw new JMSException( "No SessionFactory configured for this Messenger.
Cannot create a new JMS Session" );
}
}