Merge "Split out NoOpDOMStoreThreePhaseCommitCohort"
authorTom Pantelis <tpanteli@brocade.com>
Thu, 2 Apr 2015 11:33:08 +0000 (11:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 2 Apr 2015 11:33:09 +0000 (11:33 +0000)
1  2 
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java

index 26523395a32f0cf2e1f06fdb46d99a5e01b71494,5e85a7cb97e539e5404c6e5bdc726be49ffc172c..7eabf9e9a67be1169fb3140e9a6ec06002db5a32
@@@ -18,7 -18,6 +18,6 @@@ import com.google.common.base.Optional
  import com.google.common.base.Preconditions;
  import com.google.common.collect.Lists;
  import com.google.common.util.concurrent.CheckedFuture;
- import com.google.common.util.concurrent.ListenableFuture;
  import com.google.common.util.concurrent.SettableFuture;
  import java.util.ArrayList;
  import java.util.Collection;
@@@ -73,14 -72,15 +72,14 @@@ public class TransactionProxy extends A
          WRITE_ONLY,
          READ_WRITE;
  
 -        public static TransactionType fromInt(int type) {
 -            if(type == WRITE_ONLY.ordinal()) {
 -                return WRITE_ONLY;
 -            } else if(type == READ_WRITE.ordinal()) {
 -                return READ_WRITE;
 -            } else if(type == READ_ONLY.ordinal()) {
 -                return READ_ONLY;
 -            } else {
 -                throw new IllegalArgumentException("In TransactionType enum value" + type);
 +        // Cache all values
 +        private static final TransactionType[] VALUES = values();
 +
 +        public static TransactionType fromInt(final int type) {
 +            try {
 +                return VALUES[type];
 +            } catch (IndexOutOfBoundsException e) {
 +                throw new IllegalArgumentException("In TransactionType enum value " + type, e);
              }
          }
      }
                  LOG.debug("Tx {} Creating NoOpTransaction because of error", getIdentifier(), failure);
  
                  localTransactionContext = new NoOpTransactionContext(failure, getIdentifier(), operationLimiter);
 -            } else if (response.getClass().equals(CreateTransactionReply.SERIALIZABLE_CLASS)) {
 +            } else if (CreateTransactionReply.SERIALIZABLE_CLASS.equals(response.getClass())) {
                  localTransactionContext = createValidTransactionContext(
                          CreateTransactionReply.fromSerializable(response));
              } else {
              }
          }
      }
-     private static class NoOpDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
-         static NoOpDOMStoreThreePhaseCommitCohort INSTANCE = new NoOpDOMStoreThreePhaseCommitCohort();
-         private static final ListenableFuture<Void> IMMEDIATE_VOID_SUCCESS =
-                 com.google.common.util.concurrent.Futures.immediateFuture(null);
-         private static final ListenableFuture<Boolean> IMMEDIATE_BOOLEAN_SUCCESS =
-                 com.google.common.util.concurrent.Futures.immediateFuture(Boolean.TRUE);
-         private NoOpDOMStoreThreePhaseCommitCohort() {
-         }
-         @Override
-         public ListenableFuture<Boolean> canCommit() {
-             return IMMEDIATE_BOOLEAN_SUCCESS;
-         }
-         @Override
-         public ListenableFuture<Void> preCommit() {
-             return IMMEDIATE_VOID_SUCCESS;
-         }
-         @Override
-         public ListenableFuture<Void> abort() {
-             return IMMEDIATE_VOID_SUCCESS;
-         }
-         @Override
-         public ListenableFuture<Void> commit() {
-             return IMMEDIATE_VOID_SUCCESS;
-         }
-     }
  }