blob: 5d7178c64562a93a2d36f9ff9215443ed376b37d [file] [log] [blame]
Carmelo Cascone326ad2d2017-11-28 18:09:13 -08001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.net.pi.impl;
18
19import org.onosproject.net.pi.runtime.PiEntity;
20import org.onosproject.net.pi.runtime.PiHandle;
21import org.onosproject.net.pi.service.PiTranslatable;
22import org.onosproject.net.pi.service.PiTranslatedEntity;
23import org.onosproject.net.pi.service.PiTranslationStore;
24import org.onosproject.net.pi.service.PiTranslator;
25
26import java.util.Optional;
27
28/**
29 * Abstract implementation of a PI translator backed by a PI translation store.
30 *
31 * @param <T> PD entity class
32 * @param <E> PI entity class
33 */
34public abstract class AbstractPiTranslatorImpl
35 <T extends PiTranslatable, E extends PiEntity>
36 implements PiTranslator<T, E> {
37
38 private final PiTranslationStore<T, E> store;
39
40 AbstractPiTranslatorImpl(PiTranslationStore<T, E> store) {
41 this.store = store;
42 }
43
44 @Override
45 public void learn(PiHandle<E> handle, PiTranslatedEntity<T, E> entity) {
46 store.addOrUpdate(handle, entity);
47 }
48
49 @Override
50 public Optional<PiTranslatedEntity<T, E>> lookup(PiHandle<E> handle) {
51 return Optional.ofNullable(store.get(handle));
52 }
53
54 @Override
55 public void forget(PiHandle<E> handle) {
56 store.remove(handle);
57 }
58}