blob: 6e3de445cad3b53c9837351fe8ff30469ed808a4 [file] [log] [blame]
Mahesh Poojary Huawei337159c2015-12-04 02:21:02 +05301/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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.PortPairGroup;
23import org.onosproject.vtnrsc.PortPairGroupId;
24import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
25import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
26
27/**
28 * Provides implementation of the portPairGroupService.
29 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053030public class PortPairGroupAdapter implements PortPairGroupService {
Mahesh Poojary Huawei337159c2015-12-04 02:21:02 +053031
32 private ConcurrentMap<PortPairGroupId, PortPairGroup> portPairGroupStore = new ConcurrentHashMap<>();
33
34 @Override
35 public boolean exists(PortPairGroupId portPairGroupId) {
36 return portPairGroupStore.containsKey(portPairGroupId);
37 }
38
39 @Override
40 public int getPortPairGroupCount() {
41 return portPairGroupStore.size();
42 }
43
44 @Override
45 public Iterable<PortPairGroup> getPortPairGroups() {
46 return Collections.unmodifiableCollection(portPairGroupStore.values());
47 }
48
49 @Override
50 public PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId) {
51 return portPairGroupStore.get(portPairGroupId);
52 }
53
54 @Override
55 public boolean createPortPairGroup(PortPairGroup portPairGroup) {
56 portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup);
57 if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) {
58 return false;
59 }
60 return true;
61 }
62
63 @Override
64 public boolean updatePortPairGroup(PortPairGroup portPairGroup) {
65 if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) {
66 return false;
67 }
68
69 portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup);
70
71 if (!portPairGroup.equals(portPairGroupStore.get(portPairGroup.portPairGroupId()))) {
72 return false;
73 }
74 return true;
75 }
76
77 @Override
78 public boolean removePortPairGroup(PortPairGroupId portPairGroupId) {
79 return true;
80 }
81
82 @Override
83 public void addListener(PortPairGroupListener listener) {
84 }
85
86 @Override
87 public void removeListener(PortPairGroupListener listener) {
88 }
89}