[jboss-svn-commits] JBL Code SVN: r37226 - in labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm: annotations and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 4 14:50:45 EDT 2011


Author: mark.little at jboss.com
Date: 2011-07-04 14:50:44 -0400 (Mon, 04 Jul 2011)
New Revision: 37226

Added:
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/TransactionFree.java
Removed:
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java
Modified:
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/PersistentContainer.java
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/RecoverableContainer.java
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Retry.java
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Timeout.java
   labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/reflect/InvocationHandler.java
Log:
Added Timeout and Retry as well as LinkedList support.

Modified: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/PersistentContainer.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/PersistentContainer.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/PersistentContainer.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -50,6 +50,16 @@
 
 public class PersistentContainer<T> extends RecoverableContainer<T>
 {
+    public PersistentContainer ()
+    {
+        super();
+    }
+    
+    public PersistentContainer (final String name)
+    {
+        super(name);
+    }
+    
     /**
      * Return a handle through which the object should be used, rather than the one
      * passed in.
@@ -88,4 +98,9 @@
         
         return proxy;
     }
+        
+    public String toString ()
+    {
+        return "PersistentContainer "+name();
+    }
 }

Modified: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/RecoverableContainer.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/RecoverableContainer.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/RecoverableContainer.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -57,6 +57,21 @@
 
 public class RecoverableContainer<T>
 {
+    public RecoverableContainer ()
+    {
+        this(new Uid().stringForm());
+    }
+    
+    public RecoverableContainer (final String name)
+    {
+        _name = name;
+    }
+    
+    public final String name ()
+    {
+        return _name;
+    }
+    
     /**
      * Given an object we create a new transactional instance of it and return that
      * for future use. All accesses on the returned object will be managed according to
@@ -192,6 +207,11 @@
         }
     }
     
+    public String toString ()
+    {
+        return "RecoverableContainer "+_name;
+    }
+    
     @SuppressWarnings(value={"unchecked"})
     protected final void checkObjectType (Object member)
     {
@@ -225,4 +245,6 @@
     }
     
     protected WeakHashMap<T, T> _transactionalProxies = new WeakHashMap<T, T>();
+    
+    private final String _name;
 }

Deleted: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -1,32 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated 
- * by the @authors tag. All rights reserved. 
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors. 
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A 
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
- * MA  02110-1301, USA.
- * 
- * (C) 2005-2006,
- * @author mark.little at jboss.com
- */
-
-package org.jboss.stm.annotations;
-
-import java.lang.annotation.*;
-
-// Means that the method is not transactional.
-
- at Retention(RetentionPolicy.RUNTIME)
- at Target({ ElementType.METHOD })
-public @interface LockFree
-{
-}
\ No newline at end of file

Modified: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Retry.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Retry.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Retry.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -27,4 +27,5 @@
 @Target({ ElementType.METHOD })
 public @interface Retry
 {
+    int count ();
 }
\ No newline at end of file

Modified: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Timeout.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Timeout.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/Timeout.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -27,4 +27,5 @@
 @Target({ ElementType.METHOD })
 public @interface Timeout
 {
+    int period ();
 }
\ No newline at end of file

Copied: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/TransactionFree.java (from rev 37213, labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/LockFree.java)
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/TransactionFree.java	                        (rev 0)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/annotations/TransactionFree.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+package org.jboss.stm.annotations;
+
+import java.lang.annotation.*;
+
+// Means that the method is not transactional.
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ ElementType.METHOD })
+public @interface TransactionFree
+{
+}
\ No newline at end of file

Modified: labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/reflect/InvocationHandler.java
===================================================================
--- labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/reflect/InvocationHandler.java	2011-07-04 15:20:30 UTC (rev 37225)
+++ labs/jbosstm/workspace/mlittle/STM-Arjuna/src/main/java/org/jboss/stm/internal/reflect/InvocationHandler.java	2011-07-04 18:50:44 UTC (rev 37226)
@@ -28,7 +28,9 @@
 import org.jboss.stm.LockException;
 import org.jboss.stm.RecoverableContainer;
 import org.jboss.stm.TransactionException;
-import org.jboss.stm.annotations.LockFree;
+import org.jboss.stm.annotations.Retry;
+import org.jboss.stm.annotations.Timeout;
+import org.jboss.stm.annotations.TransactionFree;
 import org.jboss.stm.annotations.Nested;
 import org.jboss.stm.annotations.ReadLock;
 import org.jboss.stm.annotations.WriteLock;
