HONEYCOMB-443: fix benchmark after ODL Neon bump
[honeycomb.git] / infra / it / benchmark / src / main / java / io / fd / honeycomb / benchmark / util / StaticReader.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.benchmark.util;
18
19 import io.fd.honeycomb.translate.read.ReadContext;
20 import io.fd.honeycomb.translate.read.Reader;
21 import java.util.Optional;
22 import javax.annotation.Nonnull;
23 import javax.annotation.concurrent.NotThreadSafe;
24 import org.opendaylight.yangtools.concepts.Builder;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27
28 /**
29  * Statically preconfigured reader.
30  */
31 @NotThreadSafe
32 public final class StaticReader<T extends DataObject, B extends Builder<T>> implements Reader<T, B> {
33
34     private final InstanceIdentifier<T> id;
35     private final DataProvider data;
36     private long counter = 0;
37
38     public StaticReader(final InstanceIdentifier<T> id, final DataProvider data) {
39         this.id = id;
40         this.data = data;
41     }
42
43     @Nonnull
44     @Override
45     public InstanceIdentifier<T> getManagedDataObjectType() {
46         return id;
47     }
48
49     @Override
50     public String toString() {
51         return "NoopReader{" +
52                 id.getTargetType().getSimpleName() +
53                 ", counter=" + counter +
54                 '}';
55     }
56
57     @Override
58     public boolean isPresent(@Nonnull final InstanceIdentifier<T> id, @Nonnull final T built,
59                              @Nonnull final ReadContext ctx) {
60         return true;
61     }
62
63     @Nonnull
64     @Override
65     public Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id,
66                                                @Nonnull final ReadContext ctx) {
67         counter++;
68         return Optional.of(data.getData(counter));
69     }
70
71     @Override
72     public void readCurrentAttributes(@Nonnull final InstanceIdentifier<T> id, @Nonnull final B builder,
73                                       @Nonnull final ReadContext ctx) {
74         throw new UnsupportedOperationException("No read current attrs!");
75     }
76
77     @Nonnull
78     @Override
79     public B getBuilder(final InstanceIdentifier<T> id) {
80         throw new UnsupportedOperationException("No builder!");
81     }
82
83     @Override
84     public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final T readValue) {
85         throw new UnsupportedOperationException("No merge!");
86     }
87 }