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


Java QueueConnection.setExceptionListener方法代碼示例

本文整理匯總了Java中javax.jms.QueueConnection.setExceptionListener方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueConnection.setExceptionListener方法的具體用法?Java QueueConnection.setExceptionListener怎麽用?Java QueueConnection.setExceptionListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.QueueConnection的用法示例。


在下文中一共展示了QueueConnection.setExceptionListener方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createQueueConnection

import javax.jms.QueueConnection; //導入方法依賴的package包/類
private QueueConnection createQueueConnection() throws Exception
{
    QueueConnection connection;
    if (isRemote())
        connection = TestUtils.openRemoteQueueConnection();
    else
        connection = TestUtils.openLocalQueueConnection();
    
    connection.setExceptionListener(this);
    
    return connection;
}
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:13,代碼來源:AbstractCommTest.java

示例2: main

import javax.jms.QueueConnection; //導入方法依賴的package包/類
public static void main(final String[] args) throws Exception {
   QueueConnection connection = null;
   InitialContext initialContext = null;
   try {
      // Step 1. Create an initial context to perform the JNDI lookup.
      initialContext = new InitialContext();

      // Step 2. Perform a lookup on the Connection Factory
      QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("ConnectionFactory");

      // Step 3.Create a JMS Connection
      connection = cf.createQueueConnection();

      // Step 4. Set an exception listener on the connection to be notified after a problem occurred
      final AtomicReference<JMSException> exception = new AtomicReference<>();
      connection.setExceptionListener(new ExceptionListener() {
         @Override
         public void onException(final JMSException e) {
            exception.set(e);
         }
      });

      // Step 5. We start the connection
      connection.start();

      // Step 6. Create an ActiveMQServerControlMBean proxy to manage the server
      ObjectName on = ObjectNameBuilder.DEFAULT.getActiveMQServerObjectName();
      JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>());
      MBeanServerConnection mbsc = connector.getMBeanServerConnection();
      ActiveMQServerControl serverControl = MBeanServerInvocationHandler.newProxyInstance(mbsc, on, ActiveMQServerControl.class, false);

      // Step 7. List the remote address connected to the server
      System.out.println("List of remote addresses connected to the server:");
      System.out.println("----------------------------------");
      String[] remoteAddresses = serverControl.listRemoteAddresses();
      for (String remoteAddress : remoteAddresses) {
         System.out.println(remoteAddress);
      }
      System.out.println("----------------------------------");

      // Step 8. Close the connections for the 1st remote address and kickoff the client
      serverControl.closeConnectionsForAddress(remoteAddresses[0]);

      // Sleep a little bit so that the stack trace from the server won't be
      // mingled with the JMSException received on the ExceptionListener
      Thread.sleep(1000);

      // Step 9. Display the exception received by the connection's ExceptionListener
      System.err.println("\nException received from the server:");
      System.err.println("----------------------------------");
      exception.get().printStackTrace();
      System.err.println("----------------------------------");
   } finally {
      // Step 10. Be sure to close the resources!
      if (initialContext != null) {
         initialContext.close();
      }
      if (connection != null) {
         connection.close();
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:63,代碼來源:ClientKickoffExample.java

示例3: runExample

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Override
public boolean runExample() throws Exception
{
    QueueConnection connection = null;
    InitialContext initialContext = null;
    try
    {
        // Step 1. Create an initial context to perform the JNDI lookup.
        initialContext = getContext(0);

        QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("/ConnectionFactory");

        connection = cf.createQueueConnection();

        final AtomicReference<JMSException> exception = new AtomicReference<JMSException>();
        connection.setExceptionListener(new ExceptionListener()
        {
            @Override
            public void onException(final JMSException e)
            {
                exception.set(e);
            }
        });

        connection.start();

        ObjectName on = ObjectNameBuilder.DEFAULT.getHornetQServerObjectName();
        JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), new HashMap<String, String>());
        MBeanServerConnection mbsc = connector.getMBeanServerConnection();
        HornetQServerControl serverControl = MBeanServerInvocationHandler.newProxyInstance(mbsc,
                    on,
                    HornetQServerControl.class,
                    false);

        System.out.println("List of remote addresses connected to the server:");
        System.out.println("----------------------------------");
        String[] remoteAddresses = serverControl.listRemoteAddresses();
        for (String remoteAddress : remoteAddresses)
        {
            System.out.println(remoteAddress);
        }
        System.out.println("----------------------------------");

        serverControl.closeConnectionsForAddress(remoteAddresses[0]);

        Thread.sleep(1000);

        System.err.println("\nException received from the server:");
        System.err.println("----------------------------------");
        exception.get().printStackTrace();
        System.err.println("----------------------------------");

        return true;
    }
    finally
    {
        // Step 10. Be sure to close the resources!
        if (initialContext != null)
        {
            initialContext.close();
        }
        if (connection != null)
        {
            connection.close();
        }
    }
}
 
開發者ID:windup,項目名稱:windup-rulesets,代碼行數:68,代碼來源:ClientKickOffExample.java


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