Mahesh Poojary Huawei | 337159c | 2015-12-04 02:21:02 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
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.PortPair; |
| 23 | import org.onosproject.vtnrsc.PortPairId; |
| 24 | import org.onosproject.vtnrsc.portpair.PortPairListener; |
| 25 | import org.onosproject.vtnrsc.portpair.PortPairService; |
| 26 | |
| 27 | /** |
| 28 | * Provides implementation of the portPairService. |
| 29 | */ |
Phaneendra Manda | 0f21ad6 | 2016-02-12 19:32:13 +0530 | [diff] [blame] | 30 | public class PortPairAdapter implements PortPairService { |
Mahesh Poojary Huawei | 337159c | 2015-12-04 02:21:02 +0530 | [diff] [blame] | 31 | |
| 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 | } |