[jboss-cvs] JBoss Messaging SVN: r2802 - in trunk: tests/src/org/jboss/test/messaging/jms/bridge and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 26 05:02:01 EDT 2007
Author: sergeypk
Date: 2007-06-26 05:02:00 -0400 (Tue, 26 Jun 2007)
New Revision: 2802
Modified:
trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
trunk/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-999 - improved so that start() does not block if the connections cannot be established immediately.
Modified: trunk/src/main/org/jboss/jms/server/bridge/Bridge.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/bridge/Bridge.java 2007-06-26 06:43:13 UTC (rev 2801)
+++ trunk/src/main/org/jboss/jms/server/bridge/Bridge.java 2007-06-26 09:02:00 UTC (rev 2802)
@@ -280,7 +280,7 @@
{
toResume = tm.suspend();
- ok = setupJMSObjectsWithRetry();
+ ok = setupJMSObjects();
}
finally
{
@@ -318,8 +318,7 @@
else
{
log.warn("Failed to start bridge");
-
- failed = true;
+ handleFailureOnStartup();
}
}
@@ -1230,17 +1229,29 @@
{
log.warn("Failed to send + acknowledge batch, closing JMS objects", e);
- handleFailure();
+ handleFailureOnSend();
}
}
- private void handleFailure()
+ private void handleFailureOnSend()
{
+ handleFailure(new FailureHandler());
+ }
+
+ private void handleFailureOnStartup()
+ {
+ handleFailure(new StartupFailureHandler());
+ }
+
+ private void handleFailure(Runnable failureHandler)
+ {
failed = true;
- //Failure must be handled on a separate thread to the onMessage thread since we can't close the connection
- //from inside the onMessage method since it will block waiting for onMessage to complete
- Thread t = new Thread(new FailureHandler());
+ //Failure must be handled on a separate thread to the calling thread (either onMessage or start).
+ //In the case of onMessage we can't close the connection from inside the onMessage method
+ //since it will block waiting for onMessage to complete. In the case of start we want to return
+ //from the call before the connections are reestablished so that the caller is not blocked unnecessarily.
+ Thread t = new Thread(failureHandler);
t.start();
}
@@ -1249,13 +1260,55 @@
private class FailureHandler implements Runnable
{
+ /**
+ * Start the source connection - note the source connection must not be started before
+ * otherwise messages will be received and ignored
+ */
+ protected void startSourceConnection()
+ {
+ try
+ {
+ sourceConn.start();
+ }
+ catch (JMSException e)
+ {
+ log.error("Failed to start source connection", e);
+ }
+ }
+
+ protected void succeeded()
+ {
+ log.debug("Succeeded in reconnecting to servers");
+
+ synchronized (lock)
+ {
+ failed = false;
+
+ startSourceConnection();
+ }
+ }
+
+ protected void failed()
+ {
+ //We haven't managed to recreate connections or maxRetries = 0
+ log.warn("Unable to set up connections, bridge will be stopped");
+
+ try
+ {
+ stop();
+ }
+ catch (Exception ignore)
+ {
+ }
+ }
+
public void run()
{
if (trace) { log.trace("Failure handler running"); }
// Clear the messages
messages.clear();
-
+
cleanup();
boolean ok = false;
@@ -1272,38 +1325,45 @@
if (!ok)
{
- //We haven't managed to recreate connections or maxRetries = 0
- log.warn("Unable to set up connections, bridge will be stopped");
-
- try
- {
- stop();
- }
- catch (Exception ignore)
- {
- }
+ failed();
}
else
{
- log.debug("Succeeded in reconnecting to servers");
+ succeeded();
+ }
+ }
+ }
+
+ private class StartupFailureHandler extends FailureHandler
+ {
+ protected void failed()
+ {
+ // Don't call super
+ log.warn("Unable to set up connections, bridge will not be started");
+ }
+
+ protected void succeeded()
+ {
+ // Don't call super - a bit ugly in this case but better than taking the lock twice.
+ log.debug("Succeeded in connecting to servers");
+
+ synchronized (lock)
+ {
+ failed = false;
+ started = true;
- synchronized (lock)
+ //Start the source connection - note the source connection must not be started before
+ //otherwise messages will be received and ignored
+
+ try
{
- failed = false;
-
- //Start the source connection - note the source connection must not be started before
- //otherwise messages will be received and ignored
-
- try
- {
- sourceConn.start();
- }
- catch (JMSException e)
- {
- log.error("Failed to start source connection", e);
- }
+ sourceConn.start();
}
- }
+ catch (JMSException e)
+ {
+ log.error("Failed to start source connection", e);
+ }
+ }
}
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java 2007-06-26 06:43:13 UTC (rev 2801)
+++ trunk/tests/src/org/jboss/test/messaging/jms/bridge/ReconnectTest.java 2007-06-26 09:02:00 UTC (rev 2802)
@@ -116,7 +116,6 @@
{
setUpAdministeredObjects(true);
ServerManagement.kill(1);
- Thread.sleep(5000);
Bridge bridge = new Bridge(cff0, cff1, sourceQueue, destQueue,
null, null, null, null,
@@ -124,33 +123,15 @@
10, -1,
null, null);
- new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- Thread.sleep(2000);
- }
- catch (InterruptedException e)
- {
- log.debug("Server startup thread interrupted while sleeping", e);
- }
-
- try
- {
- ServerManagement.start(1, "all", false);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to start server", e);
- }
- }
- }).start();
-
try
{
bridge.start();
+ assertFalse(bridge.isStarted());
+ assertTrue(bridge.isFailed());
+
+ ServerManagement.start(1, "all", false);
+ Thread.sleep(3000);
+
assertTrue(bridge.isStarted());
assertFalse(bridge.isFailed());
}
More information about the jboss-cvs-commits
mailing list