2 * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.sfc.sbrest.provider.listener;
10 import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStart;
11 import static org.opendaylight.sfc.provider.SfcProviderDebug.printTraceStop;
13 import java.util.Collection;
14 import java.util.concurrent.ExecutorService;
15 import java.util.concurrent.Executors;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
19 import org.opendaylight.sfc.provider.api.SfcInstanceIdentifiers;
20 import org.opendaylight.sfc.sbrest.provider.task.RestOperation;
21 import org.opendaylight.sfc.sbrest.provider.task.SbRestSffTask;
22 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sff.rev140701.service.function.forwarders.ServiceFunctionForwarder;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class SbRestSffEntryDataListener extends SbRestAbstractDataListener<ServiceFunctionForwarder> {
27 private static final Logger LOG = LoggerFactory.getLogger(SbRestSffEntryDataListener.class);
28 private final ExecutorService executor = Executors.newFixedThreadPool(5);
30 public SbRestSffEntryDataListener() {
31 setInstanceIdentifier(SfcInstanceIdentifiers.SFF_ENTRY_IID);
34 public void setDataProvider(DataBroker dataBroker) {
35 setDataBroker(dataBroker);
36 registerAsDataChangeListener();
40 public void onDataTreeChanged(Collection<DataTreeModification<ServiceFunctionForwarder>> changes) {
42 for (DataTreeModification<ServiceFunctionForwarder> change: changes) {
43 DataObjectModification<ServiceFunctionForwarder> rootNode = change.getRootNode();
44 switch (rootNode.getModificationType()) {
45 case SUBTREE_MODIFIED:
47 ServiceFunctionForwarder updatedServiceFunctionForwarder = rootNode.getDataAfter();
48 LOG.debug("\nUpdated Service Function Forwarder Name: {}",
49 updatedServiceFunctionForwarder.getName());
51 RestOperation restOp = rootNode.getDataBefore() == null ? RestOperation.POST
53 executor.execute(new SbRestSffTask(restOp, updatedServiceFunctionForwarder, executor));
56 ServiceFunctionForwarder originalServiceFunctionForwarder = rootNode.getDataBefore();
57 LOG.debug("\nDeleted Service Function Forwarder Name: {}",
58 originalServiceFunctionForwarder.getName());
60 executor.execute(new SbRestSffTask(RestOperation.DELETE, originalServiceFunctionForwarder,