KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_jms > JQueueConnection


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  * --------------------------------------------------------------------------
21  * $Id: JQueueConnection.java,v 1.7 2004/03/19 14:31:48 sauthieg Exp $
22  * --------------------------------------------------------------------------
23  */

24
25 package org.objectweb.jonas_jms;
26
27 import javax.jms.ConnectionConsumer JavaDoc;
28 import javax.jms.JMSException JavaDoc;
29 import javax.jms.Queue JavaDoc;
30 import javax.jms.QueueConnection JavaDoc;
31 import javax.jms.QueueSession JavaDoc;
32 import javax.jms.ServerSessionPool JavaDoc;
33 import javax.jms.XAConnection JavaDoc;
34 import javax.jms.XAQueueConnection JavaDoc;
35 import javax.jms.XAQueueConnectionFactory JavaDoc;
36
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39 /**
40  *
41  * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
42  * Contributor(s):
43  * Philippe Durieux
44  * Jeff Mesnil
45  *
46  */

47
48 public class JQueueConnection extends JConnection implements QueueConnection JavaDoc {
49
50     // The XAQueueConnection used in the MOM
51
protected XAQueueConnection JavaDoc xaqc = null;
52
53
54     /**
55      * Constructor of a JQueueConnection for a specified user.
56      *
57      * @param user user's name
58      * @param passwd user's password
59      */

60     public JQueueConnection(JConnectionFactory jcf,
61                             XAQueueConnectionFactory JavaDoc xaqcf,
62                             String JavaDoc user, String JavaDoc passwd) throws JMSException JavaDoc {
63         super(jcf, user);
64
65         // Create the underlaying XAQueueConnection
66
xaqc = xaqcf.createXAQueueConnection(user, passwd);
67         this.xac = (XAConnection JavaDoc) xaqc;
68     }
69
70     /**
71      * Constructor of a JQueueConnection for an anonymous user.
72      */

73     public JQueueConnection(JConnectionFactory jcf, XAQueueConnectionFactory JavaDoc xaqcf)
74         throws JMSException JavaDoc {
75
76         super(jcf, INTERNAL_USER_NAME);
77         xaqc = xaqcf.createXAQueueConnection();
78         this.xac = (XAConnection JavaDoc) xaqc;
79     }
80
81     // -----------------------------------------------------------------------
82
// QueueConnection implementation
83
// -----------------------------------------------------------------------
84

85     /**
86      * Create a connection consumer for this connection
87      * @param queue - the queue to access
88      * @param selector - only messages with properties matching the message
89      * selector expression aredelivered
90      * @param sessionPool - the server session pool to associate with this connection consumer.
91      * @param maxMessages - the maximum number of messages that can be assigned
92      * to a server session at one time.
93      * @return the connection consumer.
94      * @throws JMSException - if JMS Connection fails to create a a connection consumer
95      * due to some internal error or invalid arguments for sessionPool and message selector.
96      * @throws InvalidSelectorException - if the message selector is invalid.
97      */

98     public ConnectionConsumer JavaDoc createConnectionConsumer(Queue JavaDoc queue,
99                                                        String JavaDoc selector,
100                                                        ServerSessionPool JavaDoc pool,
101                                                        int maxmessages) throws JMSException JavaDoc {
102         TraceJms.logger.log(BasicLevel.DEBUG, "");
103         return xaqc.createConnectionConsumer(queue, selector, pool, maxmessages);
104     }
105
106     /**
107      * Create a Queue Session
108      * @param transacted - if true, the session is transacted.
109      * @param acknowledgeMode - indicates whether the consumer or the client will
110      * acknowledge any messages it receives.
111      * This parameter will be ignored if the session is transacted.
112      * @return a newly created queue session.
113      * @throws JMSException - if JMS Connection fails to create a session.
114      */

115     public QueueSession JavaDoc createQueueSession(boolean transacted, int acknowledgeMode) throws JMSException JavaDoc {
116         TraceJms.logger.log(BasicLevel.DEBUG, "");
117         return new JQueueSession(this, xaqc);
118     }
119 }
120
Popular Tags