blob: c76b2e6f4561c44067f458bc75de34bf28f4f609 [file] [log] [blame]
Mahesh Poojary Huaweiaec251d2015-12-04 02:27:45 +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.PortChain;
23import org.onosproject.vtnrsc.PortChainId;
24import org.onosproject.vtnrsc.portchain.PortChainService;
25import org.onosproject.vtnrsc.portchain.PortChainEvent;
26import org.onosproject.vtnrsc.portchain.PortChainListener;
27import org.onosproject.event.AbstractListenerManager;
28
29/**
30 * Provides implementation of the portChainService.
31 */
Phaneendra Manda0f21ad62016-02-12 19:32:13 +053032public class PortChainAdapter
Mahesh Poojary Huaweiaec251d2015-12-04 02:27:45 +053033 extends AbstractListenerManager<PortChainEvent, PortChainListener>
34 implements PortChainService {
35
36 private ConcurrentMap<PortChainId, PortChain> portChainStore = new ConcurrentHashMap<>();
37
38 @Override
39 public boolean exists(PortChainId portChainId) {
40 return portChainStore.containsKey(portChainId);
41 }
42
43 @Override
44 public int getPortChainCount() {
45 return portChainStore.size();
46 }
47
48 @Override
49 public Iterable<PortChain> getPortChains() {
50 return Collections.unmodifiableCollection(portChainStore.values());
51 }
52
53 @Override
54 public PortChain getPortChain(PortChainId portChainId) {
55 return portChainStore.get(portChainId);
56 }
57
58 @Override
59 public boolean createPortChain(PortChain portChain) {
60 portChainStore.put(portChain.portChainId(), portChain);
61 if (!portChainStore.containsKey(portChain.portChainId())) {
62 return false;
63 }
64 return true;
65 }
66
67 @Override
68 public boolean updatePortChain(PortChain portChain) {
69 if (!portChainStore.containsKey(portChain.portChainId())) {
70 return false;
71 }
72
73 portChainStore.put(portChain.portChainId(), portChain);
74
75 if (!portChain.equals(portChainStore.get(portChain.portChainId()))) {
76 return false;
77 }
78 return true;
79 }
80
81 @Override
82 public boolean removePortChain(PortChainId portChainId) {
83 return true;
84 }
85}