Migrate test-provider to CompositeListener
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestNodeConnectorNotification.java
1 /*
2  * Copyright (c) 2014, 2015 Ericsson India Global Services Pvt Ltd. 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 package org.opendaylight.openflowplugin.test;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Set;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
15 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener.Component;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class OpenflowpluginTestNodeConnectorNotification {
24
25     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestNodeConnectorNotification.class);
26
27     private final PortEventListener portEventListener = new PortEventListener();
28     private final NotificationService notificationService;
29
30     public OpenflowpluginTestNodeConnectorNotification(final NotificationService notificationService) {
31         this.notificationService = notificationService;
32     }
33
34     public void init() {
35         // For switch events
36         notificationService.registerCompositeListener(portEventListener.toListener());
37     }
38
39     private static final class PortEventListener {
40         List<NodeUpdated> nodeUpdated = new ArrayList<>();
41         List<NodeRemoved> nodeRemoved = new ArrayList<>();
42         List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
43         List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
44
45         CompositeListener toListener() {
46             return new CompositeListener(Set.of(
47                 new Component<>(NodeConnectorRemoved.class, notification -> {
48                     LOG.debug("NodeConnectorRemoved Notification");
49                     LOG.debug("NodeConnectorRef {}", notification.getNodeConnectorRef());
50                     nodeConnectorRemoved.add(notification);
51                 }),
52                 new Component<>(NodeConnectorUpdated.class, notification -> {
53                     LOG.debug("NodeConnectorUpdated Notification");
54                     LOG.debug("NodeConnectorRef {}", notification.getNodeConnectorRef());
55                     nodeConnectorUpdated.add(notification);
56                 }),
57                 new Component<>(NodeRemoved.class, notification -> {
58                     LOG.debug("NodeRemoved Notification");
59                     LOG.debug("NodeRef {}", notification.getNodeRef());
60                     nodeRemoved.add(notification);
61                 }),
62                 new Component<>(NodeUpdated.class, notification -> {
63                     LOG.debug("NodeUpdated Notification");
64                     LOG.debug("NodeRef {}", notification.getNodeRef());
65                     nodeUpdated.add(notification);
66                 })));
67         }
68     }
69 }