本文整理了Java中javax.jms.Connection.setExceptionListener()
方法的一些代码示例,展示了Connection.setExceptionListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.setExceptionListener()
方法的具体详情如下:
包路径:javax.jms.Connection
类名称:Connection
方法名:setExceptionListener
[英]Sets an exception listener for this connection.
If a JMS provider detects a serious problem with a connection, it informs the connection's ExceptionListener, if one has been registered. It does this by calling the listener's onException method, passing it a JMSExceptionobject describing the problem.
An exception listener allows a client to be notified of a problem asynchronously. Some connections only consume messages, so they would have no other way to learn their connection has failed.
A connection serializes execution of its ExceptionListener.
A JMS provider should attempt to resolve connection problems itself before it notifies the client of them.
This method must not be used in a Java EE web or EJB application. Doing so may cause a JMSException to be thrown though this is not guaranteed.
[中]设置此连接的异常侦听器。
如果JMS提供程序检测到连接存在严重问题,它会通知连接的ExceptionListener(如果已注册)。它通过调用侦听器的OneException方法来实现这一点,并向其传递一个描述问题的JMSExceptionobject。
异常侦听器允许异步通知客户机问题。有些连接只使用消息,因此它们没有其他方法来了解连接是否失败。
连接序列化其ExceptionListener的执行。
JMS提供程序应该在通知客户机连接问题之前尝试自行解决连接问题。
此方法不得用于JavaEEWeb或EJB应用程序中。这样做可能会导致抛出JMSException,但这并不能保证。
代码示例来源:origin: spring-projects/spring-framework
/**
* Registers this listener container as JMS ExceptionListener on the shared connection.
*/
@Override
protected void prepareSharedConnection(Connection connection) throws JMSException {
super.prepareSharedConnection(connection);
connection.setExceptionListener(this);
}
代码示例来源:origin: openzipkin/brave
@Override public void setExceptionListener(ExceptionListener listener) throws JMSException {
delegate.setExceptionListener(TracingExceptionListener.create(listener, jmsTracing));
}
代码示例来源:origin: apache/hive
/**
* Create the JMS connection
* @return newly created JMS connection
*/
protected Connection createConnection() {
LOG.info("Will create new JMS connection");
Context jndiCntxt;
Connection jmsConnection = null;
try {
jndiCntxt = new InitialContext();
ConnectionFactory connFac = (ConnectionFactory) jndiCntxt.lookup("ConnectionFactory");
jmsConnection = connFac.createConnection();
jmsConnection.start();
jmsConnection.setExceptionListener(new ExceptionListener() {
@Override
public void onException(JMSException jmse) {
LOG.error("JMS Exception listener received exception. Ignored the error", jmse);
}
});
} catch (NamingException e) {
LOG.error("JNDI error while setting up Message Bus connection. "
+ "Please make sure file named 'jndi.properties' is in "
+ "classpath and contains appropriate key-value pairs.", e);
} catch (JMSException e) {
LOG.error("Failed to initialize connection to message bus", e);
} catch (Throwable t) {
LOG.error("Unable to connect to JMS provider", t);
}
return jmsConnection;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* 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);
}
}
代码示例来源:origin: apache/ignite
connection.setExceptionListener(new IgniteJmsExceptionListener());
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithConnectionFactoryAndExceptionListener() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
ExceptionListener listener = new ChainedExceptionListener();
given(cf.createConnection()).willReturn(con);
given(con.getExceptionListener()).willReturn(listener);
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
scf.setExceptionListener(listener);
Connection con1 = scf.createConnection();
assertEquals(listener, con1.getExceptionListener());
con1.start();
con1.stop();
con1.close();
Connection con2 = scf.createConnection();
con2.start();
con2.stop();
con2.close();
scf.destroy(); // should trigger actual close
verify(con).setExceptionListener(listener);
verify(con, times(2)).start();
verify(con, times(2)).stop();
verify(con).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextRefreshedEventStartsTheConnectionByDefault() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(),
this.container.getSessionAcknowledgeMode())).willReturn(session);
// and the connection is start()ed after the listener is registered...
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.afterPropertiesSet();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
verify(connection).setExceptionListener(this.container);
verify(connection).start();
}
代码示例来源:origin: spring-projects/spring-framework
verify(connection).setExceptionListener(this.container);
verify(connection).start();
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testDestroyClosesConsumersSessionsAndConnectionInThatOrder() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(),
this.container.getSessionAcknowledgeMode())).willReturn(session);
// and the connection is start()ed after the listener is registered...
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.afterPropertiesSet();
this.container.start();
this.container.destroy();
verify(messageConsumer).close();
verify(session).close();
verify(connection).setExceptionListener(this.container);
verify(connection).start();
verify(connection).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextRefreshedEventDoesNotStartTheConnectionIfAutoStartIsSetToFalse() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(),
this.container.getSessionAcknowledgeMode())).willReturn(session);
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.setAutoStartup(false);
this.container.afterPropertiesSet();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
verify(connection).setExceptionListener(this.container);
}
代码示例来源:origin: spring-projects/spring-framework
verify(connection).setExceptionListener(this.container);
verify(connection).start();
代码示例来源:origin: spring-projects/spring-framework
verify(connection).setExceptionListener(this.container);
verify(connection).start();
verify(errorHandler).handleError(theException);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testWithConnectionFactoryAndLocalExceptionListenerWithReconnect() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
TestConnection con = new TestConnection();
given(cf.createConnection()).willReturn(con);
TestExceptionListener listener0 = new TestExceptionListener();
TestExceptionListener listener1 = new TestExceptionListener();
TestExceptionListener listener2 = new TestExceptionListener();
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
scf.setReconnectOnException(true);
scf.setExceptionListener(listener0);
Connection con1 = scf.createConnection();
con1.setExceptionListener(listener1);
assertSame(listener1, con1.getExceptionListener());
con1.start();
Connection con2 = scf.createConnection();
con2.setExceptionListener(listener2);
assertSame(listener2, con2.getExceptionListener());
con.getExceptionListener().onException(new JMSException(""));
con2.close();
con1.getMetaData();
con.getExceptionListener().onException(new JMSException(""));
con1.close();
scf.destroy(); // should trigger actual close
assertEquals(2, con.getStartCount());
assertEquals(2, con.getCloseCount());
assertEquals(2, listener0.getCount());
assertEquals(2, listener1.getCount());
assertEquals(1, listener2.getCount());
}
代码示例来源:origin: spring-projects/spring-framework
verify(connection).setExceptionListener(this.container);
verify(connection).start();
代码示例来源:origin: spring-projects/spring-framework
verify(connection).setExceptionListener(this.container);
verify(connection).start();
verify(exceptionListener).onException(theException);
代码示例来源:origin: spring-projects/spring-framework
scf.setExceptionListener(listener0);
Connection con1 = scf.createConnection();
con1.setExceptionListener(listener1);
assertSame(listener1, con1.getExceptionListener());
Connection con2 = scf.createConnection();
con2.setExceptionListener(listener2);
assertSame(listener2, con2.getExceptionListener());
con.getExceptionListener().onException(new JMSException(""));
代码示例来源:origin: spring-projects/spring-framework
assertTrue(listener.listenerInvoked);
verify(connection).setExceptionListener(this.container);
verify(connection).start();
代码示例来源:origin: org.springframework/org.springframework.jms
/**
* Registers this listener container as JMS ExceptionListener on the shared connection.
*/
@Override
protected void prepareSharedConnection(Connection connection) throws JMSException {
super.prepareSharedConnection(connection);
connection.setExceptionListener(this);
}
代码示例来源:origin: org.uberfire/uberfire-commons
@Test
public void connectTestEmptyUserNameAndPassword() throws JMSException {
clusterService.connect();
verify(connection).setExceptionListener(any());
verify(connection).start();
verify(factory).createConnection();
}
代码示例来源:origin: org.uberfire/uberfire-commons
@Test
public void connectTest() throws JMSException {
System.setProperty(ClusterParameters.APPFORMER_JMS_USERNAME, "dora");
System.setProperty(ClusterParameters.APPFORMER_JMS_PASSWORD, "bento");
clusterService = getClusterService(factory);
clusterService.connect();
verify(connection).setExceptionListener(any());
verify(connection).start();
verify(factory).createConnection(any(), any());
}
内容来源于网络,如有侵权,请联系作者删除!