Clean up DOMNotificationRouterEvent
[mdsal.git] / dom / mdsal-dom-broker / src / main / java / org / opendaylight / mdsal / dom / broker / DOMNotificationRouterEvent.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.mdsal.dom.broker;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.dom.api.DOMNotification;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
17 import org.opendaylight.yangtools.yang.common.Empty;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * A single notification event in the notification router.
23  */
24 final class DOMNotificationRouterEvent {
25     private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
26
27     private final SettableFuture<Empty> future = SettableFuture.create();
28     private final @NonNull DOMNotification notification;
29
30     DOMNotificationRouterEvent(final DOMNotification notification) {
31         this.notification = requireNonNull(notification);
32     }
33
34     ListenableFuture<Empty> future() {
35         return future;
36     }
37
38     @SuppressWarnings("checkstyle:illegalCatch")
39     void deliverTo(final DOMNotificationListener listener) {
40         try {
41             listener.onNotification(notification);
42         } catch (Exception e) {
43             LOG.warn("Listener {} failed during notification delivery", listener, e);
44         } finally {
45             clear();
46         }
47     }
48
49     void clear() {
50         future.set(Empty.value());
51     }
52 }