/**
* Class representing a {@link Registration} of an {@link EventListener}. This interface provides the additional
* guarantee that the process of unregistration cannot fail for predictable reasons.
+ *
+ * @param <T> Type of registered listener
*/
public interface ListenerRegistration<T extends EventListener> extends ObjectRegistration<T> {
/**
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.concepts;
+
+import com.google.common.annotations.Beta;
+import java.util.EventListener;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Implementation of {@link ListenerRegistration} which does nothing in its {@link #close()} method.
+ *
+ * @param <T> Type of registered listener
+ */
+@Beta
+@NonNullByDefault
+public final class NoOpListenerRegistration<T extends EventListener> extends NoOpObjectRegistration<T>
+ implements ListenerRegistration<T> {
+ private NoOpListenerRegistration(final T instance) {
+ super(instance);
+ }
+
+ public static <T extends EventListener> ListenerRegistration<T> of(final T instance) {
+ return new NoOpListenerRegistration<>(instance);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.concepts;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Implementation of {@link ObjectRegistration} which does nothing in its {@link #close()} method.
+ *
+ * @param <T> Type of registered object
+ */
+@Beta
+@NonNullByDefault
+public class NoOpObjectRegistration<T> implements Immutable, ObjectRegistration<T> {
+ private final T instance;
+
+ NoOpObjectRegistration(final T instance) {
+ this.instance = requireNonNull(instance);
+ }
+
+ public static <T> ObjectRegistration<T> of(final T instance) {
+ return new NoOpObjectRegistration<>(instance);
+ }
+
+ @Override
+ public final T getInstance() {
+ return instance;
+ }
+
+ @Override
+ public final void close() {
+ // No-op
+ }
+
+ @Override
+ public final String toString() {
+ return MoreObjects.toStringHelper(this).add("instance", instance).toString();
+ }
+}
* Class representing a registration of an object. Such a registration is a proper resource and should be cleaned up
* when no longer required, so references to the object can be removed. This mechanism lies above the usual Java
* reference mechanism, as the entity where the object is registered may reside outside of the Java Virtual Machine.
+ *
+ * @param <T> Type of registered object
*/
public interface ObjectRegistration<T> extends Registration {
/**
* @return Registered object.
*/
@Nonnull T getInstance();
-
- @Override
- void close();
}