Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
| 16 | package org.onosproject.sfc.util; |
| 17 | |
| 18 | import java.util.concurrent.ConcurrentHashMap; |
| 19 | import java.util.concurrent.ConcurrentMap; |
| 20 | |
| 21 | import org.onosproject.vtnrsc.TenantNetwork; |
| 22 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 23 | import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
| 24 | |
| 25 | import com.google.common.collect.ImmutableList; |
| 26 | |
| 27 | /** |
| 28 | * Provides implementation of the VtnRsc service. |
| 29 | */ |
| 30 | public class TenantNetworkAdapter implements TenantNetworkService { |
| 31 | |
| 32 | private final ConcurrentMap<TenantNetworkId, TenantNetwork> tenantNetworkStore = new ConcurrentHashMap<>(); |
| 33 | |
| 34 | @Override |
| 35 | public boolean exists(TenantNetworkId networkId) { |
| 36 | return tenantNetworkStore.containsKey(networkId); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public int getNetworkCount() { |
| 41 | return tenantNetworkStore.size(); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public Iterable<TenantNetwork> getNetworks() { |
| 46 | return ImmutableList.copyOf(tenantNetworkStore.values()); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public TenantNetwork getNetwork(TenantNetworkId networkId) { |
| 51 | return tenantNetworkStore.get(networkId); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public boolean createNetworks(Iterable<TenantNetwork> networks) { |
| 56 | for (TenantNetwork network : networks) { |
| 57 | tenantNetworkStore.put(network.id(), network); |
| 58 | if (!tenantNetworkStore.containsKey(network.id())) { |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean updateNetworks(Iterable<TenantNetwork> networks) { |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean removeNetworks(Iterable<TenantNetworkId> networksIds) { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | } |