blob: 51a94094722f4cefe5dde402bf2663d45d0a14a5 [file] [log] [blame]
Phaneendra Mandabc7c6942015-12-03 16:33:24 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Phaneendra Mandabc7c6942015-12-03 16:33:24 +05303 *
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.vtnrsc.classifier.impl;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onosproject.net.DeviceId;
27import org.onosproject.store.serializers.KryoNamespaces;
28import org.onosproject.store.service.DistributedSet;
29import org.onosproject.store.service.Serializer;
30import org.onosproject.store.service.StorageService;
31import org.onosproject.vtnrsc.classifier.ClassifierService;
32import org.slf4j.Logger;
33
34import com.google.common.collect.ImmutableList;
35
36/**
37 * Provides implementation of the Classifier Service.
38 */
39@Component(immediate = true)
40@Service
41public 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 Jampani538be742016-02-10 14:55:38 -080055 .build()
56 .asDistributedSet();
Phaneendra Mandabc7c6942015-12-03 16:33:24 +053057 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}