curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dragonsinth <...@git.apache.org>
Subject [GitHub] curator pull request: CURATOR-151: SharedValue/SharedCount API upd...
Date Wed, 08 Oct 2014 00:19:22 GMT
Github user dragonsinth commented on a diff in the pull request:

    https://github.com/apache/curator/pull/47#discussion_r18558516
  
    --- Diff: curator-recipes/src/main/java/org/apache/curator/framework/recipes/shared/SharedValue.java
---
    @@ -129,29 +127,19 @@ public void setValue(byte[] newValue) throws Exception
          * value is updated. i.e. if the value is not successful you can get the updated
value
          * by calling {@link #getValue()}.
          *
    +     * @deprecated use {@link #trySetValue(VersionedValue, byte[])} for stronger atomicity
    +     * guarantees. Even if this object's internal state is up-to-date, the caller has
no way to
    +     * ensure that they've read the most recently seen value.
    +     *
          * @param newValue the new value to attempt
          * @return true if the change attempt was successful, false if not. If the change
          * was not successful, {@link #getValue()} will return the updated value
          * @throws Exception ZK errors, interruptions, etc.
          */
    +    @Deprecated
         public boolean trySetValue(byte[] newValue) throws Exception
         {
    -        Preconditions.checkState(state.get() == State.STARTED, "not started");
    -
    -        try
    -        {
    -            VersionedValue<byte[]> localCopy = currentValue.get();
    -            client.setData().withVersion(localCopy.getVersion()).forPath(path, newValue);
    -            currentValue.set(new VersionedValue<byte[]>(localCopy.getVersion()
+ 1, Arrays.copyOf(newValue, newValue.length)));
    -            return true;
    -        }
    -        catch ( KeeperException.BadVersionException ignore )
    -        {
    -            // ignore
    -        }
    -
    -        readValue();
    -        return false;
    +        return trySetValue(currentValue.get(), newValue);
         }
    --- End diff --
    
    Hmm, so when I wrote this code I was 99% sure this would NOT be a change to the existing
behavior.  In other words, if you were to inline the 2-arg version into the 1-arg version,
I think you get (essentially) identical code.  I was just trying to DRY this up.  What do
you see being different?


---
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.
---

Mime
View raw message