01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.resource.adapter.jms;
23:
24: import javax.resource.ResourceException;
25: import javax.resource.spi.ConnectionManager;
26: import javax.resource.spi.ManagedConnectionFactory;
27: import javax.resource.spi.ConnectionRequestInfo;
28: import javax.resource.spi.ManagedConnection;
29:
30: import org.jboss.logging.Logger;
31:
32: /**
33: * The resource adapters own ConnectionManager, used in non-managed
34: * environments.
35: *
36: * <p>Will handle some of the houskeeping an appserver nomaly does.
37: *
38: * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>.
39: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
40: * @version $Revision: 57189 $
41: */
42: public class JmsConnectionManager implements ConnectionManager {
43: private static final long serialVersionUID = -3638293323045716739L;
44:
45: private static final Logger log = Logger
46: .getLogger(JmsConnectionManager.class);
47:
48: /**
49: * Construct a <tt>JmsConnectionManager</tt>.
50: */
51: public JmsConnectionManager() {
52: super ();
53: }
54:
55: /**
56: * Allocate a new connection.
57: *
58: * @param mcf
59: * @param cxRequestInfo
60: * @return A new connection
61: *
62: * @throws ResourceException Failed to create connection.
63: */
64: public Object allocateConnection(ManagedConnectionFactory mcf,
65: ConnectionRequestInfo cxRequestInfo)
66: throws ResourceException {
67: boolean trace = log.isTraceEnabled();
68: if (trace)
69: log.trace("Allocating connection; mcf=" + mcf
70: + ", cxRequestInfo=" + cxRequestInfo);
71:
72: ManagedConnection mc = mcf.createManagedConnection(null,
73: cxRequestInfo);
74: Object c = mc.getConnection(null, cxRequestInfo);
75:
76: if (trace)
77: log.trace("Allocated connection: " + c
78: + ", with managed connection: " + mc);
79:
80: return c;
81: }
82: }
|