@@ -40,11 +42,36 @@
 import com.arjuna.ats.arjuna.coordinator.ActionStatus;
 import com.arjuna.ats.arjuna.coordinator.BasicAction;
 import com.arjuna.ats.txoj.Lock;
+import com.arjuna.ats.txoj.LockManager;
 import com.arjuna.ats.txoj.LockMode;
 import com.arjuna.ats.txoj.LockResult;
 
 public class InvocationHandler<T> implements java.lang.reflect.InvocationHandler
 {
+    class LockInformation
+    {
+        public LockInformation (int lockType)
+        {
+            this(lockType, LockManager.defaultSleepTime, LockManager.defaultRetry);
+        }
+        
+        public LockInformation (int lockType, int timeout, int retry)
+        {
+            _lockType = lockType;
+            _timeout = timeout;
+            _retry = retry;
+        }
+        
+        public String toString ()
+        {
+            return "Lock < "+LockMode.stringForm(_lockType)+", "+_timeout+", "+_retry+" >";
+        }
+        
+        public int _lockType;
+        public int _timeout;
+        public int _retry;
+    }
+    
     public InvocationHandler (RecoverableContainer<T> c, T obj)
     {
         this(c, obj, ObjectType.RECOVERABLE);
@@ -146,10 +173,11 @@
                  * Check to see if we've cached this before.
                  */
                 
-                Integer lockType = _cachedMethods.get(method);
+                LockInformation cachedLock = _cachedMethods.get(method);
+                int lockType = -1;
                 boolean lockFree = false;
                 
-                if (lockType == null)
+                if (cachedLock == null)
                 {
                     for (Method mt : _methods)
                     {
@@ -167,22 +195,32 @@
                         throw new LockException("Could not locate method");
                     
                     if (theMethod.isAnnotationPresent(ReadLock.class))
-                        lockType = new Integer(LockMode.READ);
+                        lockType = LockMode.READ;
                     else
                     {
                         if (theMethod.isAnnotationPresent(WriteLock.class))
-                            lockType = new Integer(LockMode.WRITE);
+                            lockType = LockMode.WRITE;
                         else
                         {
-                            if (theMethod.isAnnotationPresent(LockFree.class))
+                            if (theMethod.isAnnotationPresent(TransactionFree.class))
                                 lockFree = true;
                         }
                     }
+                   
+                    int timeout = LockManager.defaultSleepTime;
+                    int retry = LockManager.defaultRetry;
                     
-                    if ((lockType == null) && (!lockFree)) // default to WRITE
-                        lockType = new Integer(LockMode.WRITE);
+                    if (theMethod.isAnnotationPresent(Timeout.class))
+                        timeout = theMethod.getAnnotation(Timeout.class).period();
                     
-                    _cachedMethods.put(method, lockType);
+                    if (theMethod.isAnnotationPresent(Retry.class))
+                        retry = theMethod.getAnnotation(Retry.class).count();
+                    
+                    if ((lockType == -1) && (!lockFree)) // default to WRITE
+                        lockType = LockMode.WRITE;
+                    
+                    cachedLock = new LockInformation(lockType, timeout, retry);
+                    _cachedMethods.put(method, cachedLock);
                 }          
                 
                 // TODO type specific concurrency control (define Lock class in annotation?)
@@ -190,14 +228,14 @@
                 if (_txObject == null)
                     throw new LockException("Transactional object is null!");
 
-                if (lockType == null)
+                if (cachedLock == null)
                     throw new LockException("Lock type is null!");
                 
-                int result = _txObject.setlock(new Lock(lockType.intValue()), 0);
+                int result = _txObject.setlock(new Lock(cachedLock._lockType), cachedLock._retry, cachedLock._timeout);
                 
                 if (result != LockResult.GRANTED)
                 {
-                    throw new LockException("Could not set "+LockMode.stringForm(lockType.intValue())+" lock. Got: "+LockResult.stringForm(result));
+                    throw new LockException("Could not set "+LockMode.stringForm(cachedLock._lockType)+" lock. Got: "+LockResult.stringForm(result));
                 }
             }
             
@@ -220,6 +258,6 @@
     private T _theObject;
     private LockManagerProxy<T> _txObject;
     private Method[] _methods;
-    private HashMap<Method, Integer> _cachedMethods = new HashMap<Method, Integer>();
+    private HashMap<Method, InvocationHandler<T>.LockInformation> _cachedMethods = new HashMap<Method, InvocationHandler<T>.LockInformation>();
     private boolean _nestedTransactions = false;
 }



More information about the jboss-svn-commits mailing list