import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.opendaylight.yangtools.concepts.AbstractRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
private final @NonNull DOMRpcService rpcService = new RpcServiceFacade();
@GuardedBy("this")
- private Collection<Registration<?>> listeners = Collections.emptyList();
+ private ImmutableList<RegImpl<?>> listeners = ImmutableList.of();
@GuardedBy("this")
- private Collection<ActionRegistration<?>> actionListeners = Collections.emptyList();
+ private ImmutableList<ActionRegistration<?>> actionListeners = ImmutableList.of();
private volatile DOMRpcRoutingTable routingTable = DOMRpcRoutingTable.EMPTY;
private volatile DOMActionRoutingTable actionRoutingTable = DOMActionRoutingTable.EMPTY;
- private ListenerRegistration<?> listenerRegistration;
+ private Registration listenerRegistration;
@Deprecated
@VisibleForTesting
return rpcProviderService;
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void removeRpcImplementation(final DOMRpcImplementation implementation,
final Set<DOMRpcIdentifier> rpcs) {
final DOMRpcRoutingTable oldTable = routingTable;
listenerNotifier.execute(() -> notifyRemoved(newTable, implementation));
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void removeRpcImplementations(final Map<DOMRpcIdentifier, DOMRpcImplementation> map) {
final DOMRpcRoutingTable oldTable = routingTable;
final DOMRpcRoutingTable newTable = (DOMRpcRoutingTable) oldTable.removeAll(map);
listenerNotifier.execute(() -> notifyRemoved(newTable, map.values()));
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void removeActionImplementation(final DOMActionImplementation implementation,
final Set<DOMActionInstance> actions) {
final DOMActionRoutingTable oldTable = actionRoutingTable;
listenerNotifier.execute(() -> notifyActionChanged(newTable, implementation));
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void removeListener(final ListenerRegistration<? extends DOMRpcAvailabilityListener> reg) {
listeners = ImmutableList.copyOf(Collections2.filter(listeners, input -> !reg.equals(input)));
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void removeActionListener(final ListenerRegistration<? extends AvailabilityListener> reg) {
actionListeners = ImmutableList.copyOf(Collections2.filter(actionListeners, input -> !reg.equals(input)));
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void notifyAdded(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
- for (Registration<?> l : listeners) {
+ for (RegImpl<?> l : listeners) {
l.addRpc(newTable, impl);
}
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void notifyAdded(final DOMRpcRoutingTable newTable,
final Collection<? extends DOMRpcImplementation> impls) {
- for (Registration<?> l : listeners) {
+ for (RegImpl<?> l : listeners) {
for (DOMRpcImplementation impl : impls) {
l.addRpc(newTable, impl);
}
}
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void notifyRemoved(final DOMRpcRoutingTable newTable, final DOMRpcImplementation impl) {
- for (Registration<?> l : listeners) {
+ for (RegImpl<?> l : listeners) {
l.removeRpc(newTable, impl);
}
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void notifyRemoved(final DOMRpcRoutingTable newTable,
final Collection<? extends DOMRpcImplementation> impls) {
- for (Registration<?> l : listeners) {
+ for (RegImpl<?> l : listeners) {
for (DOMRpcImplementation impl : impls) {
l.removeRpc(newTable, impl);
}
}
@VisibleForTesting
- synchronized Collection<?> listeners() {
+ synchronized List<?> listeners() {
return listeners;
}
+ @VisibleForTesting
+ synchronized List<?> actionListeners() {
+ return actionListeners;
+ }
+
@VisibleForTesting
DOMRpcRoutingTable routingTable() {
return routingTable;
}
- private static final class Registration<T extends DOMRpcAvailabilityListener>
- extends AbstractListenerRegistration<T> {
-
+ private static final class RegImpl<T extends DOMRpcAvailabilityListener> extends AbstractListenerRegistration<T> {
private Map<QName, Set<YangInstanceIdentifier>> prevRpcs;
private DOMRpcRouter router;
- Registration(final DOMRpcRouter router, final T listener, final Map<QName, Set<YangInstanceIdentifier>> rpcs) {
+ RegImpl(final DOMRpcRouter router, final T listener, final Map<QName, Set<YangInstanceIdentifier>> rpcs) {
super(listener);
this.router = requireNonNull(router);
this.prevRpcs = requireNonNull(rpcs);
}
void initialTable() {
- final Collection<DOMRpcIdentifier> added = new ArrayList<>();
+ final List<DOMRpcIdentifier> added = new ArrayList<>();
for (Entry<QName, Set<YangInstanceIdentifier>> e : prevRpcs.entrySet()) {
added.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
}
final Map<QName, Set<YangInstanceIdentifier>> rpcs = verifyNotNull(newTable.getOperations(l));
final MapDifference<QName, Set<YangInstanceIdentifier>> diff = Maps.difference(prevRpcs, rpcs);
- final Collection<DOMRpcIdentifier> added = new ArrayList<>();
+ final List<DOMRpcIdentifier> added = new ArrayList<>();
for (Entry<QName, Set<YangInstanceIdentifier>> e : diff.entriesOnlyOnRight().entrySet()) {
added.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
}
final Map<QName, Set<YangInstanceIdentifier>> rpcs = verifyNotNull(newTable.getOperations(l));
final MapDifference<QName, Set<YangInstanceIdentifier>> diff = Maps.difference(prevRpcs, rpcs);
- final Collection<DOMRpcIdentifier> removed = new ArrayList<>();
+ final List<DOMRpcIdentifier> removed = new ArrayList<>();
for (Entry<QName, Set<YangInstanceIdentifier>> e : diff.entriesOnlyOnLeft().entrySet()) {
removed.addAll(Collections2.transform(e.getValue(), i -> DOMRpcIdentifier.create(e.getKey(), i)));
}
}
void initialTable() {
- final Collection<DOMActionInstance> added = new ArrayList<>();
+ final List<DOMActionInstance> added = new ArrayList<>();
for (Entry<Absolute, Set<DOMDataTreeIdentifier>> e : prevActions.entrySet()) {
added.addAll(Collections2.transform(e.getValue(), i -> DOMActionInstance.of(e.getKey(), i)));
}
@Override
public <T extends DOMActionImplementation> ObjectRegistration<T> registerActionImplementation(
final T implementation, final Set<DOMActionInstance> instances) {
+ checkArgument(!instances.isEmpty(), "Instances must not be empty");
synchronized (DOMRpcRouter.this) {
final DOMActionRoutingTable oldTable = actionRoutingTable;
@Override
public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T listener) {
synchronized (DOMRpcRouter.this) {
- final Registration<T> ret = new Registration<>(DOMRpcRouter.this, listener,
- routingTable.getOperations(listener));
- listeners = ImmutableList.<Registration<?>>builder().addAll(listeners).add(ret).build();
+ final RegImpl<T> ret = new RegImpl<>(DOMRpcRouter.this, listener, routingTable.getOperations(listener));
+ listeners = ImmutableList.<RegImpl<?>>builder().addAll(listeners).add(ret).build();
listenerNotifier.execute(ret::initialTable);
return ret;
if (entry instanceof UnknownDOMRpcRoutingTableEntry) {
return Futures.immediateFailedFuture(
new DOMRpcImplementationNotAvailableException("%s is not resolved to an RPC", entry.getType()));
- } else if (entry instanceof RoutedDOMRpcRoutingTableEntry) {
- return invokeRoutedRpc((RoutedDOMRpcRoutingTableEntry) entry, input);
- } else if (entry instanceof GlobalDOMRpcRoutingTableEntry) {
- return invokeGlobalRpc((GlobalDOMRpcRoutingTableEntry) entry, input);
+ } else if (entry instanceof RoutedDOMRpcRoutingTableEntry routed) {
+ return invokeRoutedRpc(routed, input);
+ } else if (entry instanceof GlobalDOMRpcRoutingTableEntry global) {
+ return invokeGlobalRpc(global, input);
}
return Futures.immediateFailedFuture(
if (maybeKey.isPresent()) {
final NormalizedNode key = maybeKey.get();
final Object value = key.body();
- if (value instanceof YangInstanceIdentifier) {
- final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
-
+ if (value instanceof YangInstanceIdentifier iid) {
// Find a DOMRpcImplementation for a specific iid
final List<DOMRpcImplementation> specificImpls = entry.getImplementations(iid);
if (specificImpls != null) {