*/
package org.opendaylight.controller.cluster.datastore;
-import com.google.common.base.Optional;
import java.util.EventListener;
-import java.util.Map.Entry;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
-abstract class DelayedListenerRegistration<L extends EventListener, R> implements ListenerRegistration<L> {
- private final R registrationMessage;
+abstract class DelayedListenerRegistration<L extends EventListener, M> implements ListenerRegistration<L> {
+ private final M registrationMessage;
private volatile ListenerRegistration<L> delegate;
@GuardedBy("this")
private boolean closed;
- protected DelayedListenerRegistration(R registrationMessage) {
+ protected DelayedListenerRegistration(M registrationMessage) {
this.registrationMessage = registrationMessage;
}
- R getRegistrationMessage() {
+ M getRegistrationMessage() {
return registrationMessage;
}
return delegate;
}
- synchronized <LR extends ListenerRegistration<L>> void createDelegate(
- final LeaderLocalDelegateFactory<R, LR, Optional<DataTreeCandidate>> factory) {
+ synchronized <R extends ListenerRegistration<L>> void createDelegate(
+ final LeaderLocalDelegateFactory<M, R> factory) {
if (!closed) {
- final Entry<LR, Optional<DataTreeCandidate>> res = factory.createDelegate(registrationMessage);
- this.delegate = res.getKey();
+ this.delegate = factory.createDelegate(registrationMessage);
}
}
@Override
public L getInstance() {
- final ListenerRegistration<L> d = delegate;
- return d == null ? null : (L)d.getInstance();
+ // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet.
+ // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway
+ // but, since we have to provide an implementation to satisfy the interface, we throw
+ // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error
+ // for possibly returning null.
+ throw new UnsupportedOperationException(
+ "getInstance should not be called on this instance since it could be null");
}
@Override