本文整理汇总了Java中javax.jms.ExceptionListener类的典型用法代码示例。如果您正苦于以下问题:Java ExceptionListener类的具体用法?Java ExceptionListener怎么用?Java ExceptionListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionListener类属于javax.jms包,在下文中一共展示了ExceptionListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testExceptionListenerGetsNotified
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Test(timeout = 60000)
public void testExceptionListenerGetsNotified() throws Exception {
final CountDownLatch signal = new CountDownLatch(1);
Connection connection = cf.createConnection();
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
LOG.info("ExceptionListener called with error: {}", exception.getMessage());
signal.countDown();
}
});
assertNotNull(connection.getExceptionListener());
MockJMSConnection mockJMSConnection = (MockJMSConnection) ((JmsPoolConnection) connection).getConnection();
mockJMSConnection.injectConnectionError(new JMSException("Some non-fatal error"));
assertTrue(signal.await(10, TimeUnit.SECONDS));
}
示例2: testFailedConnectThenSucceedsWithListener
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Test
public void testFailedConnectThenSucceedsWithListener() throws JMSException {
Connection connection = pooledConnFact.createConnection("invalid", "credentials");
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
LOG.warn("Connection get error: {}", exception.getMessage());
}
});
try {
connection.start();
fail("Should fail to connect");
} catch (JMSSecurityException ex) {
LOG.info("Caught expected security error");
}
connection = pooledConnFact.createConnection("system", "manager");
connection.start();
LOG.info("Successfully create new connection.");
connection.close();
}
示例3: invokeExceptionListener
import javax.jms.ExceptionListener; //导入依赖的package包/类
/**
* Invoke the registered JMS ExceptionListener, if any.
* @param ex the exception that arose during JMS processing
* @see #setExceptionListener
*/
protected void invokeExceptionListener(JMSException ex) {
ExceptionListener exceptionListener = getExceptionListener();
if (exceptionListener != null) {
exceptionListener.onException(ex);
}
}
示例4: prepareConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
/**
* Prepare the given Connection before it is exposed.
* <p>The default implementation applies ExceptionListener and client id.
* Can be overridden in subclasses.
* @param con the Connection to prepare
* @throws JMSException if thrown by JMS API methods
* @see #setExceptionListener
* @see #setReconnectOnException
*/
protected void prepareConnection(Connection con) throws JMSException {
if (getClientId() != null) {
con.setClientID(getClientId());
}
if (this.aggregatedExceptionListener != null) {
con.setExceptionListener(this.aggregatedExceptionListener);
}
else if (getExceptionListener() != null || isReconnectOnException()) {
ExceptionListener listenerToUse = getExceptionListener();
if (isReconnectOnException()) {
this.aggregatedExceptionListener = new AggregatedExceptionListener();
this.aggregatedExceptionListener.delegates.add(this);
if (listenerToUse != null) {
this.aggregatedExceptionListener.delegates.add(listenerToUse);
}
listenerToUse = this.aggregatedExceptionListener;
}
con.setExceptionListener(listenerToUse);
}
}
示例5: createConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
private Connection createConnection(URI remoteURI, String username, String password, String clientId, boolean start) throws JMSException {
JmsConnectionFactory factory = new JmsConnectionFactory(remoteURI);
Connection connection = trackJMSConnection(factory.createConnection(username, password));
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
exception.printStackTrace();
}
});
if (clientId != null && !clientId.isEmpty()) {
connection.setClientID(clientId);
}
if (start) {
connection.start();
}
return connection;
}
示例6: createCoreConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
private Connection createCoreConnection(String connectionString, String username, String password, String clientId, boolean start) throws JMSException {
ActiveMQJMSConnectionFactory factory = new ActiveMQJMSConnectionFactory(connectionString);
Connection connection = trackJMSConnection(factory.createConnection(username, password));
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
exception.printStackTrace();
}
});
if (clientId != null && !clientId.isEmpty()) {
connection.setClientID(clientId);
}
if (start) {
connection.start();
}
return connection;
}
示例7: createOpenWireConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
private Connection createOpenWireConnection(String connectionString, String username, String password, String clientId, boolean start) throws JMSException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionString);
Connection connection = trackJMSConnection(factory.createConnection(username, password));
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
exception.printStackTrace();
}
});
if (clientId != null && !clientId.isEmpty()) {
connection.setClientID(clientId);
}
if (start) {
connection.start();
}
return connection;
}
示例8: testSetExceptionListener
import javax.jms.ExceptionListener; //导入依赖的package包/类
public void testSetExceptionListener() throws Exception {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
connection = (ActiveMQConnection) cf.createConnection();
assertNull(connection.getExceptionListener());
ExceptionListener exListener = new ExceptionListener() {
@Override
public void onException(JMSException arg0) {
}
};
cf.setExceptionListener(exListener);
connection.close();
connection = (ActiveMQConnection) cf.createConnection();
assertNotNull(connection.getExceptionListener());
assertEquals(exListener, connection.getExceptionListener());
connection.close();
connection = (ActiveMQConnection) cf.createConnection();
assertEquals(exListener, connection.getExceptionListener());
assertEquals(exListener, cf.getExceptionListener());
connection.close();
}
示例9: updateInternal
import javax.jms.ExceptionListener; //导入依赖的package包/类
private void updateInternal(Map<String, ?> configuration) throws JMSException {
// get JMS up and running
jmsConnection = connectionFactory.createQueueConnection();
jmsConnection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException e) {
log.error("There was an error while working with JMS.", e);
}
});
jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = jmsSession.createQueue("test");
producer = new JMSProducer(jmsSession, destination);
consumer = new JMSConsumer(jmsSession, destination);
jmsConnection.start();
}
示例10: getConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
/**
* Creates a connection to the broker, and sets a connection listener to prevent failover and an exception listener
* with a {@link CountDownLatch} to synchronise in the {@link #check403Exception(Throwable)} method and allow the
* {@link #tearDown()} method to complete properly.
*/
public Connection getConnection(String vhost, String username, String password) throws NamingException, JMSException, URLSyntaxException
{
AMQConnection connection = (AMQConnection) getConnection(createConnectionURL(vhost, username, password));
//Prevent Failover
connection.setConnectionListener(this);
//QPID-2081: use a latch to sync on exception causing connection close, to work
//around the connection close race during tearDown() causing sporadic failures
_exceptionReceived = new CountDownLatch(1);
connection.setExceptionListener(new ExceptionListener()
{
public void onException(JMSException e)
{
_exceptionReceived.countDown();
}
});
return (Connection) connection;
}
示例11: testBrokerDeath
import javax.jms.ExceptionListener; //导入依赖的package包/类
public void testBrokerDeath() throws Exception
{
Connection conn = getConnection("guest", "guest");
conn.start();
final CountDownLatch fired = new CountDownLatch(1);
conn.setExceptionListener(new ExceptionListener()
{
public void onException(JMSException e)
{
fired.countDown();
}
});
stopBroker();
if (!fired.await(3, TimeUnit.SECONDS))
{
fail("exception listener was not fired");
}
}
示例12: createConsumer
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Override
protected MessageConsumer createConsumer() throws Exception {
connection = createConnectionToMockProvider();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = session.createQueue(_testName.getMethodName());
MessageConsumer consumer = session.createConsumer(destination);
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
}
});
connection.start();
providerListener.onConnectionFailure(new IOException());
final JmsConnection jmsConnection = connection;
assertTrue(Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return !jmsConnection.isConnected();
}
}, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2)));
return consumer;
}
示例13: createTestResources
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Override
protected void createTestResources() throws Exception {
connection = createConnectionToMockProvider();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException exception) {
}
});
Queue destination = session.createQueue(_testName.getMethodName());
sender = session.createProducer(destination);
receiver = session.createConsumer(destination);
connection.start();
providerListener.onConnectionFailure(new IOException());
final JmsConnection jmsConnection = connection;
assertTrue(Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return !jmsConnection.isConnected();
}
}, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2)));
}
示例14: testSetExceptionListenerPassthrough
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Test
public void testSetExceptionListenerPassthrough() throws JMSException {
JmsConnection connection = Mockito.mock(JmsConnection.class);
JmsContext context = new JmsContext(connection, JMSContext.AUTO_ACKNOWLEDGE);
ExceptionListener listener = new ExceptionListener() {
@Override
public void onException(JMSException exception) {
}
};
try {
context.setExceptionListener(listener);
} finally {
context.close();
}
Mockito.verify(connection, Mockito.times(1)).setExceptionListener(listener);
}
示例15: testGlobalExceptionListenerIsAppliedToCreatedConnection
import javax.jms.ExceptionListener; //导入依赖的package包/类
@Test
public void testGlobalExceptionListenerIsAppliedToCreatedConnection() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(new URI("mock://127.0.0.1:5763"));
ExceptionListener listener = new ExceptionListener() {
@Override
public void onException(JMSException exception) {
}
};
factory.setExceptionListener(listener);
Connection connection = factory.createConnection();
assertNotNull(connection);
assertNotNull(connection.getExceptionListener());
assertSame(listener, connection.getExceptionListener());
connection.close();
}