2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.samples.interfaces.mapping.oper;
19 import com.google.inject.Inject;
20 import io.fd.honeycomb.samples.interfaces.mapping.LowerLayerAccess;
21 import io.fd.honeycomb.translate.impl.read.GenericListReader;
22 import io.fd.honeycomb.translate.impl.read.GenericReader;
23 import io.fd.honeycomb.translate.read.ReaderFactory;
24 import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
25 import javax.annotation.Nonnull;
26 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.InterfacesState;
27 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.InterfacesStateBuilder;
28 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810._interface.state.Counters;
29 import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.Interface;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 public class InterfacesReaderFactory implements ReaderFactory {
35 private final LowerLayerAccess access;
38 public InterfacesReaderFactory(@Nonnull final LowerLayerAccess access) {
43 public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) {
44 // ReaderFactory is intended for registering Readers into HC framework
45 // Readers provide ONLY operational (config "false") data straight from underlying device/layer
46 // they are triggered when RESTCONF GET on operational is invoked or when NETCONF get operation is executed
48 // Our model root for operational data is InterfacesState
49 final InstanceIdentifier<InterfacesState> root = InstanceIdentifier.create(InterfacesState.class);
50 // Since InterfacesState has no direct data children (leaves) only a structural reader is registered
51 // This reader just fills in the composite hierarchy of readers
52 // Honeycomb can't automatically instantiate structural readers and plugins have to help it by invoking as:
53 registry.addStructuralReader(root, InterfacesStateBuilder.class);
55 // Next child node is Interface (list)
56 final InstanceIdentifier<Interface> ifcListId = root.child(Interface.class);
57 registry.add(new GenericListReader<>(ifcListId, new InterfaceReaderCustomizer(access)));
59 // Next child is a container Counters
60 final InstanceIdentifier<Counters> countersId = ifcListId.child(Counters.class);
61 // By adding the reader with addAfter, we can ensure ordering of execution among the readers
62 // Useful in cases when a certain read has to be invoked before/after another
63 // In this case, we are ensuring that Counters are read after Interface is read
64 // "add" could be used instead, leaving the ordering to "nature"
65 // Same applies for writers
66 registry.addAfter(new GenericReader<>(countersId, new CountersReaderCustomizer(access)), ifcListId);