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.
16 package io.fd.honeycomb.v3po.notification.impl;
18 import io.fd.honeycomb.v3po.notification.NotificationCollector;
19 import java.util.Collection;
20 import javax.annotation.Nonnull;
21 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Notification collector based on MD-SAL's {@link NotificationPublishService}.
29 public final class HoneycombNotificationCollector implements NotificationCollector, AutoCloseable {
31 private static final Logger LOG = LoggerFactory.getLogger(HoneycombNotificationCollector.class);
33 private final NotificationPublishService bindingDOMNotificationPublishServiceAdapter;
34 private final NotificationProducerRegistry notificationProducerRegistry;
36 public HoneycombNotificationCollector(
37 @Nonnull final NotificationPublishService bindingDOMNotificationPublishServiceAdapter,
38 @Nonnull final NotificationProducerRegistry notificationProducerRegistry) {
39 this.bindingDOMNotificationPublishServiceAdapter = bindingDOMNotificationPublishServiceAdapter;
40 this.notificationProducerRegistry = notificationProducerRegistry;
44 public void close() throws Exception {
49 public void onNotification(@Nonnull final Notification notification) {
50 LOG.debug("Notification: {} pushed into collector", notification.getClass().getSimpleName());
51 LOG.trace("Notification: {} pushed into collector", notification);
53 bindingDOMNotificationPublishServiceAdapter.putNotification(notification);
54 } catch (InterruptedException e) {
55 LOG.warn("Interrupted", e);
56 Thread.currentThread().interrupt();
57 throw new RuntimeException(e);
63 public Collection<Class<? extends Notification>> getNotificationTypes() {
64 return notificationProducerRegistry.getNotificationTypes();