Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DED25102CB for ; Mon, 19 Jan 2015 06:42:47 +0000 (UTC) Received: (qmail 58825 invoked by uid 500); 19 Jan 2015 06:42:50 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 58792 invoked by uid 500); 19 Jan 2015 06:42:50 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 58783 invoked by uid 99); 19 Jan 2015 06:42:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Jan 2015 06:42:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 19 Jan 2015 06:42:23 +0000 Received: (qmail 57970 invoked by uid 99); 19 Jan 2015 06:42:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Jan 2015 06:42:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 34FDFE07F5; Mon, 19 Jan 2015 06:42:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 19 Jan 2015 06:42:25 -0000 Message-Id: <8a94f655fbb8457d9002bde8c249f709@git.apache.org> In-Reply-To: <39d95fcef6dc490baf0df7faf3b744e6@git.apache.org> References: <39d95fcef6dc490baf0df7faf3b744e6@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/15] incubator-ignite git commit: # IGNITE-59 Support lock, lockAll. X-Virus-Checked: Checked by ClamAV on apache.org # 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-43 Commit: 26d796492972453198fbf5e68130fc2f54385b81 Parents: 9e7f696 Author: sevdokimov Authored: Wed Jan 14 18:58:35 2015 +0300 Committer: sevdokimov 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 extends javax.cache.Cache, IgniteAsyncS */ public void removeAll(IgnitePredicate> filter) throws CacheException; - public Lock lock(K key) throws CacheException; + public Lock lock(K key); - public Lock lockAll(Set keys) throws CacheException; + public Lock lockAll(Set 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 extends IgniteAsyncSupportAdapter implements /** {@inheritDoc} */ @Override public Lock lock(K key) throws CacheException { - // TODO IGNITE-1. - throw new UnsupportedOperationException(); + return lockAll(Collections.singleton(key)); } /** {@inheritDoc} */ - @Override public Lock lockAll(Set keys) throws CacheException { - // TODO IGNITE-1. - throw new UnsupportedOperationException(); + @Override public Lock lockAll(final Set 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} */