Phaneendra Manda | bc7c694 | 2015-12-03 16:33:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Phaneendra Manda | bc7c694 | 2015-12-03 16:33:24 +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.vtnrsc.classifier.impl; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.store.serializers.KryoNamespaces; |
| 28 | import org.onosproject.store.service.DistributedSet; |
| 29 | import org.onosproject.store.service.Serializer; |
| 30 | import org.onosproject.store.service.StorageService; |
| 31 | import org.onosproject.vtnrsc.classifier.ClassifierService; |
| 32 | import org.slf4j.Logger; |
| 33 | |
| 34 | import com.google.common.collect.ImmutableList; |
| 35 | |
| 36 | /** |
| 37 | * Provides implementation of the Classifier Service. |
| 38 | */ |
| 39 | @Component(immediate = true) |
| 40 | @Service |
| 41 | public class ClassifierManager implements ClassifierService { |
| 42 | |
| 43 | private final Logger log = getLogger(ClassifierManager.class); |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 46 | protected StorageService storageService; |
| 47 | |
| 48 | private DistributedSet<DeviceId> classifierList; |
| 49 | |
| 50 | @Activate |
| 51 | protected void activate() { |
| 52 | classifierList = storageService.<DeviceId>setBuilder() |
| 53 | .withName("classifier") |
| 54 | .withSerializer(Serializer.using(KryoNamespaces.API)) |
Madan Jampani | 538be74 | 2016-02-10 14:55:38 -0800 | [diff] [blame] | 55 | .build() |
| 56 | .asDistributedSet(); |
Phaneendra Manda | bc7c694 | 2015-12-03 16:33:24 +0530 | [diff] [blame] | 57 | log.info("Started"); |
| 58 | } |
| 59 | |
| 60 | @Deactivate |
| 61 | protected void deactivate() { |
| 62 | log.info("Stopped"); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void addClassifier(DeviceId deviceId) { |
| 67 | classifierList.add(deviceId); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Iterable<DeviceId> getClassifiers() { |
| 72 | return ImmutableList.copyOf(classifierList); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void removeClassifier(DeviceId deviceId) { |
| 77 | classifierList.remove(deviceId); |
| 78 | } |
| 79 | } |