[jboss-svn-commits] JBL Code SVN: r24556 - 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
Tue Jan 6 10:17:29 EST 2009


Author: adinn
Date: 2009-01-06 10:17:29 -0500 (Tue, 06 Jan 2009)
New Revision: 24556

Added:
   labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Counter.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/Rule.java
Log:
added Counter built-ins, upgraded error trace messages from rule agent and improved docs including adding section on Counter built-ins

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-01-06 15:13:20 UTC (rev 24555)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/agent/Transformer.java	2009-01-06 15:17:29 UTC (rev 24556)
@@ -333,13 +333,13 @@
         try {
             rule = Rule.create(ruleName, handlerClass, handlerMethod, handlerLocation, script.getRuleText(), loader);
         } catch (ParseException pe) {
-            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error parsing rule : " + pe);
+            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error parsing rule " + ruleName + " : " + pe);
             return targetClassBytes;
         } catch (TypeException te) {
-            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error checking rule : " + te);
+            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error checking rule " + ruleName + " : " + te);
             return targetClassBytes;
         } catch (Throwable th) {
-            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error processing rule : " + th);
+            System.out.println("org.jboss.jbossts.orchestration.agent.Transformer : error processing rule " + ruleName + " : " + th);
             return targetClassBytes;
         }
         System.out.println(rule);

Modified: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java	2009-01-06 15:13:20 UTC (rev 24555)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/rule/Rule.java	2009-01-06 15:17:29 UTC (rev 24556)
@@ -36,6 +36,7 @@
 import org.jboss.jbossts.orchestration.rule.grammar.ParseNode;
 import org.jboss.jbossts.orchestration.synchronization.CountDown;
 import org.jboss.jbossts.orchestration.synchronization.Waiter;
+import org.jboss.jbossts.orchestration.synchronization.Counter;
 import org.jboss.jbossts.orchestration.agent.Location;
 import org.jboss.jbossts.orchestration.agent.LocationType;
 import org.jboss.jbossts.orchestration.agent.Transformer;
@@ -699,6 +700,121 @@
         }
 
         /**
+         * delay execution of the current thread for a specified number of milliseconds
+         * @param millisecs how many milliseconds to delay for
+         */
+
+        public void delay(long millisecs)
+        {
+            try {
+                Thread.sleep(millisecs);
+            } catch (InterruptedException e) {
+                // ignore this
+            }
+        }
+
+        /**
+         * create a counter identified by the given object with count 0 as its initial count
+         * @param o an identifier used to refer to the counter in future
+         * @return true if a new counter was created and false if one already existed under the given identifier
+         */
+        public boolean createCounter(Object o)
+        {
+            return createCounter(o, 0);
+        }
+
+        /**
+         * 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
+         * @return true if a new counter was created and false if one already existed under the given identifier
+         */
+        public boolean createCounter(Object o, int value)
+        {
+            synchronized (counterMap) {
+                Counter counter = counterMap.get(o);
+                if  (counter != null) {
+                    return false;
+                } else {
+                    counterMap.put(o, new Counter(value));
+                    return true;
+                }
+            }
+        }
+
+        /**
+         * delete a counter identified by the given object with count 0 as its initial count
+         * @param o the identifier for the coounter
+         * @return true if a counter was deleted and false if no counter existed under the given identifier
+         */
+        public boolean deleteCounter(Object o)
+        {
+            synchronized (counterMap) {
+                Counter counter = counterMap.get(o);
+                if  (counter != null) {
+                    counterMap.put(o, null);
+                    return true;
+                } else {
+                    return false;
+                }
+            }
+        }
+
+        /**
+         * read the value of the counter associated with given identifier, creating a new one with count zero
+         * if none exists
+         * @param o the identifier for the coounter
+         * @return the value of the counter
+         */
+        public int readCounter(Object o)
+        {
+            synchronized (counterMap) {
+                Counter counter = counterMap.get(o);
+                if (counter == null) {
+                    counter = new Counter();
+                    counterMap.put(o, counter);
+                }
+                return counter.count();
+            }
+        }
+
+        /**
+         * increment the value of the counter associated with given identifier, creating a new one with count zero
+         * if none exists
+         * @param o the identifier for the coounter
+         * @return the value of the counter after the increment
+         */
+        public int incrementCounter(Object o)
+        {
+            synchronized (counterMap) {
+                Counter counter = counterMap.get(o);
+                if (counter == null) {
+                    counter = new Counter();
+                    counterMap.put(o, counter);
+                }
+                return counter.increment();
+            }
+        }
+
+        /**
+         * decrement the value of the counter associated with given identifier, creating a new one with count zero
+         * if none exists
+         * @param o the identifier for the coounter
+         * @return the value of the counter after the decrement
+         */
+        public int decrementCounter(Object o)
+        {
+            synchronized (counterMap) {
+                Counter counter = counterMap.get(o);
+                if (counter == null) {
+                    counter = new Counter();
+                    counterMap.put(o, counter);
+                }
+                return counter.decrement();
+            }
+        }
+
+        /**
          * cause the current thread to throw a runtime exception which will normally cause it to exit.
          * The exception may not kill the thread if the trigger method or calling code contains a
          * catch-all handler so care must be employed to ensure that a call to this builtin has the
@@ -898,6 +1014,11 @@
     private static HashMap<Object, CountDown> countDownMap = new HashMap<Object, CountDown>();
 
     /**
+     * a hash map used to identify counters from their identifying objects
+     */
+    private static HashMap<Object, Counter> counterMap = new HashMap<Object, Counter>();
+
+    /**
      * a hash map used to identify waiters from their identifying objects
      */
     private static HashMap<Object, Waiter> waitMap = new HashMap<Object, Waiter>();

Added: labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Counter.java
===================================================================
--- labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Counter.java	                        (rev 0)
+++ labs/jbosstm/workspace/adinn/orchestration/src/org/jboss/jbossts/orchestration/synchronization/Counter.java	2009-01-06 15:17:29 UTC (rev 24556)
@@ -0,0 +1,37 @@
+package org.jboss.jbossts.orchestration.synchronization;
+
+/**
+ * class used to associate a counter value with a given object
+ */
+public class Counter
+{
+    private int count;
+
+    public Counter()
+    {
+        this(0);
+    }
+    public Counter(int count)
+    {
+        this.count = count;
+    }
+
+    public synchronized int count()
+    {
+        return count;
+    }
+
+    public synchronized int increment()
+    {
+        count++;
+
+        return count;
+    }
+
+    public synchronized int decrement()
+    {
+        count--;
+
+        return count;
+    }
+}




More information about the jboss-svn-commits mailing list