Merge "Document why we are using Virgo ExtensionsHookConfigurator"
authorGiovanni Meo <gmeo@cisco.com>
Wed, 9 Apr 2014 15:11:28 +0000 (15:11 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 9 Apr 2014 15:11:28 +0000 (15:11 +0000)
opendaylight/distribution/opendaylight/src/main/resources/run.bat
opendaylight/distribution/opendaylight/src/main/resources/run.sh
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/MutableDataTree.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/NodeModification.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java

index 9d6ac8d1deaecdee57ef842335389edb9931e1d3..72ccd02707ba7f5c76f064e5a16767a42f5fd37f 100644 (file)
@@ -10,6 +10,7 @@ SET basedir=%~dp0
 SET debugport=8000
 SET consoleport=2400
 SET jmxport=1088
+SET jvmMaxMemory=
 SET extraJVMOpts=
 SET consoleOpts=-console -consoleLog
 SET PID=
@@ -82,6 +83,11 @@ IF "%~1" NEQ "" (
        )
        GOTO :EOF
     )
+    IF "!CARG:~0,4!"=="-Xmx" (
+       SET jvmMaxMemory=!CARG!
+       SHIFT
+       GOTO :LOOP
+    )
     IF "!CARG:~0,2!"=="-D" (
        SET extraJVMOpts=%extraJVMOpts% !CARG!
        SHIFT
@@ -110,6 +116,19 @@ IF "%debugSuspended%" NEQ "" (
     REM ECHO "DEBUG enabled suspended"
     SET extraJVMOpts=%extraJVMOpts% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%debugport%
 )
+
+IF "%jvmMaxMemory%"=="" (
+    SET jvmMaxMemory=-Xmx1G
+    ECHO *****************************************************************
+    ECHO JVM maximum memory was not defined. Setting maximum memory to 1G.
+    ECHO To define the maximum memory, specify the -Xmx setting on the
+    ECHO command line.
+    ECHO                    e.g. run.bat -Xmx1G
+    ECHO *****************************************************************"
+)
+
+SET extraJVMOpts=%extraJVMOpts%  %jvmMaxMemory%
+
 IF "%jmxEnabled%" NEQ "" (
     REM ECHO "JMX enabled "
     SET extraJVMOpts=%extraJVMOpts% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=%jmxport% -Dcom.sun.management.jmxremote
index 64f2c877f7ea60f2e87f13bb9d4b173a11d7a16d..92ddbbd605346095bd4110118ab517e48e625756 100755 (executable)
@@ -82,6 +82,7 @@ stopdaemon=0
 statusdaemon=0
 consolestart=1
 dohelp=0
+jvmMaxMemory=""
 extraJVMOpts=""
 agentPath=""
 unknown_option=0
@@ -97,6 +98,7 @@ while true ; do
         -status) statusdaemon=1; shift ;;
         -console) shift ;;
         -help) dohelp=1; shift;;
+        -Xmx*) jvmMaxMemory="$1"; shift;;
         -D*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -X*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
         -agentpath:*) agentPath="$1"; shift;;
@@ -114,6 +116,18 @@ if [ "${dohelp}" -eq 1 ]; then
     usage
 fi
 
+if [ "${jvmMaxMemory}"=="" ]; then
+    jvmMaxMemory="-Xmx1G"
+    echo "*****************************************************************"
+    echo "JVM maximum memory was not defined. Setting maximum memory to 1G."
+    echo "To define the maximum memory, specify the -Xmx setting on the"
+    echo "command line. "
+    echo "        e.g. ./run.sh -Xmx1G"
+    echo "*****************************************************************"
+fi
+
+extraJVMOpts="${extraJVMOpts} ${jvmMaxMemory}"
+
 # Validate debug port
 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
     echo "Debug Port not in the range [1024,65535] ${debugport}"
