001: /*
002: * $Id: DefaultConnectionManager.java 10789 2008-02-12 20:04:43Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.jca;
012:
013: import java.io.IOException;
014: import java.io.ObjectInputStream;
015:
016: import javax.resource.ResourceException;
017: import javax.resource.spi.ConnectionEvent;
018: import javax.resource.spi.ConnectionEventListener;
019: import javax.resource.spi.ConnectionManager;
020: import javax.resource.spi.ConnectionRequestInfo;
021: import javax.resource.spi.ManagedConnection;
022: import javax.resource.spi.ManagedConnectionFactory;
023: import javax.security.auth.Subject;
024:
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: /**
029: * <code>DefaultConnectionManager</code> TODO
030: */
031: public class DefaultConnectionManager implements ConnectionManager,
032: ConnectionEventListener {
033: /**
034: * Serial version
035: */
036: private static final long serialVersionUID = 1967602190602154760L;
037:
038: private transient Log logger = LogFactory.getLog(this .getClass());
039:
040: public DefaultConnectionManager() {
041: super ();
042: }
043:
044: private void readObject(ObjectInputStream ois)
045: throws ClassNotFoundException, IOException {
046: ois.defaultReadObject();
047: this .logger = LogFactory.getLog(this .getClass());
048: }
049:
050: /**
051: * @see javax.resource.spi.ConnectionManager#allocateConnection(javax.resource.spi.ManagedConnectionFactory,
052: * javax.resource.spi.ConnectionRequestInfo)
053: */
054: public Object allocateConnection(
055: ManagedConnectionFactory connectionFactory,
056: ConnectionRequestInfo info) throws ResourceException {
057: Subject subject = null;
058: ManagedConnection connection = connectionFactory
059: .createManagedConnection(subject, info);
060: connection.addConnectionEventListener(this );
061: return connection.getConnection(subject, info);
062: }
063:
064: /**
065: * @see javax.resource.spi.ConnectionEventListener#connectionClosed(javax.resource.spi.ConnectionEvent)
066: */
067: public void connectionClosed(ConnectionEvent event) {
068: try {
069: ((ManagedConnection) event.getSource()).cleanup();
070: } catch (ResourceException e) {
071: logger
072: .warn(
073: "Error occured during the cleanup of a managed connection: ",
074: e);
075: }
076: try {
077: ((ManagedConnection) event.getSource()).destroy();
078: } catch (ResourceException e) {
079: logger
080: .warn(
081: "Error occured during the destruction of a managed connection: ",
082: e);
083: }
084: }
085:
086: /**
087: * @see javax.resource.spi.ConnectionEventListener#localTransactionStarted(javax.resource.spi.ConnectionEvent)
088: */
089: public void localTransactionStarted(ConnectionEvent event) {
090: // TODO maybe later?
091: }
092:
093: /**
094: * @see javax.resource.spi.ConnectionEventListener#localTransactionCommitted(javax.resource.spi.ConnectionEvent)
095: */
096: public void localTransactionCommitted(ConnectionEvent event) {
097: // TODO maybe later?
098: }
099:
100: /**
101: * @see javax.resource.spi.ConnectionEventListener#localTransactionRolledback(javax.resource.spi.ConnectionEvent)
102: */
103: public void localTransactionRolledback(ConnectionEvent event) {
104: // TODO maybe later?
105: }
106:
107: /**
108: * @see javax.resource.spi.ConnectionEventListener#connectionErrorOccurred(javax.resource.spi.ConnectionEvent)
109: */
110: public void connectionErrorOccurred(ConnectionEvent event) {
111: logger.warn("Managed connection experiened an error: ", event
112: .getException());
113: try {
114: ((ManagedConnection) event.getSource()).cleanup();
115: } catch (ResourceException e) {
116: logger
117: .warn(
118: "Error occured during the cleanup of a managed connection: ",
119: e);
120: }
121: try {
122: ((ManagedConnection) event.getSource()).destroy();
123: } catch (ResourceException e) {
124: logger
125: .warn(
126: "Error occured during the destruction of a managed connection: ",
127: e);
128: }
129: }
130:
131: }
|