2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.tutorial.notif;
19 import io.fd.honeycomb.notification.ManagedNotificationProducer;
20 import io.fd.honeycomb.notification.NotificationCollector;
21 import java.util.Collection;
22 import java.util.Collections;
23 import javax.annotation.Nonnull;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SampleNotification;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.sample.plugin.rev160918.SampleNotificationBuilder;
26 import org.opendaylight.yangtools.yang.binding.Notification;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Notification producer for sample plugin
33 public class SampleNotificationProducer implements ManagedNotificationProducer {
35 private static final Logger LOG = LoggerFactory.getLogger(SampleNotificationProducer.class);
37 private Thread thread;
40 public void start(@Nonnull final NotificationCollector collector) {
41 LOG.info("Starting notification stream for interfaces");
43 // Simulating notification producer
44 thread = new Thread(() -> {
46 if (Thread.currentThread().isInterrupted()) {
52 } catch (InterruptedException e) {
53 Thread.currentThread().interrupt();
57 final SampleNotification notification = new SampleNotificationBuilder()
58 .setContent("Hello world " + System.currentTimeMillis())
60 LOG.info("Emitting notification: {}", notification);
61 collector.onNotification(notification);
63 }, "NotificationProducer");
64 thread.setDaemon(true);
77 public Collection<Class<? extends Notification>> getNotificationTypes() {
78 // Producing only this single type of notification
79 return Collections.singleton(SampleNotification.class);
83 public void close() throws Exception {