git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@918384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-03-03 10:28:54 +00:00
parent f33e2190d0
commit f82dc25eae
2 changed files with 45 additions and 1 deletions

View File

@ -115,6 +115,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
private int auditMaximumProducerNumber = ActiveMQMessageAudit.MAXIMUM_PRODUCER_COUNT;
private boolean useDedicatedTaskRunner;
private long consumerFailoverRedeliveryWaitPeriod = 0;
private ClientInternalExceptionListener clientInternalExceptionListener;
// /////////////////////////////////////////////
//
@ -323,6 +324,9 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
if (exceptionListener != null) {
connection.setExceptionListener(exceptionListener);
}
if (clientInternalExceptionListener != null) {
connection.setClientInternalExceptionListener(clientInternalExceptionListener);
}
}
// /////////////////////////////////////////////
@ -923,4 +927,22 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
public long getConsumerFailoverRedeliveryWaitPeriod() {
return consumerFailoverRedeliveryWaitPeriod;
}
public ClientInternalExceptionListener getClientInternalExceptionListener() {
return clientInternalExceptionListener;
}
/**
* Allows an {@link ClientInternalExceptionListener} to be configured on the ConnectionFactory so that when this factory
* is used by frameworks which don't expose the Connection such as Spring JmsTemplate, you can register
* an exception listener.
* <p> Note: access to this clientInternalExceptionListener will <b>not</b> be serialized if it is associated with more than
* on connection (as it will be if more than one connection is subsequently created by this connection factory)
* @param clientInternalExceptionListener sets the exception listener to be registered on all connections
* created by this factory
*/
public void setClientInternalExceptionListener(
ClientInternalExceptionListener clientInternalExceptionListener) {
this.clientInternalExceptionListener = clientInternalExceptionListener;
}
}

View File

@ -30,7 +30,6 @@ import javax.jms.Session;
import org.apache.activemq.broker.BrokerRegistry;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.network.DiscoveryNetworkConnector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -184,6 +183,29 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
}
public void testSetClientInternalExceptionListener() throws Exception {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
connection = (ActiveMQConnection)cf.createConnection();
assertNull(connection.getClientInternalExceptionListener());
ClientInternalExceptionListener listener = new ClientInternalExceptionListener() {
public void onException(Throwable exception) {
}
};
connection.setClientInternalExceptionListener(listener);
cf.setClientInternalExceptionListener(listener);
connection = (ActiveMQConnection)cf.createConnection();
assertNotNull(connection.getClientInternalExceptionListener());
assertEquals(listener, connection.getClientInternalExceptionListener());
connection = (ActiveMQConnection)cf.createConnection();
assertEquals(listener, connection.getClientInternalExceptionListener());
assertEquals(listener, cf.getClientInternalExceptionListener());
}
protected void assertCreateConnection(String uri) throws Exception {
// Start up a broker with a tcp connector.
broker = new BrokerService();