jstrachan 01/08/28 06:50:10
Modified: messenger PROPOSAL.html STATUS.html
messenger/src/java/org/apache/commons/messenger
Messenger.java MessengerSupport.java
ServerSessionPoolMessenger.java SessionFactory.java
ThreadLocalMessenger.java
Added: messenger/src/java/org/apache/commons/messenger
JNDISessionFactory.java
Log:
Added JNDISessionFactory for Messenger that takes its ConnectionFactory from JNDI
Revision Changes Path
1.3 +2 -0 jakarta-commons-sandbox/messenger/PROPOSAL.html
Index: PROPOSAL.html
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/PROPOSAL.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PROPOSAL.html 2001/08/28 12:02:58 1.2
+++ PROPOSAL.html 2001/08/28 13:50:10 1.3
@@ -28,6 +28,8 @@
<p><em>Messenger</em> relies on standard JDK 1.2 (or later) APIs for
production deployment along with the JMS API.
+Messenger also uses JNDI which is a standard part of JDK 1.3 onwards
+though requires a seperate jndi.jar for pre-JDK 1.3
It utilizes the JUnit unit testing framework for
developing and executing unit tests, but this is of interest only to
1.3 +3 -1 jakarta-commons-sandbox/messenger/STATUS.html
Index: STATUS.html
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/messenger/STATUS.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- STATUS.html 2001/08/28 12:02:58 1.2
+++ STATUS.html 2001/08/28 13:50:10 1.3
@@ -7,7 +7,7 @@
<div align="center">
<h1>The Jakarta Commons <em>Messenger</em> Package</h1>
-$Id: STATUS.html,v 1.2 2001/08/28 12:02:58 jstrachan Exp $<br>
+$Id: STATUS.html,v 1.3 2001/08/28 13:50:10 jstrachan Exp $<br>
<a href="#Introduction">[Introduction]</a>
<a href="#Dependencies">[Dependencies]</a>
<a href="#Release Info">[Release Info]</a>
@@ -38,6 +38,8 @@
<ul>
<li><a href="http://java.sun.com/j2se">Java Development Kit</a>
(Version 1.2 or later)</li>
+<li><a href="http://java.sun.com/products/jndi">JNDI</a>
+ (Version 1.1 or later) which ships with JDK version 1.3 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://www.junit.org">JUnit Testing Framework</a>
1.2 +19 -3
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/Messenger.java
Index: Messenger.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/Messenger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Messenger.java 2001/08/24 14:20:28 1.1
+++ Messenger.java 2001/08/28 13:50:10 1.2
@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
- * $Id: Messenger.java,v 1.1 2001/08/24 14:20:28 jstrachan Exp $
+ * $Id: Messenger.java,v 1.2 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
@@ -22,10 +22,13 @@
/** <p><code>Messenger</code> a facade over the JMS API making it easy to use JMS
- * and hiding much of the complexity of threading and configuration.</p>
+ * and hiding much of the complexity of threading and configuration.
+ * A Messenger will internally associate a JMS Session with the calling thread
+ * so that all methods called in the same thread (such as inside a Servlet or
+ * taglib) will use the same JMS Session.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface Messenger {
@@ -64,6 +67,7 @@
public void removeListener(String subject, MessageListener listener) throws
JMSException;
public void removeListener(String subject, String selector, MessageListener
listener) throws JMSException;
+
// Message factory methods
//-------------------------------------------------------------------------
@@ -81,5 +85,17 @@
public TextMessage createTextMessage() throws JMSException;
public TextMessage createTextMessage(String text) throws JMSException;
+
+ // Transaction related methods
+ //-------------------------------------------------------------------------
+
+ /** Commits all messages done in this thread and releases any locks */
+ public void commit() throws JMSException;
+
+ /** Rolls back any messages done in this thread and releases any locks */
+ public void rollback() throws JMSException;
+
+ /** Closes the session being used by this thread. */
+ public void close() throws JMSException;
}
1.2 +34 -2
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSupport.java
Index: MessengerSupport.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/MessengerSupport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MessengerSupport.java 2001/08/24 14:20:28 1.1
+++ MessengerSupport.java 2001/08/28 13:50:10 1.2
@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
- * $Id: MessengerSupport.java,v 1.1 2001/08/24 14:20:28 jstrachan Exp $
+ * $Id: MessengerSupport.java,v 1.2 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
@@ -37,7 +37,7 @@
* connection and session creation and the pooling strategy.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public abstract class MessengerSupport implements Messenger {
@@ -283,7 +283,36 @@
}
}
+ public void commit() throws JMSException {
+ Session session = borrowSession();
+ try {
+ session.commit();
+ }
+ finally {
+ returnSession( session );
+ }
+ }
+ public void rollback() throws JMSException {
+ Session session = borrowSession();
+ try {
+ session.rollback();
+ }
+ finally {
+ returnSession( session );
+ }
+ }
+
+ public void close() throws JMSException {
+ Session session = borrowSession();
+ try {
+ session.close();
+ }
+ finally {
+ deleteSession( session );
+ }
+ }
+
// Properties
//-------------------------------------------------------------------------
@@ -327,6 +356,9 @@
/** Returns a session instance back to the pool */
protected abstract void returnSession(Session session) throws JMSException;
+
+ /** Deletes a session instance */
+ protected abstract void deleteSession(Session session) throws JMSException;
/** Returns a message producer for the given session and subject */
protected MessageProducer getMessageProducer( Session session, String subject )
throws JMSException {
1.2 +4 -1
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ServerSessionPoolMessenger.java
Index: ServerSessionPoolMessenger.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ServerSessionPoolMessenger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ServerSessionPoolMessenger.java 2001/08/24 15:37:13 1.1
+++ ServerSessionPoolMessenger.java 2001/08/28 13:50:10 1.2
@@ -5,7 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*
- * $Id: ServerSessionPoolMessenger.java,v 1.1 2001/08/24 15:37:13 jstrachan Exp $
+ * $Id: ServerSessionPoolMessenger.java,v 1.2 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
@@ -22,7 +22,7 @@
* optional ServerSessionPool to implement session based pooling.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ServerSessionPoolMessenger extends MessengerSupport {
@@ -55,6 +55,9 @@
}
protected void returnSession(Session session) throws JMSException {
+ }
+
+ protected void deleteSession(Session session) throws JMSException {
}
}
1.2 +2 -2
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/SessionFactory.java
Index: SessionFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/SessionFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SessionFactory.java 2001/08/28 12:02:58 1.1
+++ SessionFactory.java 2001/08/28 13:50:10 1.2
@@ -5,7 +5,7 @@
* 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 $
+ * $Id: SessionFactory.java,v 1.2 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
@@ -26,7 +26,7 @@
* a JMS ConnectionFactory instance to create the JMS Connection lazily</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class SessionFactory {
@@ -35,7 +35,7 @@
/** The JMS ConnectionFactory used to create JMS Connection instances */
private ConnectionFactory connectionFactory;
/** JMS acknowlege mode used on each session */
- private int acknowlegeMode;
+ private int acknowlegeMode = Session.AUTO_ACKNOWLEDGE;
/** whether JMS sessions should be transacted */
private boolean transacted;
/** the optional username used when creating a new JMS connection via a JMS
ConnectionFactory */
1.2 +5 -1
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ThreadLocalMessenger.java
Index: ThreadLocalMessenger.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/ThreadLocalMessenger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ThreadLocalMessenger.java 2001/08/28 12:02:58 1.1
+++ ThreadLocalMessenger.java 2001/08/28 13:50:10 1.2
@@ -5,7 +5,7 @@
* 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 $
+ * $Id: ThreadLocalMessenger.java,v 1.2 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
@@ -20,7 +20,7 @@
* 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 $
+ * @version $Revision: 1.2 $
*/
public class ThreadLocalMessenger extends MessengerSupport {
@@ -59,6 +59,10 @@
}
protected void returnSession(Session session) {
+ }
+
+ protected void deleteSession(Session session) throws JMSException {
+ sessionPool.set( null);
}
/** Factory method to create a new JMS Session */
1.1
jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messenger/JNDISessionFactory.java
Index: JNDISessionFactory.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: JNDISessionFactory.java,v 1.1 2001/08/28 13:50:10 jstrachan Exp $
*/
package org.apache.commons.messenger;
import java.io.Serializable;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/** <p><code>JNDISessionFactory</code> is a Factory of JMS Session objects
* which looks up the ConnectionFactory object from JNDI.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a>
* @version $Revision: 1.1 $
*/
public class JNDISessionFactory extends SessionFactory {
/** the initial JNDI context used to lookup ConnectionFactory objects */
private Context context;
/** the properties used to create the initial context */
private Properties contextProperties;
/** the name used to lookup the ConnectionFactory */
private String lookupName;
// Properties
//-------------------------------------------------------------------------
/** The JNDI Name of the ConnectionFactory */
public String getLookupName() {
return lookupName;
}
/** Sets the JNDI Name of the ConnectionFactory */
public void setLookupName(String lookupName) {
this.lookupName = lookupName;
}
/** Returns the JNDI Context used to lookup JMS ConnectionFactory objects */
public Context getContext() throws NamingException {
if ( context == null ) {
context = createContext();
}
return context;
}
public void setContext(Context context) {
this.context = context;
}
/** Returns the Properties used to create the initial JNDI Context */
public Properties getContextProperties() throws NamingException {
if ( contextProperties == null ) {
contextProperties = createContextProperties();
}
return contextProperties;
}
public void setContextProperties(Properties contextProperties) {
this.contextProperties = contextProperties;
}
// Implementation methods
//-------------------------------------------------------------------------
/** Factory method used to create a connection factory.
* Lookup the ConnectionFactory in JNDI
*/
protected ConnectionFactory createConnectionFactory() throws JMSException {
try {
return (ConnectionFactory) getContext().lookup( getLookupName() );
}
catch (NamingException e) {
JMSException jmsException = new JMSException( "Failed to lookup: " +
getLookupName() + " using JNDI. " + e );
jmsException.setLinkedException(e);
throw jmsException;
}
}
/** Factory method used to create a connection factory.
* Derived classes may wish to use JNDI to load the ConnectionFactory
*/
protected Context createContext() throws NamingException {
return new InitialContext( getContextProperties() );
}
/** Factory method used to create the initial JNDI context properties.
* Derived classes may wish to overload this method to provide different
properties
*/
protected Properties createContextProperties() throws NamingException {
return System.getProperties();
}
}