Merge "BUG-650: remove executor abstraction"
authorTony Tkacik <ttkacik@cisco.com>
Fri, 21 Nov 2014 08:43:40 +0000 (08:43 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 21 Nov 2014 08:43:41 +0000 (08:43 +0000)
18 files changed:
opendaylight/adsal/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dynamicmbean/AbstractDynamicWrapper.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformation.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/Leader.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BackwardsCompatibleMountPoint.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTx.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/XmlAndJsonToCnSnInstanceIdentifierTest.java
opendaylight/md-sal/topology-manager/src/test/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporterTest.java

index 07f18ff..b68cc0c 100644 (file)
@@ -397,7 +397,7 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerCluster
      * dependencies are satisfied
      *
      */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @SuppressWarnings("unchecked")
     public void init() {
         log.debug("Routing init() is called");
         this.topologyBWAware = new ConcurrentHashMap<Short, Graph<Node, Edge>>();
index 4a14866..c595562 100644 (file)
@@ -7,15 +7,16 @@
  */
 package org.opendaylight.controller.config.manager.impl.dynamicmbean;
 
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.Description;
-import org.opendaylight.controller.config.api.annotations.RequireInterface;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
-import org.opendaylight.controller.config.spi.Module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import static java.lang.String.format;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import javax.management.Attribute;
 import javax.management.AttributeList;
 import javax.management.AttributeNotFoundException;
@@ -38,17 +39,14 @@ import javax.management.Notification;
 import javax.management.NotificationListener;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static java.lang.String.format;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.config.api.annotations.Description;
+import org.opendaylight.controller.config.api.annotations.RequireInterface;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
+import org.opendaylight.controller.config.spi.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Contains common code for readable/rw dynamic mbean wrappers. Routes all
@@ -57,9 +55,42 @@ import static java.lang.String.format;
  * a read only wrapper.
  */
 abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
-    private static final Logger LOGGER = LoggerFactory
-            .getLogger(AbstractDynamicWrapper.class);
+    private static final class ModuleNotificationListener implements NotificationListener {
+        private final ObjectName objectNameInternal;
+        private final MBeanServer internalServer;
+        private final ObjectName thisWrapperObjectName;
+        private final MBeanServer configMBeanServer;
+
+        private ModuleNotificationListener(final ObjectName objectNameInternal, final MBeanServer internalServer,
+                final ObjectName thisWrapperObjectName, final MBeanServer configMBeanServer) {
+            this.objectNameInternal = objectNameInternal;
+            this.internalServer = internalServer;
+            this.thisWrapperObjectName = thisWrapperObjectName;
+            this.configMBeanServer = configMBeanServer;
+        }
+
+        @Override
+        public void handleNotification(final Notification n, final Object handback) {
+            if (n instanceof MBeanServerNotification
+                    && n.getType()
+                    .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
+                if (((MBeanServerNotification) n).getMBeanName().equals(
+                        thisWrapperObjectName)) {
+                    try {
+                        internalServer.unregisterMBean(objectNameInternal);
+                        configMBeanServer.removeNotificationListener(
+                                MBeanServerDelegate.DELEGATE_NAME, this);
+                    } catch (MBeanRegistrationException
+                            | ListenerNotFoundException
+                            | InstanceNotFoundException e) {
+                        throw new IllegalStateException(e);
+                    }
+                }
+            }
+        }
+    }
 
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractDynamicWrapper.class);
     protected final boolean writable;
     protected final Module module;
 
@@ -69,10 +100,10 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     protected final ModuleIdentifier moduleIdentifier;
     protected final MBeanServer internalServer;
 
-    public AbstractDynamicWrapper(Module module, boolean writable,
-                                  ModuleIdentifier moduleIdentifier,
-                                  ObjectName thisWrapperObjectName, MBeanOperationInfo[] dOperations,
-                                  MBeanServer internalServer, MBeanServer configMBeanServer) {
+    public AbstractDynamicWrapper(final Module module, final boolean writable,
+                                  final ModuleIdentifier moduleIdentifier,
+                                  final ObjectName thisWrapperObjectName, final MBeanOperationInfo[] dOperations,
+                                  final MBeanServer internalServer, final MBeanServer configMBeanServer) {
 
         this.writable = writable;
         this.module = module;
@@ -96,7 +127,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
      * platform mbean server. Wait until this wrapper gets unregistered, in that
      * case unregister the module and remove listener.
      */
-    private final NotificationListener registerActualModule(Module module,
+    private final NotificationListener registerActualModule(final Module module,
                                                             final ObjectName thisWrapperObjectName,
                                                             final ObjectName objectNameInternal,
                                                             final MBeanServer internalServer,
@@ -110,27 +141,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
                     "Error occured during mbean registration with name " + objectNameInternal, e);
         }
 
-        NotificationListener listener = new NotificationListener() {
-            @Override
-            public void handleNotification(Notification n, Object handback) {
-                if (n instanceof MBeanServerNotification
-                        && n.getType()
-                        .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
-                    if (((MBeanServerNotification) n).getMBeanName().equals(
-                            thisWrapperObjectName)) {
-                        try {
-                            internalServer.unregisterMBean(objectNameInternal);
-                            configMBeanServer.removeNotificationListener(
-                                    MBeanServerDelegate.DELEGATE_NAME, this);
-                        } catch (MBeanRegistrationException
-                                | ListenerNotFoundException
-                                | InstanceNotFoundException e) {
-                            throw new IllegalStateException(e);
-                        }
-                    }
-                }
-            }
-        };
+        NotificationListener listener = new ModuleNotificationListener(objectNameInternal, internalServer, thisWrapperObjectName, configMBeanServer);
         try {
             configMBeanServer.addNotificationListener(
                     MBeanServerDelegate.DELEGATE_NAME, listener, null, null);
@@ -140,9 +151,9 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
         return listener;
     }
 
-    private static MBeanInfo generateMBeanInfo(String className, Module module,
-                                               Map<String, AttributeHolder> attributeHolderMap,
-                                               MBeanOperationInfo[] dOperations, Set<Class<?>> jmxInterfaces) {
+    private static MBeanInfo generateMBeanInfo(final String className, final Module module,
+                                               final Map<String, AttributeHolder> attributeHolderMap,
+                                               final MBeanOperationInfo[] dOperations, final Set<Class<?>> jmxInterfaces) {
 
         String dDescription = findDescription(module.getClass(), jmxInterfaces);
         MBeanConstructorInfo[] dConstructors = new MBeanConstructorInfo[0];
@@ -156,7 +167,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
                 dOperations, new MBeanNotificationInfo[0]);
     }
 
-    static String findDescription(Class<?> clazz, Set<Class<?>> jmxInterfaces) {
+    static String findDescription(final Class<?> clazz, final Set<Class<?>> jmxInterfaces) {
         List<Description> descriptions = AnnotationsHelper
                 .findClassAnnotationInSuperClassesAndIfcs(clazz, Description.class, jmxInterfaces);
         return AnnotationsHelper.aggregateDescriptions(descriptions);
@@ -168,10 +179,10 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
 
     // inspect all exported interfaces ending with MXBean, extract getters &
     // setters into attribute holder
-    private static Map<String, AttributeHolder> buildMBeanInfo(Module module,
-                                                               boolean writable, ModuleIdentifier moduleIdentifier,
-                                                               Set<Class<?>> jmxInterfaces, MBeanServer internalServer,
-                                                               ObjectName internalObjectName) {
+    private static Map<String, AttributeHolder> buildMBeanInfo(final Module module,
+                                                               final boolean writable, final ModuleIdentifier moduleIdentifier,
+                                                               final Set<Class<?>> jmxInterfaces, final MBeanServer internalServer,
+                                                               final ObjectName internalObjectName) {
 
         // internal variables for describing MBean elements
         Set<Method> methods = new HashSet<>();
@@ -231,7 +242,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     @Override
-    public Object getAttribute(String attributeName)
+    public Object getAttribute(final String attributeName)
             throws AttributeNotFoundException, MBeanException,
             ReflectionException {
         if ("MBeanInfo".equals(attributeName)) {
@@ -263,7 +274,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
         return obj;
     }
 
-    private Object fixDependencyListAttribute(Object attribute) {
+    private Object fixDependencyListAttribute(final Object attribute) {
         if (attribute.getClass().isArray() == false) {
             throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass());
         }
@@ -282,7 +293,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
         return attribute;
     }
 
-    private boolean isDependencyListAttr(String attributeName, Object attribute) {
+    private boolean isDependencyListAttr(final String attributeName, final Object attribute) {
         if (attributeHolderMap.containsKey(attributeName) == false) {
             return false;
         }
@@ -295,7 +306,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
         return isDepList;
     }
 
-    protected ObjectName fixObjectName(ObjectName on) {
+    protected ObjectName fixObjectName(final ObjectName on) {
         if (!ObjectNameUtil.ON_DOMAIN.equals(on.getDomain())) {
             throw new IllegalArgumentException("Wrong domain, expected "
                     + ObjectNameUtil.ON_DOMAIN + " setter on " + on);
@@ -310,7 +321,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     @Override
-    public AttributeList getAttributes(String[] attributes) {
+    public AttributeList getAttributes(final String[] attributes) {
         AttributeList result = new AttributeList();
         for (String attributeName : attributes) {
             try {
@@ -318,14 +329,14 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
                 result.add(new Attribute(attributeName, value));
 
             } catch (Exception e) {
-                LOGGER.debug("Getting attribute {} failed", attributeName, e);
+                LOG.debug("Getting attribute {} failed", attributeName, e);
             }
         }
         return result;
     }
 
     @Override
-    public Object invoke(String actionName, Object[] params, String[] signature)
+    public Object invoke(final String actionName, final Object[] params, final String[] signature)
             throws MBeanException, ReflectionException {
         if ("getAttribute".equals(actionName) && params.length == 1
                 && signature[0].equals(String.class.getName())) {
@@ -342,7 +353,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
                 && signature[0].equals(AttributeList.class.getName())) {
             return setAttributes((AttributeList) params[0]);
         } else {
-            LOGGER.debug("Operation not found {} ", actionName);
+            LOG.debug("Operation not found {} ", actionName);
             throw new UnsupportedOperationException(
                     format("Operation not found on %s. Method invoke is only supported for getInstance and getAttribute(s) "
                             + "method, got actionName %s, params %s, signature %s ",
@@ -356,7 +367,7 @@ abstract class AbstractDynamicWrapper implements DynamicMBeanModuleWrapper {
     }
 
     @Override
-    public final boolean equals(Object other) {
+    public final boolean equals(final Object other) {
         return module.equals(other);
     }
 
index c0cfd7e..7df80af 100644 (file)
@@ -80,4 +80,11 @@ public class FollowerLogInformationImpl implements FollowerLogInformation{
         }
         stopwatch.start();
     }
+
+    @Override
+    public void markFollowerInActive() {
+        if (stopwatch.isRunning()) {
+            stopwatch.stop();
+        }
+    }
 }
index 0dd3900..97ecef3 100644 (file)
@@ -113,4 +113,9 @@ public class Leader extends AbstractLeader {
     void markFollowerActive(String followerId) {
         followerToLog.get(followerId).markFollowerActive();
     }
+
+    @VisibleForTesting
+    void markFollowerInActive(String followerId) {
+        followerToLog.get(followerId).markFollowerInActive();
+    }
 }
index 6b534de..0fc0b4c 100644 (file)
@@ -6,7 +6,6 @@ import akka.actor.Props;
 import akka.actor.Terminated;
 import akka.testkit.JavaTestKit;
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Uninterruptibles;
 import com.google.protobuf.ByteString;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -994,10 +993,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest {
             final Terminated termMsg1 = probe.expectMsgClass(Terminated.class);
             assertEquals(termMsg1.getActor(), followerActor1);
 
-            //sleep enough for all the follower stopwatches to lapse
-            Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
-                getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+            leader.markFollowerInActive("follower-1");
             leader.markFollowerActive("follower-2");
             behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
             Assert.assertTrue("Behavior not instance of Leader when majority of followers are active",
@@ -1010,10 +1006,7 @@ public class LeaderTest extends AbstractRaftActorBehaviorTest {
             final Terminated termMsg2 = probe.expectMsgClass(Terminated.class);
             assertEquals(termMsg2.getActor(), followerActor2);
 
-            //sleep enough for the remaining the follower stopwatches to lapse
-            Uninterruptibles.sleepUninterruptibly(leaderActorContext.getConfigParams().
-                getElectionTimeOutInterval().toMillis(), TimeUnit.MILLISECONDS);
-
+            leader.markFollowerInActive("follower-2");
             behavior = leader.handleMessage(leaderActor, new IsolatedLeaderCheck());
             Assert.assertTrue("Behavior not instance of IsolatedLeader when majority followers are inactive",
                 behavior instanceof IsolatedLeader);
index 2a79c8f..9fbdd45 100644 (file)
@@ -29,7 +29,7 @@ public class MessageCollectorActor extends UntypedActor {
     @Override public void onReceive(Object message) throws Exception {
         if(message instanceof String){
             if("get-all-messages".equals(message)){
-                getSender().tell(messages, getSelf());
+                getSender().tell(new ArrayList(messages), getSelf());
             }
         } else {
             messages.add(message);
index 9ac3009..6f8035e 100644 (file)
@@ -66,7 +66,6 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest {
         Assert.assertEquals(mockListener, proxy.getInstance());
     }
 
-    @SuppressWarnings("unchecked")
     @Test(timeout=10000)
     public void testSuccessfulRegistration() {
         new JavaTestKit(getSystem()) {{
@@ -217,7 +216,6 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest {
         }};
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testCloseBeforeRegistration() {
         new JavaTestKit(getSystem()) {{
index cdf085e..38254dd 100644 (file)
@@ -807,7 +807,6 @@ public class TransactionProxyTest {
         }
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testReady() throws Exception {
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
@@ -842,7 +841,6 @@ public class TransactionProxyTest {
         verifyCohortFutures(proxy, getSystem().actorSelection(actorRef.path()));
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testReadyForwardCompatibility() throws Exception {
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE, 0);
@@ -883,7 +881,6 @@ public class TransactionProxyTest {
                 eq(actorRef.path().toString()));
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testReadyWithRecordingOperationFailure() throws Exception {
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
@@ -920,7 +917,6 @@ public class TransactionProxyTest {
                 MergeDataReply.SERIALIZABLE_CLASS, TestException.class);
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testReadyWithReplyFailure() throws Exception {
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
@@ -977,7 +973,6 @@ public class TransactionProxyTest {
         verifyCohortFutures(proxy, PrimaryNotFoundException.class);
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testReadyWithInvalidReplyMessageType() throws Exception {
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
@@ -1016,7 +1011,6 @@ public class TransactionProxyTest {
         assertTrue("Invalid identifier: " + id, id.toString().startsWith(memberName));
     }
 
-    @SuppressWarnings("unchecked")
     @Test
     public void testClose() throws Exception{
         ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
index fb72b5a..7a3b80b 100644 (file)
@@ -11,10 +11,15 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
@@ -65,18 +70,11 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
-import javax.annotation.Nullable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-
 public class BackwardsCompatibleMountPoint implements MountProvisionInstance, SchemaContextProvider, SchemaService {
 
     private final DataProviderService dataReader;
@@ -285,12 +283,10 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc
 
     class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
         private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
-            YangInstanceIdentifier ret = null;
-            if(mountPath.contains(path)) {
-                final List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
-                ret = YangInstanceIdentifier.create(newArgs);
+            if (!mountPath.contains(path)) {
+                return null;
             }
-            return ret;
+            return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
         }
 
         @Override
@@ -405,8 +401,8 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc
                 return Futures.immediateCheckedFuture(normalizedNodeOptional);
             }
 
-            @Override public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
-                YangInstanceIdentifier path) {
+            @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+                final YangInstanceIdentifier path) {
 
                 try {
                     return Futures.immediateCheckedFuture(read(store, path).get().isPresent());
@@ -527,8 +523,8 @@ public class BackwardsCompatibleMountPoint implements MountProvisionInstance, Sc
                 return new BackwardsCompatibleReadTransaction(dataReader, dataNormalizer).read(store, path);
             }
 
-            @Override public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store,
-                YangInstanceIdentifier path) {
+            @Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
+                final YangInstanceIdentifier path) {
 
                 try {
                     return Futures.immediateCheckedFuture(read(store, path).get().isPresent());
index 054c8ea..d7ff8e6 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.controller.sal.dom.broker;
 
-import java.util.List;
+import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Set;
-
 import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
@@ -37,11 +37,8 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
 @Deprecated
 public class MountPointImpl implements MountProvisionInstance, SchemaContextProvider {
 
@@ -187,12 +184,11 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv
 
     class ReadWrapper implements DataReader<YangInstanceIdentifier, CompositeNode> {
         private YangInstanceIdentifier shortenPath(final YangInstanceIdentifier path) {
-            YangInstanceIdentifier ret = null;
-            if(mountPath.contains(path)) {
-                List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
-                ret = YangInstanceIdentifier.create(newArgs);
+            if (!mountPath.contains(path)) {
+                return null;
             }
-            return ret;
+
+            return YangInstanceIdentifier.create(Iterables.skip(path.getPathArguments(), Iterables.size(mountPath.getPathArguments())));
         }
 
         @Override
index 94553f5..d65a3cf 100644 (file)
@@ -8,12 +8,10 @@
 package org.opendaylight.controller.sal.dom.broker.impl;
 
 import static com.google.common.base.Preconditions.checkState;
-
 import com.google.common.base.Predicate;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
-
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -21,7 +19,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.Future;
-
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
@@ -33,9 +30,9 @@ import org.opendaylight.controller.sal.dom.broker.util.YangSchemaUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -226,7 +223,7 @@ AutoCloseable {
         public int compare(final Entry<YangInstanceIdentifier, CompositeNode> o1, final Entry<YangInstanceIdentifier, CompositeNode> o2) {
             YangInstanceIdentifier o1Key = o1.getKey();
             YangInstanceIdentifier o2Key = o2.getKey();
-            return Integer.compare(o1Key.getPath().size(), o2Key.getPath().size());
+            return Integer.compare(Iterables.size(o1Key.getPathArguments()), Iterables.size(o2Key.getPathArguments()));
         }
     };
 
@@ -246,7 +243,7 @@ AutoCloseable {
                     childNodes.addAll(original.getValue());
                     qname = original.getNodeType();
                 } else {
-                    qname = path.getPath().get(path.getPath().size() - 1).getNodeType();
+                    qname = path.getLastPathArgument().getNodeType();
                 }
 
                 FluentIterable<YangInstanceIdentifier> directChildren = FluentIterable.from(getStoredConfigurationPaths())
@@ -254,7 +251,7 @@ AutoCloseable {
                             @Override
                             public boolean apply(final YangInstanceIdentifier input) {
                                 if (path.contains(input)) {
-                                    int nesting = input.getPath().size() - path.getPath().size();
+                                    int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments());
                                     if (nesting == 1) {
                                         return true;
                                     }
@@ -289,7 +286,7 @@ AutoCloseable {
                     childNodes.addAll(original.getValue());
                     qname = original.getNodeType();
                 } else {
-                    qname = path.getPath().get(path.getPath().size() - 1).getNodeType();
+                    qname = path.getLastPathArgument().getNodeType();
                 }
 
                 FluentIterable<YangInstanceIdentifier> directChildren = FluentIterable.from(getStoredOperationalPaths())
@@ -297,7 +294,7 @@ AutoCloseable {
                             @Override
                             public boolean apply(final YangInstanceIdentifier input) {
                                 if (path.contains(input)) {
-                                    int nesting = input.getPath().size() - path.getPath().size();
+                                    int nesting = Iterables.size(input.getPathArguments()) - Iterables.size(path.getPathArguments());
                                     if (nesting == 1) {
                                         return true;
                                     }
index 87f5477..4b53dd7 100644 (file)
@@ -19,18 +19,17 @@ import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessag
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_TARGET_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil.ROLLBACK_ON_ERROR_OPTION;
-
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
@@ -48,10 +47,11 @@ import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
@@ -260,17 +260,16 @@ public class NetconfDeviceWriteOnlyTx implements DOMDataWriteTransaction, Future
                                                     final Optional<CompositeNode> lastChildOverride) {
         Preconditions.checkArgument(Iterables.isEmpty(dataPath.getPathArguments()) == false, "Instance identifier with empty path %s", dataPath);
 
-        List<YangInstanceIdentifier.PathArgument> reversedPath = Lists.reverse(dataPath.getPath());
-
         // Create deepest edit element with expected edit operation
-        CompositeNode previous = getDeepestEditElement(reversedPath.get(0), operation, lastChildOverride);
+        CompositeNode previous = getDeepestEditElement(dataPath.getLastPathArgument(), operation, lastChildOverride);
 
+        Iterator<PathArgument> it = dataPath.getReversePathArguments().iterator();
         // Remove already processed deepest child
-        reversedPath = Lists.newArrayList(reversedPath);
-        reversedPath.remove(0);
+        it.next();
 
         // Create edit structure in reversed order
-        for (final YangInstanceIdentifier.PathArgument arg : reversedPath) {
+        while (it.hasNext()) {
+            final YangInstanceIdentifier.PathArgument arg = it.next();
             final CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
             builder.setQName(arg.getNodeType());
 
index 97cd67d..4238258 100644 (file)
@@ -16,8 +16,8 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
-
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
@@ -188,7 +188,7 @@ public class RestPostOperationTest extends JerseyTest {
         assertEquals(400, post(uri, MediaType.APPLICATION_JSON, ""));
     }
 
-    private void mockInvokeRpc(CompositeNode result, boolean sucessful, Collection<RpcError> errors) {
+    private void mockInvokeRpc(final CompositeNode result, final boolean sucessful, final Collection<RpcError> errors) {
 
         DummyRpcResult.Builder<CompositeNode> builder = new DummyRpcResult.Builder<CompositeNode>().result(result)
                 .isSuccessful(sucessful);
@@ -200,7 +200,7 @@ public class RestPostOperationTest extends JerseyTest {
                 Futures.<RpcResult<CompositeNode>> immediateFuture(rpcResult));
     }
 
-    private void mockInvokeRpc(CompositeNode result, boolean sucessful) {
+    private void mockInvokeRpc(final CompositeNode result, final boolean sucessful) {
         mockInvokeRpc(result, sucessful, Collections.<RpcError> emptyList());
     }
 
@@ -229,14 +229,14 @@ public class RestPostOperationTest extends JerseyTest {
         assertEquals(204, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface));
         verify(brokerFacade).commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
         String identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces]";
-        assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+        assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
 
         String URI_2 = "/config/test-interface:interfaces";
         assertEquals(204, post(URI_2, Draft02.MediaTypes.DATA + XML, xmlBlockData));
         verify(brokerFacade, times(2))
                 .commitConfigurationDataPost(instanceIdCaptor.capture(), compNodeCaptor.capture());
         identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces, (urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)block]";
-        assertEquals(identifier, instanceIdCaptor.getValue().getPath().toString());
+        assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
     }
 
     @Test
@@ -264,7 +264,7 @@ public class RestPostOperationTest extends JerseyTest {
         restconfImpl.setControllerContext(controllerContext);
     }
 
-    private int post(String uri, String mediaType, String data) {
+    private int post(final String uri, final String mediaType, final String data) {
         return target(uri).request(mediaType).post(Entity.entity(data, mediaType)).getStatus();
     }
 
index 4900e6a..efd5482 100644 (file)
@@ -13,8 +13,8 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-
 import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import java.io.FileNotFoundException;
 import java.util.Set;
@@ -124,7 +124,7 @@ public class URITest {
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
         assertEquals(
                 "[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]",
-                instanceIdentifier.getInstanceIdentifier().getPath().toString());
+                ImmutableList.copyOf(instanceIdentifier.getInstanceIdentifier().getPathArguments()).toString());
     }
 
     @Test
@@ -140,8 +140,7 @@ public class URITest {
         exception.expect(RestconfDocumentedException.class);
 
         controllerContext.setMountService(null);
-        InstanceIdentifierContext instanceIdentifier = controllerContext
-                .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
+        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
     }
 
     @Test
@@ -149,8 +148,7 @@ public class URITest {
         initMountService(false);
         exception.expect(RestconfDocumentedException.class);
 
-        InstanceIdentifierContext instanceIdentifier = controllerContext
-                .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
+        controllerContext.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
     }
 
     public void initMountService(final boolean withSchema) {
index 23e868c..6bd5178 100644 (file)
@@ -8,12 +8,12 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.util.List;
+import java.util.Iterator;
 import java.util.Map;
 import javax.ws.rs.WebApplicationException;
 import org.junit.BeforeClass;
@@ -22,12 +22,12 @@ import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
+import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
 public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSchemaLoader {
 
@@ -80,52 +80,51 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         verifyLeafListPredicate(cnSn);
     }
 
-    private void verifyLeafListPredicate(CompositeNode cnSn) throws URISyntaxException {
+    private void verifyLeafListPredicate(final CompositeNode cnSn) throws URISyntaxException {
         SimpleNode<?> lf11 = getSnWithInstanceIdentifierWhenLeafList(cnSn);
         Object value = lf11.getValue();
         assertTrue(value instanceof YangInstanceIdentifier);
 
         YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
-        List<PathArgument> pathArguments = instanceIdentifier.getPath();
-        assertEquals(3, pathArguments.size());
+        Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
         String revisionDate = "2014-01-17";
-        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), pathArguments.get(2)
-                .getNodeType());
 
-        assertTrue(pathArguments.get(2) instanceof NodeWithValue);
-        assertEquals("lflst11_1", ((NodeWithValue) pathArguments.get(2)).getValue());
+        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+        PathArgument arg = it.next();
+        assertFalse(it.hasNext());
+        assertEquals(TestUtils.buildQName("lflst11", "augment:module:leaf:list", "2014-01-27"), arg.getNodeType());
+
+        assertTrue(arg instanceof NodeWithValue);
+        assertEquals("lflst11_1", ((NodeWithValue) arg).getValue());
 
     }
 
-    private void verifyListPredicate(CompositeNode cnSn) throws URISyntaxException {
+    private void verifyListPredicate(final CompositeNode cnSn) throws URISyntaxException {
         SimpleNode<?> lf111 = getSnWithInstanceIdentifierWhenList(cnSn);
         Object value = lf111.getValue();
         assertTrue(value instanceof YangInstanceIdentifier);
 
         YangInstanceIdentifier instanceIdentifier = (YangInstanceIdentifier) value;
-        List<PathArgument> pathArguments = instanceIdentifier.getPath();
-        assertEquals(4, pathArguments.size());
+        Iterator<PathArgument> it = instanceIdentifier.getPathArguments().iterator();
         String revisionDate = "2014-01-17";
-        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), pathArguments.get(0)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), pathArguments.get(1)
-                .getNodeType());
-        assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), pathArguments.get(2).getNodeType());
-        assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), pathArguments.get(3)
-                .getNodeType());
-
-        assertTrue(pathArguments.get(2) instanceof NodeIdentifierWithPredicates);
-        Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArguments.get(2)).getKeyValues();
+        assertEquals(TestUtils.buildQName("cont", "instance:identifier:module", revisionDate), it.next().getNodeType());
+        assertEquals(TestUtils.buildQName("cont1", "instance:identifier:module", revisionDate), it.next().getNodeType());
+
+        PathArgument arg = it.next();
+        assertEquals(TestUtils.buildQName("lst11", "augment:module", revisionDate), arg.getNodeType());
+        assertEquals(TestUtils.buildQName("lf112", "augment:augment:module", revisionDate), it.next().getNodeType());
+        assertFalse(it.hasNext());
+
+        assertTrue(arg instanceof NodeIdentifierWithPredicates);
+        Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues();
         assertEquals(2, predicates.size());
         assertEquals("value1", predicates.get(TestUtils.buildQName("keyvalue111", "augment:module", revisionDate)));
         assertEquals("value2", predicates.get(TestUtils.buildQName("keyvalue112", "augment:module", revisionDate)));
     }
 
-    private SimpleNode<?> getSnWithInstanceIdentifierWhenList(CompositeNode cnSn) throws URISyntaxException {
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenList(final CompositeNode cnSn) throws URISyntaxException {
         CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
                 "2014-01-17"));
         assertNotNull(cont1);
@@ -138,7 +137,7 @@ public class XmlAndJsonToCnSnInstanceIdentifierTest extends YangAndXmlAndDataSch
         return lf111;
     }
 
-    private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(CompositeNode cnSn) throws URISyntaxException {
+    private SimpleNode<?> getSnWithInstanceIdentifierWhenLeafList(final CompositeNode cnSn) throws URISyntaxException {
         CompositeNode cont1 = cnSn.getFirstCompositeByName(TestUtils.buildQName("cont1", "instance:identifier:module",
                 "2014-01-17"));
         assertNotNull(cont1);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.