*/
package org.opendaylight.mdsal.binding.dom.adapter;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListenableFuture;
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.DOMService;
import org.opendaylight.yangtools.yang.binding.Notification;
-public class BindingDOMNotificationPublishServiceAdapter extends AbstractBindingAdapter<DOMNotificationPublishService>
- implements NotificationPublishService {
-
+@VisibleForTesting
+public final class BindingDOMNotificationPublishServiceAdapter
+ extends AbstractBindingAdapter<DOMNotificationPublishService> implements NotificationPublishService {
static final Factory<NotificationPublishService> BUILDER_FACTORY = Builder::new;
- public BindingDOMNotificationPublishServiceAdapter(final DOMNotificationPublishService domPublishService,
- final BindingToNormalizedNodeCodec codec) {
- super(codec, domPublishService);
- }
-
- @Deprecated
- public BindingDOMNotificationPublishServiceAdapter(final BindingToNormalizedNodeCodec codec,
+ public BindingDOMNotificationPublishServiceAdapter(final AdapterContext adapterContext,
final DOMNotificationPublishService domPublishService) {
- this(domPublishService, codec);
- }
-
- public BindingToNormalizedNodeCodec getCodecRegistry() {
- return getCodec();
- }
-
- public DOMNotificationPublishService getDomPublishService() {
- return getDelegate();
+ super(adapterContext, domPublishService);
}
@Override
- public void putNotification(final Notification notification) throws InterruptedException {
+ public void putNotification(final Notification<?> notification) throws InterruptedException {
getDelegate().putNotification(toDomNotification(notification));
}
@Override
- public ListenableFuture<? extends Object> offerNotification(final Notification notification) {
- ListenableFuture<?> offerResult = getDelegate().offerNotification(toDomNotification(notification));
- return DOMNotificationPublishService.REJECTED.equals(offerResult)
- ? NotificationPublishService.REJECTED
- : offerResult;
+ public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification) {
+ return toBindingResult(getDelegate().offerNotification(toDomNotification(notification)));
}
@Override
- public ListenableFuture<? extends Object> offerNotification(final Notification notification,
- final int timeout, final TimeUnit unit) throws InterruptedException {
- ListenableFuture<?> offerResult = getDelegate().offerNotification(toDomNotification(notification), timeout,
- unit);
- return DOMNotificationPublishService.REJECTED.equals(offerResult)
- ? NotificationPublishService.REJECTED
- : offerResult;
+ public ListenableFuture<? extends Object> offerNotification(final Notification<?> notification, final int timeout,
+ final TimeUnit unit) throws InterruptedException {
+ return toBindingResult(getDelegate().offerNotification(toDomNotification(notification), timeout, unit));
}
- private DOMNotification toDomNotification(final Notification notification) {
- return LazySerializedDOMNotification.create(getCodec(), notification);
+ private @NonNull DOMNotification toDomNotification(final Notification<?> notification) {
+ return new LazySerializedNotification(currentSerializer(), notification);
}
- protected static class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
+ private static @NonNull ListenableFuture<? extends Object> toBindingResult(
+ final @NonNull ListenableFuture<? extends Object> domResult) {
+ return DOMNotificationPublishService.REJECTED.equals(domResult) ? NotificationPublishService.REJECTED
+ : domResult;
+ }
+
+ private static final class Builder extends BindingDOMAdapterBuilder<NotificationPublishService> {
+ Builder(final AdapterContext adapterContext) {
+ super(adapterContext);
+ }
@Override
public Set<Class<? extends DOMService>> getRequiredDelegates() {
}
@Override
- protected NotificationPublishService createInstance(final BindingToNormalizedNodeCodec codec,
- final ClassToInstanceMap<DOMService> delegates) {
- final DOMNotificationPublishService domPublish = delegates.getInstance(DOMNotificationPublishService.class);
- return new BindingDOMNotificationPublishServiceAdapter(codec, domPublish);
+ protected NotificationPublishService createInstance(final ClassToInstanceMap<DOMService> delegates) {
+ return new BindingDOMNotificationPublishServiceAdapter(adapterContext(),
+ delegates.getInstance(DOMNotificationPublishService.class));
}
-
}
}