From e6747ead9528e1302daa93706cdb547c3b8209c1 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Mon, 30 Jan 2006 16:59:01 +0000 Subject: [PATCH] patch and test case for AMQ-514 to make BrokerInfo and the broker name visible to an ActiveMQConnection git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@373548 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/ActiveMQConnection.java | 17 +++++++++++++++++ .../activemq/ActiveMQConnectionFactoryTest.java | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java index 8807b8a83f..ebce559ac5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -1214,6 +1214,23 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon return brokerInfo.getBrokerId().getValue(); } + /** + * Returns the broker name if one is available or null if one is not available yet. + */ + public String getBrokerName() { + if (brokerInfo == null) { + return null; + } + return brokerInfo.getBrokerName(); + } + + /** + * Returns the broker information if it is available or null if it is not available yet. + */ + public BrokerInfo getBrokerInfo() { + return brokerInfo; + } + /** * @return Returns the RedeliveryPolicy. * @throws JMSException diff --git a/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java b/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java index 1674e88a4f..a4ee51b1f3 100755 --- a/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java @@ -60,6 +60,18 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { assertNull( BrokerRegistry.getInstance().lookup("localhost") ); } + public void testGetBrokerName() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); + connection.start(); + + String brokerName = connection.getBrokerName(); + System.out.println("Got broker name: " + brokerName); + + assertNotNull("No broker name available!", brokerName); + connection.close(); + } + public void testCreateTcpConnectionUsingAllocatedPort() throws Exception { assertCreateConnection("tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true"); }