本文整理匯總了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;
}
示例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();
}
}
}
示例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();
}
}
}