Search in sources :

Example 1 with DOMActionImplementation

use of org.opendaylight.mdsal.dom.api.DOMActionImplementation in project controller by opendaylight.

the class OpsRegistrar method updateRemoteActionEndpoints.

/**
 * Updates the action endpoints, Adding new registrations first before removing previous registrations.
 */
private void updateRemoteActionEndpoints(final Map<Address, Optional<RemoteActionEndpoint>> actionEndpoints) {
    /*
         * Updating Action providers is a two-step process. We first add the newly-discovered RPCs and then close
         * the old registration. This minimizes churn observed by listeners, as they will not observe RPC
         * unavailability which would occur if we were to do it the other way around.
         *
         * Note that when an Action moves from one remote node to another, we also do not want to expose the gap,
         * hence we register all new implementations before closing all registrations.
         */
    final Collection<ObjectRegistration<?>> prevRegs = new ArrayList<>(actionEndpoints.size());
    for (Entry<Address, Optional<RemoteActionEndpoint>> e : actionEndpoints.entrySet()) {
        LOG.debug("Updating action registrations for {}", e.getKey());
        final ObjectRegistration<DOMActionImplementation> prevReg;
        final Optional<RemoteActionEndpoint> maybeEndpoint = e.getValue();
        if (maybeEndpoint.isPresent()) {
            final RemoteActionEndpoint endpoint = maybeEndpoint.get();
            final RemoteActionImplementation impl = new RemoteActionImplementation(endpoint.getRouter(), config);
            prevReg = actionRegs.put(e.getKey(), actionProviderService.registerActionImplementation(impl, endpoint.getActions()));
        } else {
            prevReg = actionRegs.remove(e.getKey());
        }
        if (prevReg != null) {
            prevRegs.add(prevReg);
        }
    }
    prevRegs.forEach(ObjectRegistration::close);
}
Also used : DOMActionImplementation(org.opendaylight.mdsal.dom.api.DOMActionImplementation) Address(akka.actor.Address) Optional(java.util.Optional) RemoteActionEndpoint(org.opendaylight.controller.remote.rpc.registry.ActionRegistry.RemoteActionEndpoint) ArrayList(java.util.ArrayList) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration)

Aggregations

Address (akka.actor.Address)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 RemoteActionEndpoint (org.opendaylight.controller.remote.rpc.registry.ActionRegistry.RemoteActionEndpoint)1 DOMActionImplementation (org.opendaylight.mdsal.dom.api.DOMActionImplementation)1 ObjectRegistration (org.opendaylight.yangtools.concepts.ObjectRegistration)1