/*
 * Copyright 2015 Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onosproject.vtnrsc.flowClassifier.impl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.vtnrsc.FlowClassifierId;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService;

import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;

import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;

/**
 * Provides implementation of the Flow Classifier Service.
 */
@Component(immediate = true)
@Service
public class FlowClassifierManager implements FlowClassifierService {

    private final Logger log = getLogger(FlowClassifierManager.class);

    private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null";
    private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null";

    private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore
    = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>();

    @Activate
    private void activate() {
        log.info("Flow Classifier service activated");
    }

    @Deactivate
    private void deactivate() {
        log.info("Flow Classifier service deactivated");
    }

    @Override
    public boolean createFlowClassifier(FlowClassifier flowClassifier) {
        log.debug("createFlowClassifier");
        checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
        FlowClassifierId id = flowClassifier.flowClassifierId();

        flowClassifierStore.put(id, flowClassifier);
        if (!flowClassifierStore.containsKey(id)) {
            log.debug("Flow Classifier creation is failed whose identifier is {}.", id.toString());
            return false;
        }
        return true;
    }

    @Override
    public Iterable<FlowClassifier> getFlowClassifiers() {
        return ImmutableList.copyOf(flowClassifierStore.values());
    }

    @Override
    public boolean hasFlowClassifier(FlowClassifierId id) {
        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
        return flowClassifierStore.containsKey(id);
    }

    @Override
    public FlowClassifier getFlowClassifier(FlowClassifierId id) {
        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
        return flowClassifierStore.get(id);
    }

    @Override
    public boolean updateFlowClassifier(FlowClassifier flowClassifier) {
        checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL);
        FlowClassifierId id = flowClassifier.flowClassifierId();
        return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier);
    }

    @Override
    public boolean removeFlowClassifier(FlowClassifierId id) {
        checkNotNull(id, FLOW_CLASSIFIER_ID_NOT_NULL);
        flowClassifierStore.remove(id);
        if (flowClassifierStore.containsKey(id)) {
            log.debug("The Flow Classifier removal is failed whose identifier is {}", id.toString());
            return false;
        }
        return true;
    }
}
@@ -667,91 +667,101 @@
 ort 
-java.util.concurrent.ConcurrentHashMap;%0Aimport java.util.concurrent.ConcurrentMap;%0A
+org.apache.felix.scr.annotations.Activate;%0Aimport org.apache.felix.scr.annotations.Component;
 %0Aimp
@@ -789,33 +789,35 @@
 scr.annotations.
-A
+Dea
 ctivate;%0Aimport 
@@ -853,118 +853,453 @@
 ons.
-Component;%0Aimport org.apache.felix.scr.annotations.Deactivate;%0Aimport org.apache.felix.scr.annotations.Service
+Reference;%0Aimport org.apache.felix.scr.annotations.ReferenceCardinality;%0Aimport org.apache.felix.scr.annotations.Service;%0Aimport org.onlab.util.KryoNamespace;%0Aimport org.onosproject.store.serializers.KryoNamespaces;%0Aimport org.onosproject.store.service.EventuallyConsistentMap;%0Aimport org.onosproject.store.service.MultiValuedTimestamp;%0Aimport org.onosproject.store.service.StorageService;%0Aimport org.onosproject.store.service.WallClockTimestamp
 ;%0Aim
@@ -1458,17 +1458,16 @@
 ervice;%0A
-%0A
 import o
@@ -1479,24 +1479,25 @@
 f4j.Logger;%0A
+%0A
 import stati
@@ -1525,33 +1525,32 @@
 tory.getLogger;%0A
-%0A
 import static co
@@ -1598,16 +1598,17 @@
 otNull;%0A
+%0A
 import c
@@ -2101,23 +2101,33 @@
 private 
-Concurr
+EventuallyConsist
 entMap%3CF
@@ -2182,118 +2182,674 @@
 tore
+;
 %0A    
-= new ConcurrentHashMap%3CFlowClassifierId, FlowClassifier%3E();%0A%0A    @Activate%0A    private void activate() %7B
+@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)%0A    protected StorageService storageService;%0A%0A    @Activate%0A    private void activate() %7B%0A        KryoNamespace.Builder serializer = KryoNamespace.newBuilder()%0A                .register(KryoNamespaces.API)%0A                .register(MultiValuedTimestamp.class)%0A                .register(FlowClassifier.class);%0A        flowClassifierStore = storageService%0A                .%3CFlowClassifierId, FlowClassifier%3EeventuallyConsistentMapBuilder()%0A                .withName(%22flowclassifierstore%22).withSerializer(serializer)%0A                .withTimestampProvider((k, v) -%3E new WallClockTimestamp()).build();
 %0A   
@@ -2947,32 +2947,71 @@
  deactivate() %7B%0A
+        flowClassifierStore.destroy();%0A
         log.info
@@ -4325,39 +4325,32 @@
 erId();%0A        
-return 
 flowClassifierSt
@@ -4357,15 +4357,11 @@
 ore.
-replace
+put
 (id,
@@ -4379,38 +4379,30 @@
 fier
-Store.get(id), flowClassifier)
+);%0A        return true
 ;%0A  

Change ConcurrentMap to EventuallyConsistentMap in FlowClassifierManager; It should be a distributed store.