use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.
the class RpcRegistrarTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
system = ActorSystem.create("test");
final TestKit testKit = new TestKit(system);
final RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("system").build();
final Props props = RpcRegistrar.props(config, service);
testActorRef = new TestActorRef<>(system, props, testKit.getRef(), "actorRef");
endpointAddress = new Address("http", "local");
final DOMRpcIdentifier firstEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("first:identifier", "foo")));
final DOMRpcIdentifier secondEndpointId = DOMRpcIdentifier.create(SchemaPath.create(true, QName.create("second:identifier", "bar")));
final TestKit senderKit = new TestKit(system);
firstEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(firstEndpointId));
secondEndpoint = new RemoteRpcEndpoint(senderKit.getRef(), Collections.singletonList(secondEndpointId));
Mockito.doReturn(oldReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(firstEndpoint.getRpcs()));
Mockito.doReturn(newReg).when(service).registerRpcImplementation(Mockito.any(RemoteRpcImplementation.class), Mockito.eq(secondEndpoint.getRpcs()));
rpcRegistrar = testActorRef.underlyingActor();
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.
the class RpcRegistryTest method assertEndpoints.
private static void assertEndpoints(final UpdateRemoteEndpoints msg, final Address address, final TestKit invoker) {
final Map<Address, Optional<RemoteRpcEndpoint>> endpoints = msg.getEndpoints();
Assert.assertEquals(1, endpoints.size());
final Optional<RemoteRpcEndpoint> maybeEndpoint = endpoints.get(address);
Assert.assertNotNull(maybeEndpoint);
Assert.assertTrue(maybeEndpoint.isPresent());
final RemoteRpcEndpoint endpoint = maybeEndpoint.get();
final ActorRef router = endpoint.getRouter();
Assert.assertNotNull(router);
router.tell("hello", ActorRef.noSender());
final String s = invoker.expectMsgClass(Duration.create(3, TimeUnit.SECONDS), String.class);
Assert.assertEquals("hello", s);
}
use of org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint in project controller by opendaylight.
the class RpcRegistrar method updateRemoteEndpoints.
private void updateRemoteEndpoints(final Map<Address, Optional<RemoteRpcEndpoint>> endpoints) {
/*
* Updating RPC 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 RPC 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<DOMRpcImplementationRegistration<?>> prevRegs = new ArrayList<>(endpoints.size());
for (Entry<Address, Optional<RemoteRpcEndpoint>> e : endpoints.entrySet()) {
LOG.debug("Updating RPC registrations for {}", e.getKey());
final DOMRpcImplementationRegistration<?> prevReg;
final Optional<RemoteRpcEndpoint> maybeEndpoint = e.getValue();
if (maybeEndpoint.isPresent()) {
final RemoteRpcEndpoint endpoint = maybeEndpoint.get();
final RemoteRpcImplementation impl = new RemoteRpcImplementation(endpoint.getRouter(), config);
prevReg = regs.put(e.getKey(), rpcProviderService.registerRpcImplementation(impl, endpoint.getRpcs()));
} else {
prevReg = regs.remove(e.getKey());
}
if (prevReg != null) {
prevRegs.add(prevReg);
}
}
for (DOMRpcImplementationRegistration<?> r : prevRegs) {
r.close();
}
}
Aggregations