[jboss-svn-commits] JBL Code SVN: r25847 - in labs/jbosstm/workspace/adinn/orchestration: src/org/jboss/jbossts/orchestration/agent and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 27 07:13:53 EDT 2009
Author: adinn
Date: 2009-03-27 07:13:53 -0400 (Fri, 27 Mar 2009)
New Revision: 25847
Added:
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Rendezvous.java
Modified:
labs/jbosstm/workspace/adinn/orchestration/docs/ProgrammersGuide.odt
labs/jbosstm/workspace/adinn/orchestration/docs/ProgrammersGuide.pdf
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/helper/Helper.java
Log:
added rendezvous operations to Helper and documented them. also corrected operation of debug builtin to respect system property settings as advertised in the documentation
Modified: labs/jbosstm/workspace/adinn/orchestration/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)
Modified: labs/jbosstm/workspace/adinn/orchestration/docs/ProgrammersGuide.pdf
===================================================================
(Binary files differ)
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java 2009-03-27 05:52:01 UTC (rev 25846)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java 2009-03-27 11:13:53 UTC (rev 25847)
@@ -363,6 +363,11 @@
public static final String VERBOSE = ORCHESTRATION_PACKAGE_PREFIX + "verbose";
/**
+ * system property set (to any value) in order to switch on debug statements in the default Helper
+ */
+
+ public static final String DEBUG = ORCHESTRATION_PACKAGE_PREFIX + "debug";
+ /**
* system property set (to any value) in order to switch on compilation of rules and left unset
* if rules are to be interpreted.
*/
@@ -414,8 +419,10 @@
System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error processing rule " + ruleName + " : " + th);
return targetClassBytes;
}
- System.out.println(rule);
-
+ if (isVerbose()) {
+ System.out.println(rule);
+ }
+
// ok, we have a rule with a matchingclass and a candidiate method and location
// we need to see if the class has a matching method and, if so, add a call to
// execute the rule when we hit the relevant line
@@ -476,6 +483,15 @@
}
/**
+ * check whether debug mode for rule processing is enabled or disabled
+ * @return true if debug mode is enabled or verbose mode is enabled otherwise false
+ */
+ public static boolean isDebug()
+ {
+ return debug || verbose;
+ }
+
+ /**
* check whether compilation of rules is enabled or disabled
* @return true if compilation of rules is enabled etherwise false
*/
@@ -521,6 +537,11 @@
/**
* switch to control verbose output during rule processing
*/
+ private final static boolean debug = (System.getProperty(DEBUG) != null);
+
+ /**
+ * switch to control verbose output during rule processing
+ */
private final static boolean compileToBytecode = (System.getProperty(COMPILE_TO_BYTECODE) != null);
/**
Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/helper/Helper.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/helper/Helper.java 2009-03-27 05:52:01 UTC (rev 25846)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/helper/Helper.java 2009-03-27 11:13:53 UTC (rev 25847)
@@ -28,6 +28,8 @@
import org.jboss.jbossts.orchestration.synchronization.CountDown;
import org.jboss.jbossts.orchestration.synchronization.Counter;
import org.jboss.jbossts.orchestration.synchronization.Waiter;
+import org.jboss.jbossts.orchestration.synchronization.Rendezvous;
+import org.jboss.jbossts.orchestration.agent.Transformer;
import java.io.*;
import java.util.HashMap;
@@ -60,7 +62,9 @@
*/
public boolean debug(String text)
{
- System.out.println("rule.debug{" + rule.getName() + "} : " + text);
+ if (Transformer.isDebug()) {
+ System.out.println("rule.debug{" + rule.getName() + "} : " + text);
+ }
return true;
}
@@ -515,7 +519,116 @@
return createCounter(o, 0);
}
+ // rendezvous support
/**
+ * call createRendezvous(Object, int, boolean) supplying false for the last parameter
+ * @param identifier an identifier for the rendezvous
+ * @param expected the number of threads expected to meet at the rendezvous
+ * @return true if the rendezvous is created or false if a rendezvous identified by identifier already exists
+ */
+ public boolean createRendezvous(Object identifier, int expected)
+ {
+ return createRendezvous(identifier, expected, false);
+ }
+
+ /**
+ * create a rendezvous for a given number of threads to join
+ * @param identifier an identifier for the rendezvious in subsequent rendezvous operations
+ * @param expected
+ * @param restartable
+ * @return
+ */
+ public boolean createRendezvous(Object identifier, int expected, boolean restartable)
+ {
+ // need to do this atomically
+ synchronized (rendezvousMap) {
+ Rendezvous rendezvous = rendezvousMap.get(identifier);
+ if (rendezvous != null) {
+ return false;
+ }
+ rendezvous = new Rendezvous(expected, restartable);
+ rendezvousMap.put(identifier, rendezvous);
+ }
+
+ return true;
+ }
+
+ /**
+ * test whether a rendezvous with a specific expected count is associated with identifier
+ * @param identifier the identifier for the rendezvous
+ * @param expected the number of threads expected to meet at the rendezvous
+ * @return the numer of threads currently arrived at the rendezvous
+ */
+ public int getRendezvous(Object identifier, int expected)
+ {
+ Rendezvous rendezvous = rendezvousMap.get(identifier);
+ if (rendezvous == null || rendezvous.getExpected() != expected) {
+ return -1;
+ }
+
+ return rendezvous.getArrived();
+ }
+
+ /**
+ * meet other threads at a given rendezvous retrunign only when the expected number have arrived
+ * @param identifier the identifier for the rendezvous
+ * @return an ordinal which sorts all parties to the rendezvous in order of arrival from 0 to
+ * (expected-1) or -1 if the rendezvous does not exist
+ */
+ public int rendezvous(Object identifier)
+ {
+ // we don't need to (cannot) synch on the map here although the reasoning is subtle
+ // the last thread in will reset the rendezvous if it is rejoinable in which case
+ // it stays in the map anyway. if it is not rejoinable then any thread which finds it in
+ // the map will return -1 if it is calling rendezvous -- i.e. this is the same as if it was
+ // not present. if a thread calls createRendezvous with the same identifier then this might
+ // make a difference but in that case either the rendezvous should be created rejoinable or
+ // the last thread out should be responsible for recreating the rendezvous.
+
+ Rendezvous rendezvous = rendezvousMap.get(identifier);
+ if (rendezvous != null) {
+ int result = rendezvous.rendezvous();
+ if (result == rendezvous.getExpected() && !rendezvous.isRejoinable()) {
+ rendezvousMap.remove(identifier);
+ }
+
+ return result;
+ }
+
+ return -1;
+ }
+
+ /*
+ * hmm, maybe we need this and maybe not
+ *
+ * terminate a rendezvous, waking any threads which are waiting and resetting the arrived count to zero. If the
+ * rendezous is not restartable then it also gets removed from the rendezvous map. All threads waiting inside
+ * a call to rendezvous return result -1;
+ * @param identifier
+ * @param expected
+ * @return
+
+ public int resetRendezvous(Object identifier)
+ {
+ }
+ */
+
+ /*
+ * hmm, maybe we need this and maybe not
+ *
+ * delete a rendezvous, waking any threads which are waiting and resetting the arrived count to zero. All
+ * threads waiting inside a call to rendezvous return result -1;
+ * @param identifier
+ * @param expected
+ * @return
+ public int deleteRendezvous(Object identifier)
+ {
+ }
+ */
+
+
+ // counter support
+ /**
* create a counter identified by the given object with the supplied value as its iniital count
* @param o an identifier used to refer to the counter in future
* @param value the initial value for the counter
@@ -735,4 +848,9 @@
*/
private static HashMap<Object, Waiter> waitMap = new HashMap<Object, Waiter>();
+ /**
+ * a hash map used to identify rendezvous from their identifying objects
+ */
+ private static HashMap<Object, Rendezvous> rendezvousMap = new HashMap<Object, Rendezvous>();
+
}
Copied: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Rendezvous.java (from rev 25818, labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Waiter.java)
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Rendezvous.java (rev 0)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Rendezvous.java 2009-03-27 11:13:53 UTC (rev 25847)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*
+* @authors Andrew Dinn
+*/
+package org.jboss.jbossts.orchestration.synchronization;
+
+import org.jboss.jbossts.orchestration.rule.exception.ExecuteException;
+
+/**
+ * class used to manage rule rendezvous operations
+ */
+public class Rendezvous
+{
+ public Rendezvous(int expected)
+ {
+ this(expected, false);
+ }
+
+ public Rendezvous(int expected, boolean rejoinable)
+ {
+ this.expected = expected;
+ this.arrived = 0;
+ this.rejoinable = rejoinable;
+ }
+
+ public int rendezvous()
+ {
+ synchronized(this) {
+ int index = arrived++;
+ if (arrived < expected) {
+ try {
+ this.wait();
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ } else {
+ if (rejoinable) {
+ // the last one in needs to set the count back to zero while it has the lock
+ // this makes sure that any of the existing threads or any new thread trying
+ // to re-enter the rendezvous will not fail to suspend
+ arrived = 0;
+ }
+ this.notifyAll();
+ }
+ return index;
+ }
+ }
+
+ public int getExpected() {
+ return expected;
+ }
+ /**
+ * the number of threads which are expected to arrive at this rendezvous
+ */
+ private int expected;
+
+ /**
+ * the number of threads which have arrive at this rendezvous so far
+ */
+ private int arrived;
+ /**
+ * true if this rendezvous can be repeatedly joined, false it it is a one-off meeting
+ */
+ private boolean rejoinable;
+
+ public boolean isRejoinable() {
+ return rejoinable;
+ }
+
+ public int getArrived() {
+ return arrived;
+ }
+}
More information about the jboss-svn-commits
mailing list