KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jms > jca > ManagedSessionImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.jms.jca;
30
31 import com.caucho.log.Log;
32 import com.caucho.util.L10N;
33
34 import javax.jms.*;
35 import javax.resource.NotSupportedException JavaDoc;
36 import javax.resource.ResourceException JavaDoc;
37 import javax.resource.spi.ConnectionEvent JavaDoc;
38 import javax.resource.spi.ConnectionEventListener JavaDoc;
39 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
40 import javax.resource.spi.LocalTransaction JavaDoc;
41 import javax.resource.spi.ManagedConnection JavaDoc;
42 import javax.resource.spi.ManagedConnectionMetaData JavaDoc;
43 import javax.security.auth.Subject JavaDoc;
44 import javax.transaction.xa.XAResource JavaDoc;
45 import java.io.PrintWriter JavaDoc;
46 import java.util.logging.Logger JavaDoc;
47
48 /**
49  * The managed session
50  */

51 public class ManagedSessionImpl implements ManagedConnection JavaDoc {
52   protected static final Logger JavaDoc log = Log.open(ManagedSessionImpl.class);
53   private static final L10N L = new L10N(ManagedSessionImpl.class);
54
55   private ConnectionEventListener JavaDoc _listener;
56   private ConnectionEvent JavaDoc _connClosedEvent;
57
58   private Destination _destination;
59   
60   private Connection JavaDoc _connection;
61   private Session _session;
62   private MessageProducer _producer;
63
64   public ManagedSessionImpl(ConnectionFactory factory, Destination destination)
65     throws ResourceException JavaDoc
66   {
67     _destination = destination;
68
69     try {
70       _connection = factory.createConnection();
71       _session = _connection.createSession(false, 1);
72       _producer = _session.createProducer(destination);
73     } catch (Exception JavaDoc e) {
74       throw new ResourceException JavaDoc(e);
75     }
76   }
77
78   public ManagedConnectionMetaData JavaDoc getMetaData()
79   {
80     return null;
81   }
82
83   public LocalTransaction JavaDoc getLocalTransaction()
84     throws ResourceException JavaDoc
85   {
86     throw new NotSupportedException JavaDoc();
87   }
88
89   public XAResource JavaDoc getXAResource()
90     throws ResourceException JavaDoc
91   {
92     throw new NotSupportedException JavaDoc();
93   }
94
95   public void addConnectionEventListener(ConnectionEventListener JavaDoc listener)
96   {
97     _listener = listener;
98   }
99
100   public void removeConnectionEventListener(ConnectionEventListener JavaDoc listener)
101   {
102     _listener = null;
103   }
104
105   public ConnectionEventListener JavaDoc getConnectionEventListener()
106   {
107     return _listener;
108   }
109
110   public Object JavaDoc getConnection(Subject JavaDoc subj, ConnectionRequestInfo JavaDoc info)
111   {
112     return this;
113   }
114
115   public void associateConnection(Object JavaDoc o)
116     throws ResourceException JavaDoc
117   {
118     throw new NotSupportedException JavaDoc();
119   }
120
121   Session getSession()
122   {
123     return _session;
124   }
125
126   void send(Message message)
127     throws JMSException
128   {
129     _producer.send(message);
130   }
131
132   void close()
133   {
134     if (_listener != null) {
135       ConnectionEvent JavaDoc evt;
136       evt = new ConnectionEvent JavaDoc(this, ConnectionEvent.CONNECTION_CLOSED);
137       evt.setConnectionHandle(this);
138       _listener.connectionClosed(evt);
139     }
140   }
141
142   public PrintWriter JavaDoc getLogWriter()
143   {
144     return null;
145   }
146
147   public void setLogWriter(PrintWriter JavaDoc out)
148   {
149   }
150   
151   public void cleanup()
152     throws ResourceException JavaDoc
153   {
154   }
155
156   public void destroy()
157     throws ResourceException JavaDoc
158   {
159     try {
160       _producer.close();
161       _session.close();
162       _connection.close();
163     } catch (Exception JavaDoc e) {
164       throw new ResourceException JavaDoc(e);
165     }
166   }
167 }
168
169
Popular Tags