Use ByteBuf.readRetainedSlice()
[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 javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.mdsal.binding.api.NotificationService;
16 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkOverutilized;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkUtilizationNormal;
21 import org.opendaylight.yangtools.concepts.Registration;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23 import org.osgi.service.component.annotations.Activate;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.Deactivate;
26 import org.osgi.service.component.annotations.Reference;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 @Singleton
31 @Component(service = { })
32 public final class OpenflowpluginTestTopologyNotification implements AutoCloseable {
33     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestTopologyNotification.class);
34
35     private final Registration reg;
36
37     @Activate
38     @Inject
39     public OpenflowpluginTestTopologyNotification(@Reference final NotificationService notificationService) {
40         // For switch events
41         reg = notificationService.registerCompositeListener(new CompositeListener(Set.of(
42             new CompositeListener.Component<>(LinkDiscovered.class,
43                 OpenflowpluginTestTopologyNotification::onNotification),
44             new CompositeListener.Component<>(LinkOverutilized.class,
45                 OpenflowpluginTestTopologyNotification::onNotification),
46             new CompositeListener.Component<>(LinkRemoved.class,
47                 OpenflowpluginTestTopologyNotification::onNotification),
48             new CompositeListener.Component<>(LinkUtilizationNormal.class,
49                 OpenflowpluginTestTopologyNotification::onNotification))));
50     }
51
52     @Override
53     @PreDestroy
54     @Deactivate
55     public void close() {
56         reg.close();
57     }
58
59     @SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
60     private static void onNotification(final Notification<?> notification) {
61         LOG.debug("-------------------------------------------");
62         LOG.debug("{} notification ........", notification.getClass().getSimpleName());
63         LOG.debug("-------------------------------------------");
64     }
65 }