001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.jms.jca;
030:
031: import com.caucho.log.Log;
032: import com.caucho.util.L10N;
033:
034: import javax.jms.*;
035: import javax.resource.NotSupportedException;
036: import javax.resource.ResourceException;
037: import javax.resource.spi.ConnectionEvent;
038: import javax.resource.spi.ConnectionEventListener;
039: import javax.resource.spi.ConnectionRequestInfo;
040: import javax.resource.spi.LocalTransaction;
041: import javax.resource.spi.ManagedConnection;
042: import javax.resource.spi.ManagedConnectionMetaData;
043: import javax.security.auth.Subject;
044: import javax.transaction.xa.XAResource;
045: import java.io.PrintWriter;
046: import java.util.logging.Logger;
047:
048: /**
049: * The managed session
050: */
051: public class ManagedSessionImpl implements ManagedConnection {
052: protected static final Logger log = Log
053: .open(ManagedSessionImpl.class);
054: private static final L10N L = new L10N(ManagedSessionImpl.class);
055:
056: private ConnectionEventListener _listener;
057: private ConnectionEvent _connClosedEvent;
058:
059: private Destination _destination;
060:
061: private Connection _connection;
062: private Session _session;
063: private MessageProducer _producer;
064:
065: public ManagedSessionImpl(ConnectionFactory factory,
066: Destination destination) throws ResourceException {
067: _destination = destination;
068:
069: try {
070: _connection = factory.createConnection();
071: _session = _connection.createSession(false, 1);
072: _producer = _session.createProducer(destination);
073: } catch (Exception e) {
074: throw new ResourceException(e);
075: }
076: }
077:
078: public ManagedConnectionMetaData getMetaData() {
079: return null;
080: }
081:
082: public LocalTransaction getLocalTransaction()
083: throws ResourceException {
084: throw new NotSupportedException();
085: }
086:
087: public XAResource getXAResource() throws ResourceException {
088: throw new NotSupportedException();
089: }
090:
091: public void addConnectionEventListener(
092: ConnectionEventListener listener) {
093: _listener = listener;
094: }
095:
096: public void removeConnectionEventListener(
097: ConnectionEventListener listener) {
098: _listener = null;
099: }
100:
101: public ConnectionEventListener getConnectionEventListener() {
102: return _listener;
103: }
104:
105: public Object getConnection(Subject subj, ConnectionRequestInfo info) {
106: return this ;
107: }
108:
109: public void associateConnection(Object o) throws ResourceException {
110: throw new NotSupportedException();
111: }
112:
113: Session getSession() {
114: return _session;
115: }
116:
117: void send(Message message) throws JMSException {
118: _producer.send(message);
119: }
120:
121: void close() {
122: if (_listener != null) {
123: ConnectionEvent evt;
124: evt = new ConnectionEvent(this ,
125: ConnectionEvent.CONNECTION_CLOSED);
126: evt.setConnectionHandle(this );
127: _listener.connectionClosed(evt);
128: }
129: }
130:
131: public PrintWriter getLogWriter() {
132: return null;
133: }
134:
135: public void setLogWriter(PrintWriter out) {
136: }
137:
138: public void cleanup() throws ResourceException {
139: }
140:
141: public void destroy() throws ResourceException {
142: try {
143: _producer.close();
144: _session.close();
145: _connection.close();
146: } catch (Exception e) {
147: throw new ResourceException(e);
148: }
149: }
150: }
|