1 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 ; 36 import javax.resource.ResourceException ; 37 import javax.resource.spi.ConnectionEvent ; 38 import javax.resource.spi.ConnectionEventListener ; 39 import javax.resource.spi.ConnectionRequestInfo ; 40 import javax.resource.spi.LocalTransaction ; 41 import javax.resource.spi.ManagedConnection ; 42 import javax.resource.spi.ManagedConnectionMetaData ; 43 import javax.security.auth.Subject ; 44 import javax.transaction.xa.XAResource ; 45 import java.io.PrintWriter ; 46 import java.util.logging.Logger ; 47 48 51 public class ManagedSessionImpl implements ManagedConnection { 52 protected static final Logger log = Log.open(ManagedSessionImpl.class); 53 private static final L10N L = new L10N(ManagedSessionImpl.class); 54 55 private ConnectionEventListener _listener; 56 private ConnectionEvent _connClosedEvent; 57 58 private Destination _destination; 59 60 private Connection _connection; 61 private Session _session; 62 private MessageProducer _producer; 63 64 public ManagedSessionImpl(ConnectionFactory factory, Destination destination) 65 throws ResourceException 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 e) { 74 throw new ResourceException (e); 75 } 76 } 77 78 public ManagedConnectionMetaData getMetaData() 79 { 80 return null; 81 } 82 83 public LocalTransaction getLocalTransaction() 84 throws ResourceException 85 { 86 throw new NotSupportedException (); 87 } 88 89 public XAResource getXAResource() 90 throws ResourceException 91 { 92 throw new NotSupportedException (); 93 } 94 95 public void addConnectionEventListener(ConnectionEventListener listener) 96 { 97 _listener = listener; 98 } 99 100 public void removeConnectionEventListener(ConnectionEventListener listener) 101 { 102 _listener = null; 103 } 104 105 public ConnectionEventListener getConnectionEventListener() 106 { 107 return _listener; 108 } 109 110 public Object getConnection(Subject subj, ConnectionRequestInfo info) 111 { 112 return this; 113 } 114 115 public void associateConnection(Object o) 116 throws ResourceException 117 { 118 throw new NotSupportedException (); 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 evt; 136 evt = new ConnectionEvent (this, ConnectionEvent.CONNECTION_CLOSED); 137 evt.setConnectionHandle(this); 138 _listener.connectionClosed(evt); 139 } 140 } 141 142 public PrintWriter getLogWriter() 143 { 144 return null; 145 } 146 147 public void setLogWriter(PrintWriter out) 148 { 149 } 150 151 public void cleanup() 152 throws ResourceException 153 { 154 } 155 156 public void destroy() 157 throws ResourceException 158 { 159 try { 160 _producer.close(); 161 _session.close(); 162 _connection.close(); 163 } catch (Exception e) { 164 throw new ResourceException (e); 165 } 166 } 167 } 168 169 | Popular Tags |