IGNITE-59 Added gate to CacheLockImpl.

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/6badd2ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/6badd2ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/6badd2ba

Branch: refs/heads/ignite-132
Commit: 6badd2bac19ef13304ac4d564f322f69e9d0f244
Parents: 3647e88
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Tue Jan 27 18:32:20 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Tue Jan 27 18:32:20 2015 +0300

----------------------------------------------------------------------
 .../processors/cache/CacheLockImpl.java         | 36 +++++++++++++++++---
 .../processors/cache/IgniteCacheProxy.java      |  2 +-
 2 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6badd2ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
index 0f1fe42..d918499 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLockImpl.java
@@ -30,9 +30,15 @@ import java.util.concurrent.locks.*;
 /**
  *
  */
-class CacheLockImpl<K> implements Lock {
+class CacheLockImpl<K, V> implements Lock {
+    /** Gateway. */
+    private final GridCacheGateway<K, V> gate;
+
     /** */
-    private final GridCacheProjectionEx<K, ?> delegate;
+    private final GridCacheProjectionEx<K, V> delegate;
+
+    /** Projection. */
+    private final GridCacheProjectionImpl<K, V> prj;
 
     /** */
     private final Collection<? extends K> keys;
@@ -44,17 +50,22 @@ class CacheLockImpl<K> implements Lock {
     private volatile Thread lockedThread;
 
     /**
+     * @param gate Gate.
      * @param delegate Delegate.
+     * @param prj Projection.
      * @param keys Keys.
      */
-    CacheLockImpl(GridCacheProjectionEx<K, ?> delegate, Collection<? extends 
K> keys) {
+    CacheLockImpl(GridCacheGateway<K, V> gate, GridCacheProjectionEx<K, V> 
delegate, GridCacheProjectionImpl<K, V> prj,
+        Collection<? extends K> keys) {
+        this.gate = gate;
         this.delegate = delegate;
+        this.prj = prj;
         this.keys = keys;
     }
 
     /** {@inheritDoc} */
     @Override public void lock() {
-        //cctx.readlock();
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
 
         try {
             delegate.lockAll(keys, 0);
@@ -65,7 +76,7 @@ class CacheLockImpl<K> implements Lock {
             throw new CacheException(e.getMessage(), e);
         }
         finally {
-            //cctx.readunlock();
+            gate.leave(prev);
         }
     }
 
@@ -87,6 +98,8 @@ class CacheLockImpl<K> implements Lock {
 
     /** {@inheritDoc} */
     @Override public boolean tryLock() {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
         try {
             boolean res = delegate.lockAll(keys, -1);
 
@@ -98,6 +111,9 @@ class CacheLockImpl<K> implements Lock {
         catch (IgniteCheckedException e) {
             throw new CacheException(e.getMessage(), e);
         }
+        finally {
+            gate.leave(prev);
+        }
     }
 
     /** {@inheritDoc} */
@@ -108,6 +124,8 @@ class CacheLockImpl<K> implements Lock {
         if (time <= 0)
             return tryLock();
 
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
         try {
             IgniteFuture<Boolean> fut = delegate.lockAllAsync(keys, 
unit.toMillis(time));
 
@@ -142,10 +160,15 @@ class CacheLockImpl<K> implements Lock {
         catch (IgniteCheckedException e) {
             throw new CacheException(e.getMessage(), e);
         }
+        finally {
+            gate.leave(prev);
+        }
     }
 
     /** {@inheritDoc} */
     @Override public void unlock() {
+        GridCacheProjectionImpl<K, V> prev = gate.enter(prj);
+
         try {
             if (lockedThread != Thread.currentThread()) {
                 throw new IllegalStateException("Failed to unlock keys (did 
current thread acquire lock " +
@@ -164,6 +187,9 @@ class CacheLockImpl<K> implements Lock {
         catch (IgniteCheckedException e) {
             throw new CacheException(e.getMessage(), e);
         }
+        finally {
+            gate.leave(prev);
+        }
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/6badd2ba/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 5993097..42d9ce2 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -189,7 +189,7 @@ public class IgniteCacheProxy<K, V> extends 
IgniteAsyncSupportAdapter implements
 
     /** {@inheritDoc} */
     @Override public Lock lockAll(final Collection<? extends K> keys) {
-        return new CacheLockImpl<>(delegate, keys);
+        return new CacheLockImpl<>(gate, delegate, prj, keys);
     }
 
     /** {@inheritDoc} */

Reply via email to