Return-Path: X-Original-To: apmail-curator-dev-archive@minotaur.apache.org Delivered-To: apmail-curator-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2DCD117989 for ; Wed, 8 Oct 2014 00:13:09 +0000 (UTC) Received: (qmail 86913 invoked by uid 500); 8 Oct 2014 00:13:09 -0000 Delivered-To: apmail-curator-dev-archive@curator.apache.org Received: (qmail 86868 invoked by uid 500); 8 Oct 2014 00:13:09 -0000 Mailing-List: contact dev-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list dev@curator.apache.org Received: (qmail 86855 invoked by uid 99); 8 Oct 2014 00:13:08 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Oct 2014 00:13:08 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 6DD1C9061CB; Wed, 8 Oct 2014 00:13:08 +0000 (UTC) From: Randgalt To: dev@curator.apache.org Reply-To: dev@curator.apache.org References: In-Reply-To: Subject: [GitHub] curator pull request: CURATOR-151: SharedValue/SharedCount API upd... Content-Type: text/plain Message-Id: <20141008001308.6DD1C9061CB@tyr.zones.apache.org> Date: Wed, 8 Oct 2014 00:13:08 +0000 (UTC) Github user Randgalt commented on a diff in the pull request: https://github.com/apache/curator/pull/47#discussion_r18558309 --- Diff: curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java --- @@ -165,14 +153,20 @@ public boolean trySetValue(byte[] newValue) throws Exception * was not successful, {@link #getValue()} will return the updated value * @throws Exception ZK errors, interruptions, etc. */ - public boolean trySetValue(VersionedValue newValue) throws Exception + public boolean trySetValue(VersionedValue previous, byte[] newValue) throws Exception { Preconditions.checkState(state.get() == State.STARTED, "not started"); + VersionedValue current = currentValue.get(); + if ( previous.getVersion() != current.getVersion() || !Arrays.equals(previous.getValue(), current.getValue()) ) + { + return false; + } + try { - client.setData().withVersion(newValue.getVersion()).forPath(path, newValue.getValue()); - currentValue.set(new VersionedValue(newValue.getVersion() + 1, Arrays.copyOf(newValue.getValue(), newValue.getValue().length))); + Stat result = client.setData().withVersion(previous.getVersion()).forPath(path, newValue); + updateValue(result.getVersion(), Arrays.copyOf(newValue, newValue.length)); --- End diff -- If we're going to add this behavior I'd change the name of this method so it's clear about the behavior. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---