import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListenableFuture;
+import java.time.Instant;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory;
import org.opendaylight.mdsal.dom.api.DOMNotification;
import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
import org.opendaylight.mdsal.dom.api.DOMService;
+import org.opendaylight.yangtools.yang.binding.EventInstantAware;
import org.opendaylight.yangtools.yang.binding.Notification;
-public class BindingDOMNotificationPublishServiceAdapter implements NotificationPublishService, AutoCloseable {
+public class BindingDOMNotificationPublishServiceAdapter extends AbstractBindingAdapter<DOMNotificationPublishService>
+ implements NotificationPublishService {
static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
- private final BindingToNormalizedNodeCodec codecRegistry;
- private final DOMNotificationPublishService domPublishService;
+ public BindingDOMNotificationPublishServiceAdapter(final DOMNotificationPublishService domPublishService,
+ final BindingToNormalizedNodeCodec codec) {
+ super(codec, domPublishService);
+ }
+ @Deprecated
public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
final DOMNotificationPublishService domPublishService) {
- this.codecRegistry = codec;
- this.domPublishService = domPublishService;
+ this(domPublishService, codec);
}
public BindingToNormalizedNodeCodec getCodecRegistry() {
- return codecRegistry;
+ return getCodec();
}
public DOMNotificationPublishService getDomPublishService() {
- return domPublishService;
+ return getDelegate();
}
@Override
public void putNotification(final Notification notification) throws InterruptedException {
- domPublishService.putNotification(toDomNotification(notification));
+ getDelegate().putNotification(toDomNotification(notification));
}
@Override
public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
- ListenableFuture<?> offerResult = domPublishService.offerNotification(toDomNotification(notification));
+ ListenableFuture<?> offerResult = getDelegate().offerNotification(toDomNotification(notification));
return DOMNotificationPublishService.REJECTED.equals(offerResult)
? NotificationPublishService.REJECTED
: offerResult;
@Override
public ListenableFuture<? extends Object> offerNotification(final Notification notification,
final int timeout, final TimeUnit unit) throws InterruptedException {
- ListenableFuture<?> offerResult = domPublishService.offerNotification(
- toDomNotification(notification), timeout, unit);
+ ListenableFuture<?> offerResult = getDelegate().offerNotification(toDomNotification(notification), timeout,
+ unit);
return DOMNotificationPublishService.REJECTED.equals(offerResult)
? NotificationPublishService.REJECTED
: offerResult;
}
- private DOMNotification toDomNotification(final Notification notification) {
- return LazySerializedDOMNotification.create(codecRegistry, notification);
- }
-
- @Override
- public void close() throws Exception {
-
+ private @NonNull DOMNotification toDomNotification(final Notification notification) {
+ final Instant instant = notification instanceof EventInstantAware
+ ? ((EventInstantAware) notification).eventInstant() : Instant.now();
+ return LazySerializedDOMNotification.create(getCodec(), notification, instant);
}
protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
-
@Override
public Set<Class<? extends DOMService>> getRequiredDelegates() {
return ImmutableSet.of(DOMNotificationPublishService.class);
final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
}
-
}
}