Specialize CommitCoordinationTask
[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.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * A single notification event in the notification router.
22  */
23 final class DOMNotificationRouterEvent {
24     private static final Logger LOG = LoggerFactory.getLogger(DOMNotificationRouterEvent.class);
25
26     private final SettableFuture<Void> future = SettableFuture.create();
27     private final @NonNull DOMNotification notification;
28
29     DOMNotificationRouterEvent(final DOMNotification notification) {
30         this.notification = requireNonNull(notification);
31     }
32
33     ListenableFuture<Void> future() {
34         return future;
35     }
36
37     @SuppressWarnings("checkstyle:illegalCatch")
38     void deliverTo(DOMNotificationListener listener) {
39         try {
40             listener.onNotification(notification);
41         } catch (Exception e) {
42             LOG.warn("Listener {} failed during notification delivery", listener, e);
43         } finally {
44             clear();
45         }
46     }
47
48     void clear() {
49         future.set(null);
50     }
51 }