Author: jmesnil
Date: 2010-05-21 08:52:44 -0400 (Fri, 21 May 2010)
New Revision: 9250
Modified:
trunk/src/main/org/hornetq/ra/inflow/HornetQActivation.java
Log:
Resource Adapter Activation setup
* try to setup the HornetQActivation multiple times in case the JMS resources have not
been deployed
by the AS before the MDB is activated
Modified: trunk/src/main/org/hornetq/ra/inflow/HornetQActivation.java
===================================================================
--- trunk/src/main/org/hornetq/ra/inflow/HornetQActivation.java 2010-05-20 12:48:35 UTC
(rev 9249)
+++ trunk/src/main/org/hornetq/ra/inflow/HornetQActivation.java 2010-05-21 12:52:44 UTC
(rev 9250)
@@ -102,6 +102,13 @@
private HornetQConnectionFactory factory;
+ // Whether we are in the failure recovery loop
+ private AtomicBoolean inFailure = new AtomicBoolean(false);
+
+ private final int setupAttempts = 5;
+
+ private final long setupInterval = 10 * 1000;
+
static
{
try
@@ -492,6 +499,56 @@
}
/**
+ * Handles any failure by trying to reconnect
+ *
+ * @param failure the reason for the failure
+ */
+ public void handleFailure(Throwable failure)
+ {
+ log.warn("Failure in HornetQ activation " + spec, failure);
+ int reconnectCount = 0;
+
+ // Only enter the failure loop once
+ if (inFailure.getAndSet(true))
+ return;
+ try
+ {
+ while (deliveryActive.get() && reconnectCount < setupAttempts)
+ {
+ teardown();
+
+ try
+ {
+ Thread.sleep(setupInterval);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("Interrupted trying to reconnect " + spec, e);
+ break;
+ }
+
+ log.info("Attempting to reconnect " + spec);
+ try
+ {
+ setup();
+ log.info("Reconnected with HornetQ");
+ break;
+ }
+ catch (Throwable t)
+ {
+ log.error("Unable to reconnect " + spec, t);
+ }
+ ++reconnectCount;
+ }
+ }
+ finally
+ {
+ // Leaving failure recovery loop
+ inFailure.set(false);
+ }
+ }
+
+ /**
* Handles the setup
*/
private class SetupActivation implements Work
@@ -504,7 +561,7 @@
}
catch (Throwable t)
{
- HornetQActivation.log.error("Unable to start activation ", t);
+ handleFailure(t);
}
}
Show replies by date