import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMRpcImplementationRegistration;
+import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
private Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> listeners = Collections.emptyList();
private volatile DOMRpcRoutingTable routingTable = DOMRpcRoutingTable.EMPTY;
+ public static DOMRpcRouter newInstance(SchemaService schemaService) {
+ final DOMRpcRouter rpcRouter = new DOMRpcRouter();
+ schemaService.registerSchemaContextListener(rpcRouter);
+ return rpcRouter;
+ }
+
@Override
public <T extends DOMRpcImplementation> DOMRpcImplementationRegistration<T> registerRpcImplementation(final T implementation, final DOMRpcIdentifier... rpcs) {
return registerRpcImplementation(implementation, ImmutableSet.copyOf(rpcs));
final DOMRpcRoutingTable newTable = oldTable.remove(implementation, rpcs);
final Collection<DOMRpcIdentifier> removedRpcs = notPresentRpcs(newTable, rpcs);
- final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
routingTable = newTable;
-
- listenerNotifier.execute(new Runnable() {
- @Override
- public void run() {
- for (ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
- // Need to ensure removed listeners do not get notified
- synchronized (DOMRpcRouter.this) {
- if (listeners.contains(l)) {
- l.getInstance().onRpcUnavailable(removedRpcs);
+ if(!removedRpcs.isEmpty()) {
+ final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
+ listenerNotifier.execute(new Runnable() {
+ @Override
+ public void run() {
+ for (final ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
+ // Need to ensure removed listeners do not get notified
+ synchronized (DOMRpcRouter.this) {
+ if (listeners.contains(l)) {
+ l.getInstance().onRpcUnavailable(removedRpcs);
+ }
}
}
}
- }
- });
+ });
+ }
}
@Override
final DOMRpcRoutingTable newTable = oldTable.add(implementation, rpcs);
final Collection<DOMRpcIdentifier> addedRpcs = notPresentRpcs(oldTable, rpcs);
- final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
routingTable = newTable;
- listenerNotifier.execute(new Runnable() {
- @Override
- public void run() {
- for (ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
- // Need to ensure removed listeners do not get notified
- synchronized (DOMRpcRouter.this) {
- if (listeners.contains(l)) {
- l.getInstance().onRpcAvailable(addedRpcs);
+ if(!addedRpcs.isEmpty()) {
+ final Collection<ListenerRegistration<? extends DOMRpcAvailabilityListener>> capturedListeners = listeners;
+ listenerNotifier.execute(new Runnable() {
+ @Override
+ public void run() {
+ for (final ListenerRegistration<? extends DOMRpcAvailabilityListener> l : capturedListeners) {
+ // Need to ensure removed listeners do not get notified
+ synchronized (DOMRpcRouter.this) {
+ if (listeners.contains(l)) {
+ l.getInstance().onRpcAvailable(addedRpcs);
+ }
}
}
}
- }
- });
+ });
+ }
return new AbstractDOMRpcImplementationRegistration<T>(implementation) {
@Override