Author: ritchiem
Date: Tue Nov 7 05:36:47 2006
New Revision: 472108
URL: http://svn.apache.org/viewvc?view=rev&rev=472108
Log:
Added attempt to unbind if an error occurs.
Modified:
incubator/qpid/trunk/qpid/java/client/src/org/apache/qpid/client/transport/TransportConnection.java
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
Modified:
incubator/qpid/trunk/qpid/java/client/src/org/apache/qpid/client/transport/TransportConnection.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/org/apache/qpid/client/transport/TransportConnection.java?view=diff&rev=472108&r1=472107&r2=472108
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/src/org/apache/qpid/client/transport/TransportConnection.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/src/org/apache/qpid/client/transport/TransportConnection.java
Tue Nov 7 05:36:47 2006
@@ -187,38 +187,40 @@
if (!_inVmPipeAddress.containsKey(port))
{
_logger.info("Creating InVM Qpid.AMQP listening on port " + port);
-
+ IoHandlerAdapter provider = null;
try
{
VmPipeAddress pipe = new VmPipeAddress(port);
- String protocolProviderClass =
System.getProperty("amqj.protocolprovider.class", DEFAULT_QPID_SERVER);
- _logger.info("Creating Qpid protocol provider: " +
protocolProviderClass);
+ provider = createBrokerInstance(port);
- // can't use introspection to get Provider as it is a server
class.
- // need to go straight to IoHandlerAdapter but that requries
the queues and exchange from the ApplicationRegistry which we can't access.
+ _acceptor.bind(pipe, provider);
- //get right constructor and pass in instancec ID - "port"
- IoHandlerAdapter provider;
+ _inVmPipeAddress.put(port, pipe);
+ _logger.info("Created InVM Qpid.AMQP listening on port " +
port);
+ }
+ catch (IOException e)
+ {
+ _logger.error(e);
+
+ //Try and unbind provider
try
{
- Class[] cnstr = {Integer.class};
- Object[] params = {port};
- provider = (IoHandlerAdapter)
Class.forName(protocolProviderClass).getConstructor(cnstr).newInstance(params);
- //Give the broker a second to create
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
+ VmPipeAddress pipe = new VmPipeAddress(port);
+
+ _acceptor.unbind(pipe);
+
+ if (provider == null)
{
- //do nothing
+ provider = createBrokerInstance(port);
}
+
+ _acceptor.bind(pipe, provider);
+ _inVmPipeAddress.put(port, pipe);
+ _logger.info("Created InVM Qpid.AMQP listening on port " +
port);
}
- catch (Exception e)
+ catch (IOException justUseFirstException)
{
- _logger.info("Unable to create InVM Qpid.AMQP on port " +
port + ". Because: " + e.getCause());
- _logger.error(e);
String because;
if (e.getCause() == null)
{
@@ -229,37 +231,61 @@
because = e.getCause().toString();
}
-
- throw new AMQVMBrokerCreationException(port, because + "
Stopped InVM Qpid.AMQP creation");
+ throw new AMQVMBrokerCreationException(port, because + "
Stopped binding of InVM Qpid.AMQP");
}
+ }
+ }
+ else
+ {
+ _logger.info("InVM Qpid.AMQP on port " + port + " already exits.");
+ }
- _acceptor.bind(pipe, provider);
+ }
- _inVmPipeAddress.put(port, pipe);
- _logger.info("Created InVM Qpid.AMQP listening on port " +
port);
+ private static IoHandlerAdapter createBrokerInstance(int port) throws
AMQVMBrokerCreationException
+ {
+ String protocolProviderClass =
System.getProperty("amqj.protocolprovider.class", DEFAULT_QPID_SERVER);
+ _logger.info("Creating Qpid protocol provider: " +
protocolProviderClass);
+
+ // can't use introspection to get Provider as it is a server class.
+ // need to go straight to IoHandlerAdapter but that requries the
queues and exchange from the ApplicationRegistry which we can't access.
+
+ //get right constructor and pass in instancec ID - "port"
+ IoHandlerAdapter provider;
+ try
+ {
+ Class[] cnstr = {Integer.class};
+ Object[] params = {port};
+ provider = (IoHandlerAdapter)
Class.forName(protocolProviderClass).getConstructor(cnstr).newInstance(params);
+ //Give the broker a second to create
+ try
+ {
+ Thread.sleep(1000);
}
- catch (IOException e)
+ catch (InterruptedException e)
{
- _logger.error(e);
-
- String because;
- if (e.getCause() == null)
- {
- because = e.toString();
- }
- else
- {
- because = e.getCause().toString();
- }
-
- throw new AMQVMBrokerCreationException(port, because + "
Stopped binding of InVM Qpid.AMQP");
+ //do nothing
}
}
- else
+ catch (Exception e)
{
- _logger.info("InVM Qpid.AMQP on port " + port + " already exits.");
+ _logger.info("Unable to create InVM Qpid.AMQP on port " + port +
". Because: " + e.getCause());
+ _logger.error(e);
+ String because;
+ if (e.getCause() == null)
+ {
+ because = e.toString();
+ }
+ else
+ {
+ because = e.getCause().toString();
+ }
+
+
+ throw new AMQVMBrokerCreationException(port, because + " Stopped
InVM Qpid.AMQP creation");
}
+ return provider;
}
public static void killAllVMBrokers()
Modified:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java?view=diff&rev=472108&r1=472107&r2=472108
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java
Tue Nov 7 05:36:47 2006
@@ -30,6 +30,7 @@
import org.junit.Test;
import org.junit.Assert;
import org.junit.BeforeClass;
+import org.junit.AfterClass;
import javax.jms.*;
@@ -53,13 +54,7 @@
private MessageConsumer testConsumer2;
@BeforeClass
- public static void setupVM()
- {
- System.setProperty("amqj.NoAutoCreateVMBroker", "true");
- }
-
- @Before
- public void setup() throws Exception
+ public static void setupBeforeClass()
{
try
{
@@ -69,6 +64,18 @@
{
Assert.fail("Unable to create VM Broker: " + e.getMessage());
}
+ }
+
+ @AfterClass
+ public static void setupAfterClass()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Before
+ public void setup() throws Exception
+ {
+
queue1 = new AMQQueue("Q1", false);
queue2 = new AMQQueue("Q2", false);
@@ -115,8 +122,6 @@
con.close();
testCon.close();
prepCon.close();
-
- TransportConnection.killVMBroker(1);
}
@Test