1 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.translate.utils.rev160406;
3 import com.google.common.base.Optional;
4 import io.fd.honeycomb.v3po.translate.MappingContext;
5 import javax.annotation.Nonnull;
6 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
7 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
8 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
9 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
10 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
11 import org.opendaylight.yangtools.yang.binding.DataObject;
12 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 public class RealtimeMappingContextModule extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.translate.utils.rev160406.AbstractRealtimeMappingContextModule {
15 public RealtimeMappingContextModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
16 super(identifier, dependencyResolver);
19 public RealtimeMappingContextModule(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.translate.utils.rev160406.RealtimeMappingContextModule oldModule, java.lang.AutoCloseable oldInstance) {
20 super(identifier, dependencyResolver, oldModule, oldInstance);
24 public void customValidation() {
25 // add custom validation form module attributes here.
29 public java.lang.AutoCloseable createInstance() {
30 // Provides real time CRUD on top of Context data broker
31 return new MappingContext() {
34 public <T extends DataObject> Optional<T> read(@Nonnull final InstanceIdentifier<T> currentId) {
35 try(ReadOnlyTransaction tx = getContextBindingBrokerDependency().newReadOnlyTransaction()) {
37 return tx.read(LogicalDatastoreType.OPERATIONAL, currentId).checkedGet();
38 } catch (ReadFailedException e) {
39 throw new IllegalStateException("Unable to perform read of " + currentId, e);
45 public void delete(final InstanceIdentifier<?> path) {
46 final WriteTransaction writeTx = getContextBindingBrokerDependency().newWriteOnlyTransaction();
47 writeTx.delete(LogicalDatastoreType.OPERATIONAL, path);
49 writeTx.submit().checkedGet();
50 } catch (TransactionCommitFailedException e) {
51 throw new IllegalStateException("Unable to perform delete of " + path, e);
56 public <T extends DataObject> void merge(final InstanceIdentifier<T> path, final T data) {
57 final WriteTransaction writeTx = getContextBindingBrokerDependency().newWriteOnlyTransaction();
58 writeTx.merge(LogicalDatastoreType.OPERATIONAL, path, data);
60 writeTx.submit().checkedGet();
61 } catch (TransactionCommitFailedException e) {
62 throw new IllegalStateException("Unable to perform merge of " + path, e);
67 public <T extends DataObject> void put(final InstanceIdentifier<T> path, final T data) {
68 final WriteTransaction writeTx = getContextBindingBrokerDependency().newWriteOnlyTransaction();
69 writeTx.put(LogicalDatastoreType.OPERATIONAL, path, data);
71 writeTx.submit().checkedGet();
72 } catch (TransactionCommitFailedException e) {
73 throw new IllegalStateException("Unable to perform put of " + path, e);