BUG-4117: add impl for FlowCapableNode Connector notif.
[openflowplugin.git] / applications / old-notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / old / notification / supplier / OldNotifProviderImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.applications.old.notification.supplier;
10
11 import com.google.common.annotations.VisibleForTesting;
12 import com.google.common.base.Preconditions;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.List;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
18 import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.NodeConnectorNotificationSupplierImpl;
19 import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.NodeNotificationSupplierImpl;
20 import org.opendaylight.openflowplugin.applications.old.notification.supplier.tools.OldNotifProviderConfig;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
27
28 /**
29  * Provider Implementation
30  */
31 public class OldNotifProviderImpl implements OldNotifProvider {
32
33     private final DataBroker db;
34     private final OldNotifProviderConfig config;
35     private final NotificationProviderService nps;
36
37     /* Supplier List property help for easy close method implementation and testing */
38     private List<OldNotifSupplierDefinition<?>> supplierList;
39     private OldNotifSupplierForItemRoot<FlowCapableNode, NodeUpdated, NodeRemoved> nodeSupp;
40     private OldNotifSupplierForItemRoot<FlowCapableNodeConnector, NodeConnectorUpdated, NodeConnectorRemoved> connectorSupp;
41
42     /**
43      * Provider constructor set all needed final parameters
44      *
45      * @param config - Configuration Object
46      * @param nps - notifProviderService
47      * @param db - dataBroker
48      */
49     public OldNotifProviderImpl(final OldNotifProviderConfig config,
50             final NotificationProviderService nps, final DataBroker db) {
51         this.config = Preconditions.checkNotNull(config);
52         this.db = Preconditions.checkNotNull(db);
53         this.nps = Preconditions.checkNotNull(nps);
54     }
55
56     @Override
57     public void start() {
58         nodeSupp = new NodeNotificationSupplierImpl(nps, db);
59         connectorSupp = new NodeConnectorNotificationSupplierImpl(nps, db);
60
61         supplierList = new ArrayList<>(Arrays.<OldNotifSupplierDefinition<?>> asList(nodeSupp, connectorSupp));
62     }
63
64     @Override
65     public void close() throws Exception {
66         for (OldNotifSupplierDefinition<?> supplier : supplierList) {
67             if (supplier != null) {
68                 supplier.close();
69                 supplier = null;
70             }
71         }
72     }
73
74     @VisibleForTesting
75     List<OldNotifSupplierDefinition<?>> getSupplierList() {
76         return supplierList;
77     }
78 }
79