Migrate test-provider to CompositeListener
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestTopologyNotification.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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.util.Set;
12 import org.opendaylight.mdsal.binding.api.NotificationService;
13 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
14 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener.Component;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkOverutilized;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkUtilizationNormal;
19 import org.opendaylight.yangtools.yang.binding.Notification;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class OpenflowpluginTestTopologyNotification {
24     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestTopologyNotification.class);
25
26     private final NotificationService notificationService;
27
28     public OpenflowpluginTestTopologyNotification(final NotificationService notificationService) {
29         this.notificationService = notificationService;
30     }
31
32     public void init() {
33         // For switch events
34         notificationService.registerCompositeListener(new CompositeListener(Set.of(
35             new Component<>(LinkDiscovered.class, this::onNotification),
36             new Component<>(LinkOverutilized.class, this::onNotification),
37             new Component<>(LinkRemoved.class, this::onNotification),
38             new Component<>(LinkUtilizationNormal.class, this::onNotification))));
39     }
40
41     @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
42     private void onNotification(Notification<?> notification) {
43         LOG.debug("-------------------------------------------");
44         LOG.debug("{} notification ........", notification.getClass().getSimpleName());
45         LOG.debug("-------------------------------------------");
46     }
47 }