git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@666887 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-06-11 23:13:59 +00:00
parent 0dec0b6b0c
commit 6db9a37d2f
1 changed files with 12 additions and 29 deletions

View File

@ -17,9 +17,9 @@
package org.apache.activemq.ra; package org.apache.activemq.ra;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.ExceptionListener; import javax.jms.ExceptionListener;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -32,7 +32,6 @@ import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData; import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject; import javax.security.auth.Subject;
import javax.transaction.xa.XAResource; import javax.transaction.xa.XAResource;
import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.LocalTransactionEventListener; import org.apache.activemq.LocalTransactionEventListener;
import org.apache.activemq.TransactionContext; import org.apache.activemq.TransactionContext;
@ -63,8 +62,8 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
private final ActiveMQConnection physicalConnection; private final ActiveMQConnection physicalConnection;
private final TransactionContext transactionContext; private final TransactionContext transactionContext;
private final ArrayList<ManagedConnectionProxy> proxyConnections = new ArrayList<ManagedConnectionProxy>(); private final List<ManagedConnectionProxy> proxyConnections = new CopyOnWriteArrayList<ManagedConnectionProxy>();
private final ArrayList<ConnectionEventListener> listeners = new ArrayList<ConnectionEventListener>(); private final List<ConnectionEventListener> listeners = new CopyOnWriteArrayList<ConnectionEventListener>();
private final LocalAndXATransaction localAndXATransaction; private final LocalAndXATransaction localAndXATransaction;
private Subject subject; private Subject subject;
@ -81,9 +80,7 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
this.localAndXATransaction = new LocalAndXATransaction(transactionContext) { this.localAndXATransaction = new LocalAndXATransaction(transactionContext) {
public void setInManagedTx(boolean inManagedTx) throws JMSException { public void setInManagedTx(boolean inManagedTx) throws JMSException {
super.setInManagedTx(inManagedTx); super.setInManagedTx(inManagedTx);
Iterator<ManagedConnectionProxy> iterator = proxyConnections.iterator(); for (ManagedConnectionProxy proxy:proxyConnections) {
while (iterator.hasNext()) {
ManagedConnectionProxy proxy = iterator.next();
proxy.setUseSharedTxContext(inManagedTx); proxy.setUseSharedTxContext(inManagedTx);
} }
} }
@ -145,27 +142,21 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
private void fireBeginEvent() { private void fireBeginEvent() {
ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_STARTED); ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
Iterator<ConnectionEventListener> iterator = listeners.iterator(); for(ConnectionEventListener l:listeners) {
while (iterator.hasNext()) {
ConnectionEventListener l = iterator.next();
l.localTransactionStarted(event); l.localTransactionStarted(event);
} }
} }
private void fireCommitEvent() { private void fireCommitEvent() {
ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED); ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
Iterator<ConnectionEventListener> iterator = listeners.iterator(); for(ConnectionEventListener l:listeners) {
while (iterator.hasNext()) {
ConnectionEventListener l = iterator.next();
l.localTransactionCommitted(event); l.localTransactionCommitted(event);
} }
} }
private void fireRollbackEvent() { private void fireRollbackEvent() {
ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK); ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
Iterator<ConnectionEventListener> iterator = listeners.iterator(); for(ConnectionEventListener l:listeners) {
while (iterator.hasNext()) {
ConnectionEventListener l = iterator.next();
l.localTransactionRolledback(event); l.localTransactionRolledback(event);
} }
} }
@ -174,18 +165,14 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.CONNECTION_CLOSED); ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.CONNECTION_CLOSED);
event.setConnectionHandle(proxy); event.setConnectionHandle(proxy);
Iterator<ConnectionEventListener> iterator = listeners.iterator(); for(ConnectionEventListener l:listeners) {
while (iterator.hasNext()) {
ConnectionEventListener l = iterator.next();
l.connectionClosed(event); l.connectionClosed(event);
} }
} }
private void fireErrorOccurredEvent(Exception error) { private void fireErrorOccurredEvent(Exception error) {
ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, error); ConnectionEvent event = new ConnectionEvent(ActiveMQManagedConnection.this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, error);
Iterator<ConnectionEventListener> iterator = listeners.iterator(); for(ConnectionEventListener l:listeners) {
while (iterator.hasNext()) {
ConnectionEventListener l = iterator.next();
l.connectionErrorOccurred(event); l.connectionErrorOccurred(event);
} }
} }
@ -238,9 +225,7 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
return; return;
} }
Iterator<ManagedConnectionProxy> iterator = proxyConnections.iterator(); for (ManagedConnectionProxy proxy:proxyConnections) {
while (iterator.hasNext()) {
ManagedConnectionProxy proxy = iterator.next();
proxy.cleanup(); proxy.cleanup();
} }
proxyConnections.clear(); proxyConnections.clear();
@ -399,9 +384,7 @@ public class ActiveMQManagedConnection implements ManagedConnection, ExceptionLi
LOG.warn("Connection failed: " + e); LOG.warn("Connection failed: " + e);
LOG.debug("Cause: ", e); LOG.debug("Cause: ", e);
// Let any active proxy connections know that exception occured. for (ManagedConnectionProxy proxy:proxyConnections) {
for (Iterator<ManagedConnectionProxy> iter = proxyConnections.iterator(); iter.hasNext();) {
ManagedConnectionProxy proxy = iter.next();
proxy.onException(e); proxy.onException(e);
} }
// Let the container know that the error occured. // Let the container know that the error occured.