Mahesh Poojary Huawei | 337159c | 2015-12-04 02:21:02 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary Huawei | 337159c | 2015-12-04 02:21:02 +0530 | [diff] [blame] | 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 | package org.onosproject.sfc.util; |
| 17 | |
| 18 | import java.util.concurrent.ConcurrentMap; |
| 19 | import java.util.concurrent.ConcurrentHashMap; |
| 20 | import java.util.Collections; |
| 21 | |
| 22 | import org.onosproject.vtnrsc.PortPairGroup; |
| 23 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 24 | import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener; |
| 25 | import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; |
| 26 | |
| 27 | /** |
| 28 | * Provides implementation of the portPairGroupService. |
| 29 | */ |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 30 | public class PortPairGroupAdapter implements PortPairGroupService { |
Mahesh Poojary Huawei | 337159c | 2015-12-04 02:21:02 +0530 | [diff] [blame] | 31 | |
| 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 | } |