blob: 20e13215c1748d163610e874ad2cf27a3f779b22 [file] [log] [blame]
Mahesh Poojary Huawei337159c2015-12-04 02:21:02 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Huawei337159c2015-12-04 02:21:02 +05303 *
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 */
16package org.onosproject.sfc.util;
17
18import java.util.concurrent.ConcurrentMap;
19import java.util.concurrent.ConcurrentHashMap;
20import java.util.Collections;
21
22import org.onosproject.vtnrsc.PortPair;
23import org.onosproject.vtnrsc.PortPairId;
24import org.onosproject.vtnrsc.portpair.PortPairListener;
25import org.onosproject.vtnrsc.portpair.PortPairService;
26
27/**
28 * Provides implementation of the portPairService.
29 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053030public class PortPairAdapter implements PortPairService {
Mahesh Poojary Huawei337159c2015-12-04 02:21:02 +053031
32 private ConcurrentMap<PortPairId, PortPair> portPairStore = new ConcurrentHashMap<>();
33
34 @Override
35 public boolean exists(PortPairId portPairId) {
36 return portPairStore.containsKey(portPairId);
37 }
38
39 @Override
40 public int getPortPairCount() {
41 return portPairStore.size();
42 }
43
44 @Override
45 public Iterable<PortPair> getPortPairs() {
46 return Collections.unmodifiableCollection(portPairStore.values());
47 }
48
49 @Override
50 public PortPair getPortPair(PortPairId portPairId) {
51 return portPairStore.get(portPairId);
52 }
53
54 @Override
55 public boolean createPortPair(PortPair portPair) {
56 portPairStore.put(portPair.portPairId(), portPair);
57 if (!portPairStore.containsKey(portPair.portPairId())) {
58 return false;
59 }
60 return true;
61 }
62
63 @Override
64 public boolean updatePortPair(PortPair portPair) {
65 if (!portPairStore.containsKey(portPair.portPairId())) {
66 return false;
67 }
68
69 portPairStore.put(portPair.portPairId(), portPair);
70
71 if (!portPair.equals(portPairStore.get(portPair.portPairId()))) {
72 return false;
73 }
74 return true;
75 }
76
77 @Override
78 public boolean removePortPair(PortPairId portPairId) {
79 return true;
80 }
81
82 @Override
83 public void addListener(PortPairListener listener) {
84 }
85
86 @Override
87 public void removeListener(PortPairListener listener) {
88 }
89}