Use ByteBuf.readRetainedSlice()
[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 javax.annotation.PreDestroy;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.mdsal.binding.api.NotificationService;
17 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
18 //import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener.Component;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
23 import org.opendaylight.yangtools.concepts.Registration;
24 import org.osgi.service.component.annotations.Activate;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Deactivate;
27 import org.osgi.service.component.annotations.Reference;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 @Singleton
32 @Component(service = { })
33 public final class OpenflowpluginTestNodeConnectorNotification implements AutoCloseable {
34     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestNodeConnectorNotification.class);
35
36     private final PortEventListener portEventListener = new PortEventListener();
37     private final Registration reg;
38
39     @Inject
40     @Activate
41     public OpenflowpluginTestNodeConnectorNotification(@Reference final NotificationService notificationService) {
42         // For switch events
43         reg = notificationService.registerCompositeListener(portEventListener.toListener());
44     }
45
46     @PreDestroy
47     @Deactivate
48     @Override
49     public void close() {
50         reg.close();
51     }
52
53     private static final class PortEventListener {
54         List<NodeUpdated> nodeUpdated = new ArrayList<>();
55         List<NodeRemoved> nodeRemoved = new ArrayList<>();
56         List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
57         List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
58
59         CompositeListener toListener() {
60             return new CompositeListener(Set.of(
61                 new CompositeListener.Component<>(NodeConnectorRemoved.class, notification -> {
62                     LOG.debug("NodeConnectorRemoved Notification");
63                     LOG.debug("NodeConnectorRef {}", notification.getNodeConnectorRef());
64                     nodeConnectorRemoved.add(notification);
65                 }),
66                 new CompositeListener.Component<>(NodeConnectorUpdated.class, notification -> {
67                     LOG.debug("NodeConnectorUpdated Notification");
68                     LOG.debug("NodeConnectorRef {}", notification.getNodeConnectorRef());
69                     nodeConnectorUpdated.add(notification);
70                 }),
71                 new CompositeListener.Component<>(NodeRemoved.class, notification -> {
72                     LOG.debug("NodeRemoved Notification");
73                     LOG.debug("NodeRef {}", notification.getNodeRef());
74                     nodeRemoved.add(notification);
75                 }),
76                 new CompositeListener.Component<>(NodeUpdated.class, notification -> {
77                     LOG.debug("NodeUpdated Notification");
78                     LOG.debug("NodeRef {}", notification.getNodeRef());
79                     nodeUpdated.add(notification);
80                 })));
81         }
82     }
83 }