From 9d4dae985d986f9c8d4116319ff00a228788563c Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Tue, 22 Mar 2016 15:09:23 +0100 Subject: Initial implementation of VPP writers Composite, recursive and extensible writers Change-Id: I1fbd1d49af44343ab655e31d17ba51dd0f8ca268 Signed-off-by: Maros Marsalek --- .../honeycomb/v3po/impl/trans/util/VppRWUtils.java | 14 + .../trans/w/impl/AbstractCompositeVppWriter.java | 320 +++++++++++++++++++++ .../impl/trans/w/impl/CompositeChildVppWriter.java | 105 +++++++ .../impl/trans/w/impl/CompositeListVppWriter.java | 142 +++++++++ .../impl/trans/w/impl/CompositeRootVppWriter.java | 72 +++++ .../trans/w/impl/spi/ChildVppWriterCustomizer.java | 31 ++ .../trans/w/impl/spi/ListVppWriterCustomizer.java | 33 +++ .../trans/w/impl/spi/RootVppWriterCustomizer.java | 40 +++ .../trans/w/util/DelegatingWriterRegistry.java | 72 +++++ .../impl/trans/w/util/NoopWriterCustomizer.java | 45 +++ .../w/util/ReflexiveChildWriterCustomizer.java | 59 ++++ .../impl/trans/w/util/TransactionWriteContext.java | 88 ++++++ 12 files changed, 1021 insertions(+) create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/AbstractCompositeVppWriter.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeChildVppWriter.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeListVppWriter.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeRootVppWriter.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ChildVppWriterCustomizer.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ListVppWriterCustomizer.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/RootVppWriterCustomizer.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistry.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/NoopWriterCustomizer.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/ReflexiveChildWriterCustomizer.java create mode 100644 v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContext.java (limited to 'v3po') diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/util/VppRWUtils.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/util/VppRWUtils.java index fe0f1f2fb..d11910b6f 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/util/VppRWUtils.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/util/VppRWUtils.java @@ -23,6 +23,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import io.fd.honeycomb.v3po.impl.trans.SubtreeManager; import io.fd.honeycomb.v3po.impl.trans.r.ChildVppReader; +import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -61,10 +62,18 @@ public final class VppRWUtils { return Collections.emptyList(); } + public static List>> emptyChildWriterList() { + return Collections.emptyList(); + } + public static List>> emptyAugReaderList() { return Collections.emptyList(); } + public static List>> emptyAugWriterList() { + return Collections.emptyList(); + } + public static List>> singletonAugReaderList( ChildVppReader> item) { return Collections.>>singletonList(item); @@ -75,6 +84,11 @@ public final class VppRWUtils { return Collections.>>singletonList(item); } + public static List>> singletonChildWriterList( + ChildVppWriter> item) { + return Collections.>>singletonList(item); + } + /** * Replace last item in ID with a provided IdentifiableItem of the same type */ diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/AbstractCompositeVppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/AbstractCompositeVppWriter.java new file mode 100644 index 000000000..44690bd28 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/AbstractCompositeVppWriter.java @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.base.Function; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils; +import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.VppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AbstractCompositeVppWriter implements VppWriter { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractCompositeVppWriter.class); + + public static final Function INDEX_FUNCTION = new Function() { + @Override + public Object apply(final DataObject input) { + return input instanceof Identifiable + ? ((Identifiable) input).getKey() + : input; + } + }; + + private final Map, ChildVppWriter>> childReaders; + private final Map, ChildVppWriter>> augReaders; + private final InstanceIdentifier instanceIdentifier; + + public AbstractCompositeVppWriter(final Class type, + final List>> childReaders, + final List>> augReaders) { + this.instanceIdentifier = InstanceIdentifier.create(type); + this.childReaders = VppRWUtils.uniqueLinkedIndex(childReaders, VppRWUtils.MANAGER_CLASS_FUNCTION); + this.augReaders = VppRWUtils.uniqueLinkedIndex(augReaders, VppRWUtils.MANAGER_CLASS_AUG_FUNCTION); + } + + protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) { + LOG.debug("{}: Writing current: {} data: {}", this, id, data); + + LOG.trace("{}: Writing current attributes", this); + writeCurrentAttributes(id, data, ctx); + + for (ChildVppWriter> child : childReaders.values()) { + LOG.debug("{}: Writing child in: {}", this, child); + child.writeChild(id, data, ctx); + } + + for (ChildVppWriter> child : augReaders.values()) { + LOG.debug("{}: Writing augment in: {}", this, child); + child.writeChild(id, data, ctx); + } + + LOG.debug("{}: Current node written successfully", this); + } + + protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, + final WriteContext ctx) { + LOG.debug("{}: Updating current: {} dataBefore: {}, datAfter: {}", this, id, dataBefore, dataAfter); + + if(dataBefore.equals(dataAfter)) { + LOG.debug("{}: Skipping current(no update): {}", this, id); + // No change, ignore + return; + } + + LOG.trace("{}: Updating current attributes", this); + updateCurrentAttributes(id, dataBefore, dataAfter, ctx); + + for (ChildVppWriter> child : childReaders.values()) { + LOG.debug("{}: Updating child in: {}", this, child); + child.updateChild(id, dataBefore, dataAfter, ctx); + } + + for (ChildVppWriter> child : augReaders.values()) { + LOG.debug("{}: Updating augment in: {}", this, child); + child.updateChild(id, dataBefore, dataAfter, ctx); + } + + LOG.debug("{}: Current node updated successfully", this); + } + + protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) { + LOG.debug("{}: Deleting current: {} dataBefore: {}", this, id, dataBefore); + + // delete in reversed order + for (ChildVppWriter> child : reverseCollection(augReaders.values())) { + LOG.debug("{}: Deleting augment in: {}", this, child); + child.deleteChild(id, dataBefore, ctx); + } + + for (ChildVppWriter> child : reverseCollection(childReaders.values())) { + LOG.debug("{}: Deleting child in: {}", this, child); + child.deleteChild(id, dataBefore, ctx); + } + + LOG.trace("{}: Deleting current attributes", this); + deleteCurrentAttributes(id, dataBefore, ctx); + } + + @SuppressWarnings("unchecked") + @Override + public void update(@Nonnull final InstanceIdentifier id, + @Nonnull final List dataBefore, + @Nonnull final List dataAfter, + @Nonnull final WriteContext ctx) { + LOG.debug("{}: Updating : {}", this, id); + LOG.trace("{}: Updating : {}, from: {} to: {}", this, id, dataBefore, dataAfter); + + if (idPointsToCurrent(id)) { + if(isWrite(dataBefore, dataAfter)) { + writeAll((InstanceIdentifier) id, dataAfter, ctx); + } else if(isDelete(dataBefore, dataAfter)) { + deleteAll((InstanceIdentifier) id, dataBefore, ctx); + } else { + checkArgument(!dataBefore.isEmpty() && !dataAfter.isEmpty(), "No data to process"); + updateAll((InstanceIdentifier) id, dataBefore, dataAfter, ctx); + } + } else { + if (isWrite(dataBefore, dataAfter)) { + writeSubtree(id, dataAfter, ctx); + } else if (isDelete(dataBefore, dataAfter)) { + deleteSubtree(id, dataBefore, ctx); + } else { + checkArgument(!dataBefore.isEmpty() && !dataAfter.isEmpty(), "No data to process"); + updateSubtree(id, dataBefore, dataAfter, ctx); + } + } + } + + protected void updateAll(final @Nonnull InstanceIdentifier id, + final @Nonnull List dataBefore, + final @Nonnull List dataAfter, final WriteContext ctx) { + LOG.trace("{}: Updating all : {}", this, id); + + final Map indexedAfter = indexData(dataAfter); + final Map indexedBefore = indexData(dataBefore); + + for (Map.Entry after : indexedAfter.entrySet()) { + final DataObject before = indexedBefore.get(after.getKey()); + if(before == null) { + writeCurrent(id, castToManaged(after.getValue()), ctx); + } else { + updateCurrent(id, castToManaged(before), castToManaged(after.getValue()), ctx); + } + } + + // Delete the rest in dataBefore + for (Object deletedNodeKey : Sets.difference(indexedBefore.keySet(), indexedAfter.keySet())) { + final DataObject deleted = indexedBefore.get(deletedNodeKey); + deleteCurrent(id, castToManaged(deleted), ctx); + } + } + + private static Map indexData(final List data) { + return Maps.uniqueIndex(data, INDEX_FUNCTION); + } + + protected void deleteAll(final @Nonnull InstanceIdentifier id, + final @Nonnull List dataBefore, final WriteContext ctx) { + LOG.trace("{}: Deleting all : {}", this, id); + for (DataObject singleValue : dataBefore) { + checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleValue.getClass())); + deleteCurrent(id, castToManaged(singleValue), ctx); + } + } + + private D castToManaged(final DataObject data) { + checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(data.getClass())); + return getManagedDataObjectType().getTargetType().cast(data); + } + + protected void writeAll(final @Nonnull InstanceIdentifier id, + final @Nonnull List dataAfter, final WriteContext ctx) { + LOG.trace("{}: Writing all : {}", this, id); + for (DataObject singleValue : dataAfter) { + checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleValue.getClass())); + writeCurrent(id, castToManaged(singleValue), ctx); + } + } + + private static boolean isWrite(final List dataBefore, + final List dataAfter) { + return dataBefore.isEmpty() && !dataAfter.isEmpty(); + } + + private static boolean isDelete(final List dataBefore, + final List dataAfter) { + return dataAfter.isEmpty() && !dataBefore.isEmpty(); + } + + private void writeSubtree(final InstanceIdentifier id, + final List dataAfter, final WriteContext ctx) { + LOG.debug("{}: Writing subtree: {}", this, id); + final VppWriter> vppWriter = getNextWriter(id); + + if (vppWriter != null) { + LOG.debug("{}: Writing subtree: {} in: {}", this, id, vppWriter); + vppWriter.update(id, Collections.emptyList(), dataAfter, ctx); + } else { + // If there's no dedicated writer, use write current + // But we need current data after to do so + final InstanceIdentifier currentId = VppRWUtils.cutId(id, getManagedDataObjectType()); + List currentDataAfter = ctx.readAfter(currentId); + LOG.debug("{}: Dedicated subtree writer missing for: {}. Writing current.", this, + VppRWUtils.getNextId(id, getManagedDataObjectType()).getType(), currentDataAfter); + writeAll(currentId, currentDataAfter, ctx); + } + } + + private boolean idPointsToCurrent(final @Nonnull InstanceIdentifier id) { + return id.getTargetType().equals(getManagedDataObjectType().getTargetType()); + } + + @SuppressWarnings("unchecked") + private void deleteSubtree(final InstanceIdentifier id, + final List dataBefore, final WriteContext ctx) { + LOG.debug("{}: Deleting subtree: {}", this, id); + final VppWriter> vppWriter = getNextWriter(id); + + if (vppWriter != null) { + LOG.debug("{}: Deleting subtree: {} in: {}", this, id, vppWriter); + vppWriter.update(id, dataBefore, Collections.emptyList(), ctx); + } else { + updateSubtreeFromCurrent(id, ctx); + } + } + + private void updateSubtreeFromCurrent(final InstanceIdentifier id, final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.cutId(id, getManagedDataObjectType()); + List currentDataBefore = ctx.readBefore(currentId); + List currentDataAfter = ctx.readAfter(currentId); + LOG.debug("{}: Dedicated subtree writer missing for: {}. Updating current without subtree", this, + VppRWUtils.getNextId(id, getManagedDataObjectType()).getType(), currentDataAfter); + updateAll((InstanceIdentifier) id, currentDataBefore, currentDataAfter, ctx); + } + + @SuppressWarnings("unchecked") + private void updateSubtree(final InstanceIdentifier id, + final List dataBefore, + final List dataAfter, + final WriteContext ctx) { + LOG.debug("{}: Updating subtree: {}", this, id); + final VppWriter> vppWriter = getNextWriter(id); + + if (vppWriter != null) { + LOG.debug("{}: Updating subtree: {} in: {}", this, id, vppWriter); + vppWriter.update(id, dataBefore, dataAfter, ctx); + } else { + updateSubtreeFromCurrent(id, ctx); + } + } + + private VppWriter> getNextWriter(final InstanceIdentifier id) { + final Class next = VppRWUtils.getNextId(id, getManagedDataObjectType()).getType(); + return childReaders.get(next); + } + + private static List reverseCollection(final Collection original) { + // TODO find a better reverse mechanism (probably a different collection for child readers is necessary) + final ArrayList list = Lists.newArrayList(original); + Collections.reverse(list); + return list; + } + + protected abstract void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D data, + @Nonnull final WriteContext ctx); + + protected abstract void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataBefore, + @Nonnull final WriteContext ctx); + + protected abstract void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataBefore, + @Nonnull final D dataAfter, + @Nonnull final WriteContext ctx); + + @Nonnull + @Override + public InstanceIdentifier getManagedDataObjectType() { + return instanceIdentifier; + } + + + @Override + public String toString() { + return String.format("Writer[%s]", getManagedDataObjectType().getTargetType().getSimpleName()); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeChildVppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeChildVppWriter.java new file mode 100644 index 000000000..919bbaa0f --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeChildVppWriter.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl; + +import com.google.common.base.Optional; +import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils; +import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import io.fd.honeycomb.v3po.impl.trans.w.impl.spi.ChildVppWriterCustomizer; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class CompositeChildVppWriter extends AbstractCompositeVppWriter + implements ChildVppWriter { + + private final ChildVppWriterCustomizer customizer; + + public CompositeChildVppWriter(@Nonnull final Class type, + @Nonnull final List>> childWriters, + @Nonnull final List>> augReaders, + @Nonnull final ChildVppWriterCustomizer customizer) { + super(type, childWriters, augReaders); + this.customizer = customizer; + } + + public CompositeChildVppWriter(@Nonnull final Class type, + @Nonnull final List>> childWriters, + @Nonnull final ChildVppWriterCustomizer customizer) { + this(type, childWriters, VppRWUtils.emptyAugWriterList(), customizer); + } + + public CompositeChildVppWriter(@Nonnull final Class type, + @Nonnull final ChildVppWriterCustomizer customizer) { + this(type, VppRWUtils.emptyChildWriterList(), VppRWUtils.emptyAugWriterList(), customizer); + } + + @Override + protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D data, + @Nonnull final WriteContext ctx) { + customizer.writeCurrentAttributes(id, data, ctx.getContext()); + } + + @Override + protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull WriteContext ctx) { + customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext()); + } + + @Override + protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final D dataAfter, @Nonnull WriteContext ctx) { + customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext()); + } + + @Override + public void writeChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentData, @Nonnull WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final Optional currentData = customizer.extract(currentId, parentData); + if(currentData.isPresent()) { + writeCurrent(currentId, currentData.get(), ctx); + } + } + + @Override + public void deleteChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentData, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final Optional currentData = customizer.extract(currentId, parentData); + if(currentData.isPresent()) { + deleteCurrent(currentId, currentData.get(), ctx); + } + } + + @Override + public void updateChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentDataBefore, @Nonnull final DataObject parentDataAfter, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final Optional before = customizer.extract(currentId, parentDataBefore); + final Optional after = customizer.extract(currentId, parentDataAfter); + if(before.isPresent() && after.isPresent()) { + updateCurrent(currentId, before.get(), after.get(), ctx); + } + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeListVppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeListVppWriter.java new file mode 100644 index 000000000..8914d3757 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeListVppWriter.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl; + +import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils; +import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import io.fd.honeycomb.v3po.impl.trans.w.impl.spi.ListVppWriterCustomizer; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class CompositeListVppWriter, K extends Identifier> extends AbstractCompositeVppWriter + implements ChildVppWriter { + + private final ListVppWriterCustomizer customizer; + + public CompositeListVppWriter(@Nonnull final Class type, + @Nonnull final List>> childReaders, + @Nonnull final List>> augReaders, + @Nonnull final ListVppWriterCustomizer customizer) { + super(type, childReaders, augReaders); + this.customizer = customizer; + } + + public CompositeListVppWriter(@Nonnull final Class type, + @Nonnull final List>> childReaders, + @Nonnull final ListVppWriterCustomizer customizer) { + this(type, childReaders, VppRWUtils.emptyAugWriterList(), customizer); + } + + public CompositeListVppWriter(@Nonnull final Class type, + @Nonnull final ListVppWriterCustomizer customizer) { + this(type, VppRWUtils.emptyChildWriterList(), VppRWUtils.emptyAugWriterList(), customizer); + + } + + @Override + protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D data, + @Nonnull final WriteContext ctx) { + customizer.writeCurrentAttributes(id, data, ctx.getContext()); + } + + @Override + protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final WriteContext ctx) { + customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext()); + } + + @Override + protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final D dataAfter, @Nonnull final WriteContext ctx) { + customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext()); + } + + @Override + public void writeChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentData, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final List currentData = customizer.extract(currentId, parentData); + writeAll(currentId, currentData, ctx); + } + + @Override + public void deleteChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentDataBefore, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final List dataBefore = customizer.extract(currentId, parentDataBefore); + deleteAll(currentId, dataBefore, ctx); + } + + @Override + public void updateChild(@Nonnull final InstanceIdentifier parentId, + @Nonnull final DataObject parentDataBefore, @Nonnull final DataObject parentDataAfter, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier currentId = VppRWUtils.appendTypeToId(parentId, getManagedDataObjectType()); + final List dataBefore = customizer.extract(currentId, parentDataBefore); + final List dataAfter = customizer.extract(currentId, parentDataAfter); + updateAll(currentId, dataBefore, dataAfter, ctx); + } + + @Override + protected void writeCurrent(final InstanceIdentifier id, final D data, final WriteContext ctx) { + // Make sure the key is present + if(isWildcarded(id)) { + super.writeCurrent(getSpecificId(id, data), data, ctx); + } else { + super.writeCurrent(id, data, ctx); + } + } + + @Override + protected void updateCurrent(final InstanceIdentifier id, final D dataBefore, final D dataAfter, + final WriteContext ctx) { + // Make sure the key is present + if(isWildcarded(id)) { + super.updateCurrent(getSpecificId(id, dataBefore), dataBefore, dataAfter, ctx); + } else { + super.updateCurrent(id, dataBefore, dataAfter, ctx); + } + } + + @Override + protected void deleteCurrent(final InstanceIdentifier id, final D dataBefore, final WriteContext ctx) { + // Make sure the key is present + if(isWildcarded(id)) { + super.deleteCurrent(getSpecificId(id, dataBefore), dataBefore, ctx); + } else { + super.deleteCurrent(id, dataBefore, ctx); + } + } + + private boolean isWildcarded(final InstanceIdentifier id) { + return id.firstIdentifierOf(getManagedDataObjectType().getTargetType()).isWildcarded(); + } + + private InstanceIdentifier getSpecificId(final InstanceIdentifier currentId, final D current) { + return VppRWUtils.replaceLastInId(currentId, + new InstanceIdentifier.IdentifiableItem<>(currentId.getTargetType(), current.getKey())); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeRootVppWriter.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeRootVppWriter.java new file mode 100644 index 000000000..6be5651b3 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/CompositeRootVppWriter.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl; + +import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils; +import io.fd.honeycomb.v3po.impl.trans.w.ChildVppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import io.fd.honeycomb.v3po.impl.trans.w.impl.spi.RootVppWriterCustomizer; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class CompositeRootVppWriter extends AbstractCompositeVppWriter { + + private final RootVppWriterCustomizer customizer; + + public CompositeRootVppWriter(@Nonnull final Class type, + @Nonnull final List>> childReaders, + @Nonnull final List>> augReaders, + @Nonnull final RootVppWriterCustomizer customizer) { + super(type, childReaders, augReaders); + this.customizer = customizer; + } + + public CompositeRootVppWriter(@Nonnull final Class type, + @Nonnull final List>> childReaders, + @Nonnull final RootVppWriterCustomizer customizer) { + this(type, childReaders, VppRWUtils.emptyAugWriterList(), customizer); + } + + public CompositeRootVppWriter(@Nonnull final Class type, + @Nonnull final RootVppWriterCustomizer customizer) { + this(type, VppRWUtils.emptyChildWriterList(), VppRWUtils.emptyAugWriterList(), customizer); + } + + @Override + protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D data, + @Nonnull final WriteContext ctx) { + customizer.writeCurrentAttributes(id, data, ctx.getContext()); + } + + @Override + protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final WriteContext ctx) { + customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext()); + } + + @Override + protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataBefore, + @Nonnull final D dataAfter, + @Nonnull final WriteContext ctx) { + customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext()); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ChildVppWriterCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ChildVppWriterCustomizer.java new file mode 100644 index 000000000..5ea504209 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ChildVppWriterCustomizer.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl.spi; + +import com.google.common.annotations.Beta; +import com.google.common.base.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@Beta +public interface ChildVppWriterCustomizer extends RootVppWriterCustomizer { + + @Nonnull + Optional extract(@Nonnull final InstanceIdentifier currentId, @Nonnull final DataObject parentData); + +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ListVppWriterCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ListVppWriterCustomizer.java new file mode 100644 index 000000000..edd8de930 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/ListVppWriterCustomizer.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl.spi; + +import com.google.common.annotations.Beta; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@Beta +public interface ListVppWriterCustomizer, K extends Identifier> extends RootVppWriterCustomizer { + + @Nonnull + List extract(@Nonnull final InstanceIdentifier currentId, @Nonnull final DataObject parentData); + +} \ No newline at end of file diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/RootVppWriterCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/RootVppWriterCustomizer.java new file mode 100644 index 000000000..6a2d0c2bf --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/impl/spi/RootVppWriterCustomizer.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.impl.spi; + +import com.google.common.annotations.Beta; +import io.fd.honeycomb.v3po.impl.trans.util.Context; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +@Beta +public interface RootVppWriterCustomizer { + + void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataAfter, + @Nonnull final Context writeContext); + + void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataBefore, + @Nonnull final D dataAfter, + @Nonnull final Context writeContext); + + void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final D dataBefore, + @Nonnull final Context writeContext); +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistry.java new file mode 100644 index 000000000..6df960626 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/DelegatingWriterRegistry.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.util; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.Iterables; +import io.fd.honeycomb.v3po.impl.trans.util.VppRWUtils; +import io.fd.honeycomb.v3po.impl.trans.w.VppWriter; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Simple reader registry able to perform and aggregated read (ROOT read) on top of all + * provided readers. Also able to delegate a specific read to one of the delegate readers. + * + * This could serve as a utility to hold & hide all available readers in upper layers. + */ +public final class DelegatingWriterRegistry implements VppWriter { + + private final Map, VppWriter> rootReaders; + + /** + * Create new {@link DelegatingWriterRegistry} + * + * @param rootReaders List of delegate readers + */ + public DelegatingWriterRegistry(@Nonnull final List> rootReaders) { + this.rootReaders = VppRWUtils.uniqueLinkedIndex(checkNotNull(rootReaders), VppRWUtils.MANAGER_CLASS_FUNCTION); + } + + /** + * @throws UnsupportedOperationException This getter is not supported for reader registry since it does not manage a + * specific node type + */ + @Nonnull + @Override + public InstanceIdentifier getManagedDataObjectType() { + throw new UnsupportedOperationException("Root registry has no type"); + } + + @Override + public void update(@Nonnull final InstanceIdentifier id, + @Nonnull final List dataBefore, + @Nonnull final List dataAfter, + @Nonnull final WriteContext ctx) { + final InstanceIdentifier.PathArgument first = checkNotNull( + Iterables.getFirst(id.getPathArguments(), null), "Empty id"); + final VppWriter vppWriter = rootReaders.get(first.getType()); + checkNotNull(vppWriter, + "Unable to write %s. Missing writer. Current writers for: %s", id, rootReaders.keySet()); + vppWriter.update(id, dataBefore, dataAfter, ctx); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/NoopWriterCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/NoopWriterCustomizer.java new file mode 100644 index 000000000..4f02a1d5e --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/NoopWriterCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.util; + +import io.fd.honeycomb.v3po.impl.trans.util.Context; +import io.fd.honeycomb.v3po.impl.trans.w.impl.spi.RootVppWriterCustomizer; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class NoopWriterCustomizer implements RootVppWriterCustomizer { + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataAfter, + @Nonnull final Context ctx) { + + } + + @Override + public void updateCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final D dataAfter, + @Nonnull final Context ctx) { + + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier id, @Nonnull final D dataBefore, + @Nonnull final Context ctx) { + + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/ReflexiveChildWriterCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/ReflexiveChildWriterCustomizer.java new file mode 100644 index 000000000..9d324a059 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/ReflexiveChildWriterCustomizer.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.util; + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +import io.fd.honeycomb.v3po.impl.trans.util.ReflectionUtils; +import io.fd.honeycomb.v3po.impl.trans.w.impl.spi.ChildVppWriterCustomizer; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Collections; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Might be slow ! + */ +public class ReflexiveChildWriterCustomizer extends NoopWriterCustomizer implements + ChildVppWriterCustomizer { + + @Nonnull + @Override + @SuppressWarnings("unchecked") + public Optional extract(@Nonnull final InstanceIdentifier currentId, @Nonnull final DataObject parentData) { + final Class currentType = currentId.getTargetType(); + final Optional method = ReflectionUtils.findMethodReflex(getParentType(currentId), + "get" + currentType.getSimpleName(), Collections.>emptyList(), currentType); + + Preconditions.checkArgument(method.isPresent(), "Unable to get %s from %s", currentType, parentData); + + try { + return method.isPresent() + ? Optional.of((C) method.get().invoke(parentData)) + : Optional.absent(); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("Unable to get " + currentType + " from " + parentData, e); + } + } + + private Class getParentType(final @Nonnull InstanceIdentifier currentId) { + return Iterables.get(currentId.getPathArguments(), Iterables.size(currentId.getPathArguments()) - 2).getType(); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContext.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContext.java new file mode 100644 index 000000000..3a1fd2f57 --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/w/util/TransactionWriteContext.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.trans.w.util; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import io.fd.honeycomb.v3po.impl.trans.util.Context; +import io.fd.honeycomb.v3po.impl.trans.w.WriteContext; +import java.util.Collections; +import java.util.List; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class TransactionWriteContext implements WriteContext, AutoCloseable { + + private final ReadOnlyTransaction beforeTx; + private final ReadOnlyTransaction afterTx; + private final Context ctx; + + public TransactionWriteContext(final ReadOnlyTransaction beforeTx, final ReadOnlyTransaction afterTx, + final Context ctx) { + super(); + this.beforeTx = beforeTx; + this.afterTx = afterTx; + this.ctx = ctx; + } + + public TransactionWriteContext(final ReadOnlyTransaction beforeTx, + final ReadOnlyTransaction afterTx) { + this(beforeTx, afterTx, new Context()); + } + + @Override + public List readBefore(final InstanceIdentifier currentId) { + return read(currentId, beforeTx); + } + + private List read(final InstanceIdentifier currentId, + final ReadOnlyTransaction tx) { + // FIXME how to read all for list (using wildcarded ID) ? + + final CheckedFuture, ReadFailedException> read = + tx.read(LogicalDatastoreType.CONFIGURATION, currentId); + try { + final Optional optional = read.checkedGet(); + return optional.isPresent() + ? Collections.singletonList(optional.get()) + : Collections.emptyList(); + } catch (ReadFailedException e) { + throw new IllegalStateException("Unable to perform read", e); + } + } + + @Override + public List readAfter(final InstanceIdentifier currentId) { + return read(currentId, afterTx); + } + + @Override + public Context getContext() { + return ctx; + } + + /** + * Does not close the transactions + */ + @Override + public void close() throws Exception { + ctx.close(); + } +} -- cgit 1.2.3-korg