當前位置: 首頁>>代碼示例>>Java>>正文


Java ExceptionListener類代碼示例

本文整理匯總了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));
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:21,代碼來源:JmsPoolConnectionTest.java

示例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();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:26,代碼來源:PooledConnectionSecurityExceptionTest.java

示例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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:AbstractMessageListenerContainer.java

示例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);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:SingleConnectionFactory.java

示例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;
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:23,代碼來源:JMSClientTestSupport.java

示例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;
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:23,代碼來源:JMSClientTestSupport.java

示例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;
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:23,代碼來源:JMSClientTestSupport.java

示例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();

}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:ActiveMQConnectionFactoryTest.java

示例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();
}
 
開發者ID:pires,項目名稱:fabric8-amq-example,代碼行數:17,代碼來源:AMQClientImpl.java

示例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;
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:27,代碼來源:AbstractACLTestCase.java

示例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");
    }
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:23,代碼來源:ExceptionListenerTest.java

示例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;
}
 
開發者ID:apache,項目名稱:qpid-jms,代碼行數:27,代碼來源:JmsMessageConsumerFailedTest.java

示例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)));
}
 
開發者ID:apache,項目名稱:qpid-jms,代碼行數:27,代碼來源:JmsSessionFailedTest.java

示例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);
}
 
開發者ID:apache,項目名稱:qpid-jms,代碼行數:21,代碼來源:JmsContextTest.java

示例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();
}
 
開發者ID:apache,項目名稱:qpid-jms,代碼行數:20,代碼來源:JmsConnectionFactoryTest.java


注:本文中的javax.jms.ExceptionListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。