Author: manik.surtani(a)jboss.com
Date: 2008-06-25 09:20:58 -0400 (Wed, 25 Jun 2008)
New Revision: 6025
Added:
core/trunk/src/main/java/org/jboss/cache/lock/AbstractLockManager.java
core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java
Log:
Added abstract classes to simplify lock manager implementations
Added: core/trunk/src/main/java/org/jboss/cache/lock/AbstractLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/AbstractLockManager.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/lock/AbstractLockManager.java 2008-06-25
13:20:58 UTC (rev 6025)
@@ -0,0 +1,35 @@
+package org.jboss.cache.lock;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+
+/**
+ * Common lock manager functionality
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public abstract class AbstractLockManager implements LockManager
+{
+ protected Configuration configuration;
+ protected long lockAcquisitionTimeout;
+
+ @Inject
+ public void injectConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ @Start
+ public void setLockAcquisitionTimeout()
+ {
+ this.lockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
+ }
+
+ public Object getLockOwner(InvocationContext ctx)
+ {
+ return ctx.getGlobalTransaction() != null ? ctx.getGlobalTransaction() :
Thread.currentThread();
+ }
+}
Added: core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java
(rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/lock/FqnLockManager.java 2008-06-25 13:20:58
UTC (rev 6025)
@@ -0,0 +1,50 @@
+package org.jboss.cache.lock;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeSPI;
+
+import java.util.Collection;
+
+/**
+ * An abstract lock manager that deals with Fqns rather than nodes.
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public abstract class FqnLockManager extends AbstractLockManager
+{
+ public boolean lock(NodeSPI node, LockType lockType, Object owner) throws
InterruptedException
+ {
+ return lock(node.getFqn(), lockType, owner);
+ }
+
+ public boolean lock(NodeSPI node, LockType lockType, Object owner, long timeout)
throws InterruptedException
+ {
+ return lock(node.getFqn(), lockType, owner, timeout);
+ }
+
+ public boolean lockAndRecord(NodeSPI node, LockType lockType, InvocationContext ctx)
throws InterruptedException
+ {
+ return lockAndRecord(node.getFqn(), lockType, ctx);
+ }
+
+ public void unlock(NodeSPI node, Object owner)
+ {
+ unlock(node.getFqn(), owner);
+ }
+
+ public boolean ownsLock(NodeSPI node, Object owner)
+ {
+ return ownsLock(node.getFqn(), owner);
+ }
+
+ public Object getWriteOwner(NodeSPI node)
+ {
+ return getWriteOwner(node.getFqn());
+ }
+
+ public Collection<Object> getReadOwners(NodeSPI node)
+ {
+ return getReadOwners(node.getFqn());
+ }
+}
Show replies by date