2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.dom.adapter;
10 import static java.util.Objects.requireNonNull;
12 import java.time.Instant;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
15 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
16 import org.opendaylight.mdsal.dom.api.DOMEvent;
17 import org.opendaylight.mdsal.dom.api.DOMNotification;
18 import org.opendaylight.yangtools.yang.binding.Notification;
19 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 * Lazy serialized implementation of DOM Notification.
26 * This implementation performs serialization of data, only if receiver of notification actually accessed data from
29 public final class LazySerializedDOMNotification implements DOMNotification, DOMEvent {
30 private final @NonNull BindingNormalizedNodeSerializer codec;
31 private final @NonNull Notification data;
32 private final @NonNull SchemaPath type;
33 private final @NonNull Instant eventInstant;
35 private volatile ContainerNode domBody;
37 LazySerializedDOMNotification(final BindingNormalizedNodeSerializer codec, final Notification data,
38 final SchemaPath type, final Instant eventInstant) {
39 this.codec = requireNonNull(codec);
40 this.data = requireNonNull(data);
41 this.type = requireNonNull(type);
42 this.eventInstant = requireNonNull(eventInstant);
45 static @NonNull DOMNotification create(final BindingNormalizedNodeSerializer codec, final Notification data,
46 final Instant eventInstant) {
47 // TODO: for nested (YANG 1.1) notifications we will need the SchemaPath where the notification is being invoked
48 // and use that instead of ROOT. How Binding users will refer to it is TBD (but probably
49 // InstanceIdentifier, which means we will need to do some lifting to find the SchemaPath)
50 final SchemaPath type = SchemaPath.ROOT.createChild(BindingReflections.findQName(data.implementedInterface()));
51 return new LazySerializedDOMNotification(codec, data, type, eventInstant);
55 public SchemaPath getType() {
60 public ContainerNode getBody() {
61 ContainerNode local = domBody;
63 domBody = local = codec.toNormalizedNodeNotification(data);
69 public Instant getEventInstant() {
73 public @NonNull Notification getBindingData() {