You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/01/16 13:45:49 UTC
[3/6] incubator-ignite git commit: # IGNITE-59 Support lock, lockAll.
# IGNITE-59 Support lock, lockAll.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/26d79649
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/26d79649
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/26d79649
Branch: refs/heads/ignite-1
Commit: 26d796492972453198fbf5e68130fc2f54385b81
Parents: 9e7f696
Author: sevdokimov <se...@gridgain.com>
Authored: Wed Jan 14 18:58:35 2015 +0300
Committer: sevdokimov <se...@gridgain.com>
Committed: Fri Jan 16 15:45:41 2015 +0300
----------------------------------------------------------------------
.../java/org/apache/ignite/IgniteCache.java | 4 +-
.../processors/cache/IgniteCacheProxy.java | 76 ++++++++++++++++++--
2 files changed, 73 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/26d79649/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 2988005..f4aa3d5 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -180,9 +180,9 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
*/
public void removeAll(IgnitePredicate<Entry<K, V>> filter) throws CacheException;
- public Lock lock(K key) throws CacheException;
+ public Lock lock(K key);
- public Lock lockAll(Set<? extends K> keys) throws CacheException;
+ public Lock lockAll(Set<? extends K> keys);
/**
* Checks if any node owns a lock for this key.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/26d79649/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 f95cd2a..055827b 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
@@ -23,6 +23,7 @@ import org.apache.ignite.cache.query.*;
import org.apache.ignite.cluster.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.resources.*;
+import org.gridgain.grid.*;
import org.gridgain.grid.cache.*;
import org.gridgain.grid.kernal.*;
import org.gridgain.grid.kernal.processors.cache.*;
@@ -258,14 +259,79 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements
/** {@inheritDoc} */
@Override public Lock lock(K key) throws CacheException {
- // TODO IGNITE-1.
- throw new UnsupportedOperationException();
+ return lockAll(Collections.<K>singleton(key));
}
/** {@inheritDoc} */
- @Override public Lock lockAll(Set<? extends K> keys) throws CacheException {
- // TODO IGNITE-1.
- throw new UnsupportedOperationException();
+ @Override public Lock lockAll(final Set<? extends K> keys) {
+ return new Lock() {
+ @Override public void lock() {
+ try {
+ delegate.lockAll(keys, 0);
+ }
+ catch (GridInterruptedException ignored) {
+
+ }
+ catch (IgniteCheckedException e) {
+ throw new CacheException(e);
+ }
+ }
+
+ @Override public void lockInterruptibly() throws InterruptedException {
+ if (Thread.interrupted())
+ throw new InterruptedException();
+
+ try {
+ delegate.lockAll(keys, 0);
+ }
+ catch (GridInterruptedException e) {
+ if (e.getCause() instanceof InterruptedException)
+ throw (InterruptedException)e.getCause();
+
+ throw new InterruptedException();
+ }
+ catch (IgniteCheckedException e) {
+ throw new CacheException(e);
+ }
+ }
+
+ @Override public boolean tryLock() {
+ try {
+ return delegate.lockAll(keys, -1);
+ }
+ catch (IgniteCheckedException e) {
+ throw new CacheException(e);
+ }
+ }
+
+ @Override public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
+ try {
+ return delegate.lockAll(keys, unit.toMillis(time));
+ }
+ catch (GridInterruptedException e) {
+ if (e.getCause() instanceof InterruptedException)
+ throw (InterruptedException)e.getCause();
+
+ throw new InterruptedException();
+ }
+ catch (IgniteCheckedException e) {
+ throw new CacheException(e);
+ }
+ }
+
+ @Override public void unlock() {
+ try {
+ delegate.unlockAll(keys);
+ }
+ catch (IgniteCheckedException e) {
+ throw new CacheException(e);
+ }
+ }
+
+ @NotNull @Override public Condition newCondition() {
+ throw new UnsupportedOperationException();
+ }
+ };
}
/** {@inheritDoc} */