From ac1fa871f050c36b798047fe7e93718d4681996a Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Sun, 10 Apr 2016 23:45:43 +0200 Subject: HONEYCOMB-34: Configurable ConfigDataTree dependency Change-Id: I17a93835541e66835398391e2a127b25767b774a Signed-off-by: Marek Gradzki --- .../honeycomb/v3po/data/impl/ConfigDataTree.java | 19 ++++--- .../data/impl/rev160411/ConfigDataTreeModule.java | 64 ++++++++++++++++++++++ .../rev160411/ConfigDataTreeModuleFactory.java | 13 +++++ 3 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java create mode 100644 v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModuleFactory.java (limited to 'v3po/data-impl/src/main/java') diff --git a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTree.java b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTree.java index f636e6708..59a555fda 100644 --- a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTree.java +++ b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ConfigDataTree.java @@ -57,7 +57,7 @@ public final class ConfigDataTree implements ModifiableDataTree { private final BindingNormalizedNodeSerializer serializer; private final DataTree dataTree; - private final WriterRegistry writer; + private final WriterRegistry writerRegistry; public static final ReadableDataTree EMPTY_OPERATIONAL = new ReadableDataTree() { @Override public CheckedFuture>, ReadFailedException> read( @@ -69,16 +69,17 @@ public final class ConfigDataTree implements ModifiableDataTree { /** * Creates configuration data tree instance. * - * @param serializer service for serialization between Java Binding Data representation and NormalizedNode - * representation. - * @param dataTree data tree for configuration data representation - * @param writer service for translation between Java Binding Data and data provider. + * @param serializer service for serialization between Java Binding Data representation and NormalizedNode + * representation. + * @param dataTree data tree for configuration data representation + * @param writerRegistry service for translation between Java Binding Data and data provider, capable of performing + * bulk updates. */ public ConfigDataTree(@Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final DataTree dataTree, @Nonnull final WriterRegistry writer) { + @Nonnull final DataTree dataTree, @Nonnull final WriterRegistry writerRegistry) { this.serializer = checkNotNull(serializer, "serializer should not be null"); this.dataTree = checkNotNull(dataTree, "dataTree should not be null"); - this.writer = checkNotNull(writer, "writer should not be null"); + this.writerRegistry = checkNotNull(writerRegistry, "writerRegistry should not be null"); } @Override @@ -110,8 +111,8 @@ public final class ConfigDataTree implements ModifiableDataTree { final DOMDataReadOnlyTransaction beforeTx = new ReadOnlyTransaction(EMPTY_OPERATIONAL, takeSnapshot()); final ConfigSnapshot modificationSnapshot = new ConfigSnapshot(modification); final DOMDataReadOnlyTransaction afterTx = new ReadOnlyTransaction(EMPTY_OPERATIONAL, modificationSnapshot); - try(final WriteContext ctx = new TransactionWriteContext(serializer, beforeTx, afterTx)) { - writer.update(nodesBefore, nodesAfter, ctx); + try (final WriteContext ctx = new TransactionWriteContext(serializer, beforeTx, afterTx)) { + writerRegistry.update(nodesBefore, nodesAfter, ctx); } catch (io.fd.honeycomb.v3po.translate.write.WriterRegistry.BulkUpdateException e) { LOG.warn("Failed to apply all changes", e); LOG.info("Trying to revert successful changes for current transaction"); diff --git a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java new file mode 100644 index 000000000..88e87956b --- /dev/null +++ b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java @@ -0,0 +1,64 @@ +package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411; + +import io.fd.honeycomb.v3po.data.DataTreeSnapshot; +import io.fd.honeycomb.v3po.data.ModifiableDataTree; +import io.fd.honeycomb.v3po.data.impl.ConfigDataTree; +import io.fd.honeycomb.v3po.translate.TranslationException; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; +import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; + +public class ConfigDataTreeModule extends + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.AbstractConfigDataTreeModule { + public ConfigDataTreeModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public ConfigDataTreeModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.ConfigDataTreeModule oldModule, + java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); + dataTree.setSchemaContext(getSchemaServiceDependency().getGlobalContext()); + return new CloseableConfigDataTree(new ConfigDataTree(getBindingNormalizedNodeSerializerDependency(), dataTree, + getWriterRegistryDependency())); + } + + private static final class CloseableConfigDataTree implements ModifiableDataTree, AutoCloseable { + + private final ConfigDataTree delegate; + + CloseableConfigDataTree(final ConfigDataTree delegate) { + this.delegate = delegate; + } + + @Override + public void close() throws Exception { + // NOP + } + + @Override + public void modify(final DataTreeModification modification) + throws DataValidationFailedException, TranslationException { + delegate.modify(modification); + } + + @Override + public DataTreeSnapshot takeSnapshot() { + return delegate.takeSnapshot(); + } + } +} diff --git a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModuleFactory.java b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModuleFactory.java new file mode 100644 index 000000000..19baab13a --- /dev/null +++ b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: data-impl yang module local name: config-data-tree +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Sun Apr 10 22:07:29 CEST 2016 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411; +public class ConfigDataTreeModuleFactory extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.AbstractConfigDataTreeModuleFactory { + +} -- cgit 1.2.3-korg