* @throws InterruptedException if interrupted while waiting
* @throws NullPointerException if the notification is null
*/
- void putNotification(@NonNull Notification notification) throws InterruptedException;
+ void putNotification(@NonNull Notification<?> notification) throws InterruptedException;
/**
* Publishes a notification to subscribed listeners. This initiates the process of sending the
* resource constraints prevent
* @throws NullPointerException if the notification is null
*/
- @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification notification);
+ @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification<?> notification);
/**
* Publishes a notification to subscribed listeners. This initiates the process of sending the
* @throws NullPointerException if the notification or unit is null
* @throws IllegalArgumentException if timeout is negative.
*/
- @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification notification,
+ @NonNull ListenableFuture<? extends Object> offerNotification(@NonNull Notification<?> notification,
int timeout, @NonNull TimeUnit unit) throws InterruptedException;
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
* @return a {@link Registration} instance that should be used to unregister the listener by invoking the
* {@link Registration#close()} method when no longer needed
*/
- <N extends Notification> @NonNull Registration registerListener(Class<N> type, Listener<N> listener,
+ <N extends Notification<N> & DataObject> @NonNull Registration registerListener(Class<N> type, Listener<N> listener,
Executor executor);
/**
* @return a {@link Registration} instance that should be used to unregister the listener by invoking the
* {@link Registration#close()} method when no longer needed
*/
- default <N extends Notification> @NonNull Registration registerListener(final Class<N> type,
+ default <N extends Notification<N> & DataObject> @NonNull Registration registerListener(final Class<N> type,
final Listener<N> listener) {
return registerListener(type, listener, MoreExecutors.directExecutor());
}
* @param N Notification type
*/
@FunctionalInterface
- interface Listener<N extends Notification> extends EventListener {
+ interface Listener<N extends Notification<N> & DataObject> extends EventListener {
/**
* Process a global notification.
*
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
}
@Override
- public <N extends Notification> Registration registerListener(final Class<N> type, final Listener<N> listener,
- final Executor executor) {
+ public <N extends Notification<N> & DataObject> Registration registerListener(final Class<N> type,
+ final Listener<N> listener, final Executor executor) {
final var domListener = new SingleBindingDOMNotificationAdapter<>(adapterContext, type, listener, executor);
return domNotifService.registerNotificationListener(domListener, domListener.getSupportedNotifications());
}
import java.util.concurrent.Executor;
import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-final class SingleBindingDOMNotificationAdapter<N extends Notification> extends AbstractDOMNotificationListenerAdapter {
+final class SingleBindingDOMNotificationAdapter<N extends Notification<N> & DataObject>
+ extends AbstractDOMNotificationListenerAdapter {
private final Listener<N> delegate;
private final Executor executor;
private final Class<N> type;
import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.osgi.service.component.annotations.Activate;
}
@Override
- public <N extends Notification> Registration registerListener(final Class<N> type, final Listener<N> listener,
- final Executor executor) {
+ public <N extends Notification<N> & DataObject> Registration registerListener(final Class<N> type,
+ final Listener<N> listener, final Executor executor) {
return delegate().registerListener(type, listener, executor);
}
* @param data NormalizedNode representing data
* @return Binding representation of Notification
*/
- @Nullable Notification fromNormalizedNodeNotification(@NonNull Absolute path, @NonNull ContainerNode data);
+ @Nullable Notification<?> fromNormalizedNodeNotification(@NonNull Absolute path, @NonNull ContainerNode data);
/**
* Translates supplied NormalizedNode Notification into Binding data, optionally taking an instant
* @return Binding representation of Notification
*/
@Beta
- @Nullable Notification fromNormalizedNodeNotification(@NonNull Absolute path, @NonNull ContainerNode data,
+ @Nullable Notification<?> fromNormalizedNodeNotification(@NonNull Absolute path, @NonNull ContainerNode data,
@Nullable Instant eventInstant);
/**
* @param data NormalizedNode representing notification data
* @return NormalizedNode representation of notification
*/
- @NonNull ContainerNode toNormalizedNodeNotification(@NonNull Notification data);
+ @NonNull ContainerNode toNormalizedNodeNotification(@NonNull Notification<?> data);
/**
* Translates supplied Binding RPC input or output into NormalizedNode data.
* @return {@link BindingStreamEventWriter} which will write to supplied
* {@link NormalizedNodeStreamWriter}.
*/
- @NonNull BindingStreamEventWriter newNotificationWriter(@NonNull Class<? extends Notification> notification,
+ @NonNull BindingStreamEventWriter newNotificationWriter(@NonNull Class<? extends Notification<?>> notification,
@NonNull NormalizedNodeStreamWriter domWriter);
/**
}
@Override
- public ContainerNode toNormalizedNodeNotification(final Notification data) {
+ public ContainerNode toNormalizedNodeNotification(final Notification<?> data) {
return delegate().toNormalizedNodeNotification(data);
}
}
@Override
- public Notification fromNormalizedNodeNotification(final Absolute path, final ContainerNode data) {
+ public Notification<?> fromNormalizedNodeNotification(final Absolute path, final ContainerNode data) {
return delegate().fromNormalizedNodeNotification(path, data);
}
@Override
- public Notification fromNormalizedNodeNotification(final Absolute path, final ContainerNode data,
+ public Notification<?> fromNormalizedNodeNotification(final Absolute path, final ContainerNode data,
final Instant eventInstant) {
return delegate().fromNormalizedNodeNotification(path, data, eventInstant);
}
}
@Override
- public BindingStreamEventWriter newNotificationWriter(final Class<? extends Notification> notification,
+ public BindingStreamEventWriter newNotificationWriter(final Class<? extends Notification<?>> notification,
final NormalizedNodeStreamWriter streamWriter) {
return delegate().newNotificationWriter(notification, streamWriter);
}
}
@Override
- public BindingStreamEventWriter newNotificationWriter(final Class<? extends Notification> notification,
+ public BindingStreamEventWriter newNotificationWriter(final Class<? extends Notification<?>> notification,
final NormalizedNodeStreamWriter domWriter) {
return root.getNotification(notification).createWriter(domWriter);
}
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
- public ContainerNode toNormalizedNodeNotification(@NonNull final Notification data) {
+ public ContainerNode toNormalizedNodeNotification(@NonNull final Notification<?> data) {
// FIXME: Should the cast to DataObject be necessary?
return serializeDataObject((DataObject) data,
- (ctx, iface, domWriter) -> ctx.newNotificationWriter(iface.asSubclass(Notification.class), domWriter));
+ (ctx, iface, domWriter) -> ctx.newNotificationWriter(
+ (Class<? extends Notification<?>>) iface.asSubclass(Notification.class), domWriter));
}
@Override
private Type notificationType(final GeneratedTypeBuilder builder, final TypeBuilderFactory builderFactory) {
final AbstractCompositeGenerator<?> parent = getParent();
if (parent instanceof ModuleGenerator) {
- return BindingTypes.NOTIFICATION;
+ return BindingTypes.notification(builder);
}
final Type parentType = Type.of(parent.typeName());
public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
- public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);
public static final ConcreteType QNAME = typeForClass(QName.class);
public static final ConcreteType RPC_INPUT = typeForClass(RpcInput.class);
private static final ConcreteType INSTANCE_NOTIFICATION = typeForClass(InstanceNotification.class);
private static final ConcreteType KEYED_LIST_ACTION = typeForClass(KeyedListAction.class);
private static final ConcreteType KEYED_LIST_NOTIFICATION = typeForClass(KeyedListNotification.class);
+ private static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
private static final ConcreteType OPAQUE_OBJECT = typeForClass(OpaqueObject.class);
private static final ConcreteType RPC_RESULT = typeForClass(RpcResult.class);
return parameterizedTypeFor(KEYED_LIST_ACTION, keyType, parent, input, output);
}
+ /**
+ * Type specializing {@link Notification} for a particular type.
+ *
+ * @param concreteType The concrete type of this notification
+ * @return A parameterized type corresponding to {@code Notification<ConcreteType>}
+ * @throws NullPointerException if any argument is is null
+ */
+ public static ParameterizedType notification(final Type concreteType) {
+ return parameterizedTypeFor(NOTIFICATION, concreteType);
+ }
+
/**
* Type specializing {@link InstanceNotification} for a particular type.
*
+ * @param concreteType The concrete type of this notification
* @param parent Type of parent defining the notification
- * @return A parameterized type corresponding to {@code InstanceNotification<Parent>}
+ * @return A parameterized type corresponding to {@code InstanceNotification<ConcreteType, Parent>}
* @throws NullPointerException if {@code parent} is is null
*/
public static ParameterizedType instanceNotification(final Type concreteType, final Type parent) {
/**
* Type specializing {@link InstanceNotification} for a particular type.
*
+ * @param concreteType The concrete type of this notification
* @param parent Type of parent defining the notification
* @param keyType Type of parent's key
- * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ParentKey, Parent>}
+ * @return A parameterized type corresponding to {@code KeyedInstanceNotification<ConcreteType, ParentKey, Parent>}
* @throws NullPointerException if any argument is is null
*/
public static ParameterizedType keyedListNotification(final Type concreteType, final Type parent,
*/
package org.opendaylight.mdsal.binding.model.ri;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
assertEquals("IDENTIFIABLE", typeForClass(Identifiable.class), BindingTypes.IDENTIFIABLE);
assertEquals("IDENTIFIER", typeForClass(Identifier.class), BindingTypes.IDENTIFIER);
assertEquals("INSTANCE_IDENTIFIER", typeForClass(InstanceIdentifier.class), BindingTypes.INSTANCE_IDENTIFIER);
- assertEquals("NOTIFICATION", typeForClass(Notification.class), BindingTypes.NOTIFICATION);
assertEquals("NOTIFICATION_LISTENER", typeForClass(NotificationListener.class),
BindingTypes.NOTIFICATION_LISTENER);
assertEquals("RPC_SERVICE", typeForClass(RpcService.class), BindingTypes.RPC_SERVICE);
final ParameterizedType augmentationType = BindingTypes.augmentation(Types.objectType());
assertEquals("Augmentation", augmentationType.getName());
}
+
+ @Test
+ public void testNotificationNull() {
+ assertThrows(NullPointerException.class, () -> BindingTypes.notification(null));
+ }
+
+ @Test
+ public void testNotification() {
+ final ParameterizedType notificationType = BindingTypes.notification(Types.objectType());
+ assertEquals(Types.typeForClass(Notification.class), notificationType.getRawType());
+ assertArrayEquals(new Object[] { Types.objectType() }, notificationType.getActualTypeArguments());
+ }
}
\ No newline at end of file
* interface. In case they do, {@link EventInstantAware#eventInstant()} returns the time when this notification was
* generated.
*/
-// FIXME: 6.0.0: narrow implementedInterface()
-public interface Notification extends BaseNotification {
-
+public interface Notification<T extends Notification<T> & DataObject> extends BaseNotification {
+ @Override
+ Class<T> implementedInterface();
}