index f252744876f0b8da325523fdcce62c8bad3a7552..14d82799d76ec3d0a58b7797ab9d718163072c6c 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.controller.md.sal.dom.store.impl;
 import static com.google.common.base.Preconditions.checkState;
 
 import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification;
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
@@ -22,16 +23,18 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 
+/*
+ * FIXME: the thread safety of concurrent write/delete/read/seal operations
+ *        needs to be evaluated.
+ */
 class MutableDataTree {
-
-    private static final Logger log = LoggerFactory.getLogger(MutableDataTree.class);
-
-    final DataAndMetadataSnapshot snapshot;
-    final NodeModification rootModification;
-    final ModificationApplyOperation strategyTree;
-
-    private boolean sealed = false;
+    private static final Logger LOG = LoggerFactory.getLogger(MutableDataTree.class);
+    private final AtomicBoolean sealed = new AtomicBoolean();
+    private final ModificationApplyOperation strategyTree;
+    private final DataAndMetadataSnapshot snapshot;
+    private final NodeModification rootModification;
 
     private MutableDataTree(final DataAndMetadataSnapshot snapshot, final ModificationApplyOperation strategyTree) {
         this.snapshot = snapshot;
@@ -58,7 +61,6 @@ class MutableDataTree {
             return NormalizedNodeUtils.findNode(modification.getKey(), data, path);
         }
         return Optional.absent();
-
     }
 
     private Optional<StoreMetadataNode> resolveSnapshot(
@@ -78,13 +80,13 @@ class MutableDataTree {
             return resolveModificationStrategy(path).apply(modification, modification.getOriginal(),
                     StoreUtils.increase(snapshot.getMetadataTree().getSubtreeVersion()));
         } catch (Exception e) {
-            log.error("Could not create snapshot for {}", path,e);
+            LOG.error("Could not create snapshot for {}", path,e);
             throw e;
         }
     }
 
     private ModificationApplyOperation resolveModificationStrategy(final InstanceIdentifier path) {
-        log.trace("Resolving modification apply strategy for {}", path);
+        LOG.trace("Resolving modification apply strategy for {}", path);
         return TreeNodeUtils.findNodeChecked(strategyTree, path);
     }
 
@@ -103,12 +105,13 @@ class MutableDataTree {
     }
 
     public void seal() {
-        sealed = true;
+        final boolean success = sealed.compareAndSet(false, true);
+        Preconditions.checkState(success, "Attempted to seal an already-sealed Data Tree.");
         rootModification.seal();
     }
 
     private void checkSealed() {
-        checkState(!sealed, "Data Tree is sealed. No further modifications allowed.");
+        checkState(!sealed.get(), "Data Tree is sealed. No further modifications allowed.");
     }
 
     protected NodeModification getRootModification() {
@@ -119,6 +122,4 @@ class MutableDataTree {
     public String toString() {
         return "MutableDataTree [modification=" + rootModification + "]";
     }
-
-
 }
index 02c2a4fa06042e2984745183262a7d053411157a..830d7e3dc40303859748e5d1977eeaa3f7018c3b 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.primitives.UnsignedLong;
 public final class StoreUtils {
 
     private final static Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER = new Function<Identifiable<Object>, Object>() {
-
         @Override
         public Object apply(final Identifiable<Object> input) {
             return input.getIdentifier();
@@ -45,6 +44,11 @@ public final class StoreUtils {
         return new InitialDataChangeEvent(path, data.getData());
     }
 
+    /*
+     * Suppressing warnings here allows us to fool the compiler enough
+     * such that we can reuse a single function for all applicable types
+     * and present it in a type-safe manner to our users.
+     */
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <V> Function<Identifiable<V>, V> identifierExtractor() {
         return (Function) EXTRACT_IDENTIFIER;
@@ -90,7 +94,6 @@ public final class StoreUtils {
         public NormalizedNode<?, ?> getUpdatedSubtree() {
             return data;
         }
-
     }
 
     public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
@@ -101,7 +104,6 @@ public final class StoreUtils {
         StringBuilder builder = new StringBuilder();
         toStringTree(builder, metaNode, 0);
         return builder.toString();
-
     }
 
     private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode, final int offset) {
@@ -109,15 +111,15 @@ public final class StoreUtils {
         builder.append(prefix).append(toStringTree(metaNode.getIdentifier()));
         NormalizedNode<?, ?> dataNode = metaNode.getData();
         if (dataNode instanceof NormalizedNodeContainer<?, ?, ?>) {
-            builder.append(" {").append("\n");
+            builder.append(" {\n");
             for (StoreMetadataNode child : metaNode.getChildren()) {
                 toStringTree(builder, child, offset + 4);
             }
-            builder.append(prefix).append("}");
+            builder.append(prefix).append('}');
         } else {
-            builder.append(" ").append(dataNode.getValue());
+            builder.append(' ').append(dataNode.getValue());
         }
-        builder.append("\n");
+        builder.append('\n');
     }
 
     private static String toStringTree(final PathArgument identifier) {
index a0c15eb4a0590f2fe56f7008456a36ddc2dbba03..04fb3b7c6c50499ad0b96b220c2685b597bdcb9d 100644 (file)
@@ -12,6 +12,8 @@ import static com.google.common.base.Preconditions.checkState;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import javax.annotation.concurrent.GuardedBy;
+
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -51,6 +53,7 @@ public class NodeModification implements StoreTreeNode<NodeModification>, Identi
 
     private final Map<PathArgument, NodeModification> childModification;
 
+    @GuardedBy("this")
     private boolean sealed = false;
 
     protected NodeModification(final PathArgument identifier, final Optional<StoreMetadataNode> original) {
@@ -173,6 +176,7 @@ public class NodeModification implements StoreTreeNode<NodeModification>, Identi
         this.value = value;
     }
 
+    @GuardedBy("this")
     private void checkSealed() {
         checkState(!sealed, "Node Modification is sealed. No further changes allowed.");
     }
@@ -202,7 +206,8 @@ public class NodeModification implements StoreTreeNode<NodeModification>, Identi
         return !childModification.isEmpty();
     }
 
-    public void updateModificationType(final ModificationType type) {
+    @GuardedBy("this")
+    private void updateModificationType(final ModificationType type) {
         modificationType = type;
         clearSnapshot();
     }
index a2a706a9da3f84b197aaa80d57487b89ff2cb55b..339d9cb44e2ed9515daa1eabbb8db2d913dab91a 100644 (file)
@@ -43,7 +43,7 @@ public class TreeNodeUtils {
 
     public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final InstanceIdentifier path) {
         T current = tree;
-        List<PathArgument> nested = new ArrayList<>(path.getPath());
+        List<PathArgument> nested = new ArrayList<>(path.getPath().size());
         for(PathArgument pathArg : path.getPath()) {
             Optional<T> potential = current.getChild(pathArg);
             nested.add(pathArg);
@@ -80,11 +80,17 @@ public class TreeNodeUtils {
             final InstanceIdentifier currentPath = new InstanceIdentifier(path.getPath().subList(0, nesting));
             return new SimpleEntry<InstanceIdentifier,T>(currentPath,current.get());
         }
-        // Nesting minus one is safe, since current is allways present when nesting = 0
-        // so this prat of code is never triggered, in cases nesting == 0;
+
+        /*
+         * Subtracting 1 from nesting level at this point is safe, because we
+         * cannot reach here with nesting == 0: that would mean the above check
+         * for current.isPresent() failed, which it cannot, as current is always
+         * present. At any rate we check state just to be on the safe side.
+         */
+        Preconditions.checkState(nesting > 0);
         final InstanceIdentifier parentPath = new InstanceIdentifier(path.getPath().subList(0, nesting - 1));
-        return new SimpleEntry<InstanceIdentifier,T>(parentPath,parent.get());
 
+        return new SimpleEntry<InstanceIdentifier,T>(parentPath,parent.get());
     }
 
     public static <T extends StoreTreeNode<T>> Optional<T> getChild(final Optional<T> parent,final PathArgument child) {