SET debugport=8000
SET consoleport=2400
SET jmxport=1088
+SET jvmMaxMemory=
SET extraJVMOpts=
SET consoleOpts=-console -consoleLog
SET PID=
)
GOTO :EOF
)
+ IF "!CARG:~0,4!"=="-Xmx" (
+ SET jvmMaxMemory=!CARG!
+ SHIFT
+ GOTO :LOOP
+ )
IF "!CARG:~0,2!"=="-D" (
SET extraJVMOpts=%extraJVMOpts% !CARG!
SHIFT
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
statusdaemon=0
consolestart=1
dohelp=0
+jvmMaxMemory=""
extraJVMOpts=""
agentPath=""
unknown_option=0
-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;;
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}"
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;
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;
return NormalizedNodeUtils.findNode(modification.getKey(), data, path);
}
return Optional.absent();
-
}
private Optional<StoreMetadataNode> resolveSnapshot(
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);
}
}
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() {
public String toString() {
return "MutableDataTree [modification=" + rootModification + "]";
}
-
-
}
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();
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;
public NormalizedNode<?, ?> getUpdatedSubtree() {
return data;
}
-
}
public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
StringBuilder builder = new StringBuilder();
toStringTree(builder, metaNode, 0);
return builder.toString();
-
}
private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode, final int offset) {
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) {
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;
private final Map<PathArgument, NodeModification> childModification;
+ @GuardedBy("this")
private boolean sealed = false;
protected NodeModification(final PathArgument identifier, final Optional<StoreMetadataNode> original) {
this.value = value;
}
+ @GuardedBy("this")
private void checkSealed() {
checkState(!sealed, "Node Modification is sealed. No further changes allowed.");
}
return !childModification.isEmpty();
}
- public void updateModificationType(final ModificationType type) {
+ @GuardedBy("this")
+ private void updateModificationType(final ModificationType type) {
modificationType = type;
clearSnapshot();
}
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);
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) {