[jboss-svn-commits] JBL Code SVN: r23596 - labs/jbosstm/trunk/XTS/WS-C/dev/src/com/arjuna/services/framework/startup.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 27 10:53:42 EDT 2008
Author: adinn
Date: 2008-10-27 10:53:42 -0400 (Mon, 27 Oct 2008)
New Revision: 23596
Modified:
labs/jbosstm/trunk/XTS/WS-C/dev/src/com/arjuna/services/framework/startup/Sequencer.java
Log:
modified the sequencer latch which assumed (wrongly) that XTS start which lifts the latch happened in a different thread to war listener init code and hence was deadlocking itself if the XTS start got run after the listeners. the sequencer code now defers callback execution if the latch is in place and the latch lift code runs deferred callbacks when it lifts th elatch, thus ensuring that the latch lifter can complete initialisaton before any sequencer callbacks run.
Modified: labs/jbosstm/trunk/XTS/WS-C/dev/src/com/arjuna/services/framework/startup/Sequencer.java
===================================================================
--- labs/jbosstm/trunk/XTS/WS-C/dev/src/com/arjuna/services/framework/startup/Sequencer.java 2008-10-27 10:34:36 UTC (rev 23595)
+++ labs/jbosstm/trunk/XTS/WS-C/dev/src/com/arjuna/services/framework/startup/Sequencer.java 2008-10-27 14:53:42 UTC (rev 23596)
@@ -17,6 +17,11 @@
* triggered, thus ensuring that callbacks for web apps with lower sequence indices complete before callbacks with
* higher indices are called.
*
+ * This version also includes a global latch which can be used to ensure that no callbacks are not processed until a
+ * client lifts the latch. If the latch has already been lifted when the final element of a sequencer is closed the
+ * callbacks are run straight away. If the latch is closed then the sequencer is installed in a deferred list. When
+ * the latch is lifted the deferred list is scanned and callbacks are run for each sequencer found in the list.
+ *
* User: adinn
* Date: Nov 30, 2007
* Time: 4:05:13 PM
@@ -133,19 +138,26 @@
/**
* undo the latch which initially delays running of any callback sequences. this is provided
* to enable the Service start routine to configure any necessary parameters before the
- * listener callbacks are run. It is synchronized on the class so we can safely notify any
- * threads waiting to pass the latch which will be waiting on the Sequencer.class.
+ * listener callbacks are run.
*/
- public static synchronized void unlatch()
+ public static void unlatch()
{
- latched = false;
- Sequencer.class.notifyAll();
+ synchronized (Sequencer.class) {
+ latched = false;
+ }
+
+ Iterator<Sequencer> iterator = deferred.iterator();
+
+ while (iterator.hasNext()) {
+ Sequencer sequencer = iterator.next();
+ sequencer.runCallbacks();
+ }
}
// private implementation
/**
- * a global latch used to delay running of callbacks until the XTS servcie is ready to
+ * a global latch used to defer running of callbacks until the XTS service is ready to
* let them run
*/
private static boolean latched = true;
@@ -159,7 +171,14 @@
new Sequencer(WEBAPP_MAX11)
};
+
/**
+ * a list of sequencers for which invocation of callbacks has been deferred pending lifting of the sequencer latch
+ */
+
+ private static List<Sequencer> deferred = new ArrayList<Sequencer>();
+
+ /**
* method called by the Callback constructor to append a startup callback to the list for a web
* app in the appropriate startup sequence
* @param callback a callback to add to the list for the web app
@@ -220,9 +239,16 @@
private void runCallbacks()
{
- // we cannot run the callbacks until the sequencer has been unlatched
- passLatch();
+ // if the latch is lifted then run the callbacks otherwise defer them for the
+ // thread which raises the latch to run
+ synchronized(Sequencer.class) {
+ if (latched) {
+ deferred.add(this);
+ return;
+ }
+ }
+
for (int i = 0; i < sequenceSize; i++) {
Iterator<Callback> iter = callbacks[i].iterator();
while (iter.hasNext()) {
@@ -233,20 +259,6 @@
}
/**
- * do not return until the latch has been lifted
- */
- private static synchronized void passLatch()
- {
- while (latched) {
- try {
- Sequencer.class.wait();
- } catch (InterruptedException e) {
- // ignore
- }
- }
- }
-
- /**
* construct a Sequencer to manage registration and execution of callbacks associated with an ordered sequence
* of web apps
* @param sequenceSize count of the number of web apps for which callbacks are to be registered
More information about the jboss-svn-commits
mailing list