1 18 package org.apache.activemq.ra; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 import javax.resource.ResourceException ; 24 import javax.resource.spi.ConnectionEvent ; 25 import javax.resource.spi.ConnectionEventListener ; 26 import javax.resource.spi.ConnectionManager ; 27 import javax.resource.spi.ConnectionRequestInfo ; 28 import javax.resource.spi.ManagedConnection ; 29 import javax.resource.spi.ManagedConnectionFactory ; 30 import javax.security.auth.Subject ; 31 32 33 39 public class SimpleConnectionManager implements ConnectionManager , ConnectionEventListener { 40 41 private static final long serialVersionUID = -7662970495944876239L; 42 43 private static final Log log = LogFactory.getLog(SimpleConnectionManager.class); 44 45 48 public Object allocateConnection(ManagedConnectionFactory connectionFactory, ConnectionRequestInfo info) throws ResourceException { 49 Subject subject = null; 50 ManagedConnection connection = connectionFactory.createManagedConnection(subject, info); 51 connection.addConnectionEventListener(this); 52 return connection.getConnection(subject, info); 53 } 54 55 58 public void connectionClosed(ConnectionEvent event) { 59 try { 60 ((ManagedConnection ) event.getSource()).cleanup(); 61 } 62 catch (ResourceException e) { 63 log.warn("Error occured during the cleanup of a managed connection: ", e); 64 } 65 try { 66 ((ManagedConnection ) event.getSource()).destroy(); 67 } 68 catch (ResourceException e) { 69 log.warn("Error occured during the destruction of a managed connection: ", e); 70 } 71 } 72 73 76 public void localTransactionStarted(ConnectionEvent event) { 77 } 78 79 82 public void localTransactionCommitted(ConnectionEvent event) { 83 } 84 85 88 public void localTransactionRolledback(ConnectionEvent event) { 89 } 90 91 94 public void connectionErrorOccurred(ConnectionEvent event) { 95 log.warn("Managed connection experiened an error: ", event.getException()); 96 try { 97 ((ManagedConnection ) event.getSource()).cleanup(); 98 } 99 catch (ResourceException e) { 100 log.warn("Error occured during the cleanup of a managed connection: ", e); 101 } 102 try { 103 ((ManagedConnection ) event.getSource()).destroy(); 104 } 105 catch (ResourceException e) { 106 log.warn("Error occured during the destruction of a managed connection: ", e); 107 } 108 } 109 110 } 111 | Popular Tags |