@Override public final <T> CompletionStage<T> invokeCommand(Address target, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { return performRequest(Collections.singleton(target), command, collector, c -> realOne.invokeCommand(target, command, c, rpcOptions), rpcOptions); }
public Object invokeRemotelyAsync(List<Address> finalOwners, InvocationContext rCtx, WriteCommand writeCmd) { if (rCtx.isOriginLocal() && writeCmd.isSuccessful()) { // This is called with the entry locked. In order to avoid deadlocks we must not wait for RPC while // holding the lock, therefore we'll return a future and wait for it in LockingInterceptor after // unlocking (and committing) the entry. if (isSynchronous(writeCmd)) { if (finalOwners != null) { return rpcManager.invokeCommand( finalOwners, writeCmd, MapResponseCollector.ignoreLeavers(finalOwners.size()), rpcManager.getSyncRpcOptions()); } else { return rpcManager.invokeCommandOnAll(writeCmd, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions()); } } else { rpcManager.sendToMany(finalOwners, writeCmd, DeliverOrder.NONE); } } return null; } }
@Override public final <T> CompletionStage<T> invokeCommand(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { return performRequest(targets, command, collector, c -> realOne.invokeCommand(targets, command, c, rpcOptions), rpcOptions); }
@Override public final <T> CompletionStage<T> invokeCommandStaggered(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { return performRequest(targets, command, collector, c -> realOne.invokeCommand(targets, command, c, rpcOptions), rpcOptions); }
@Override public <T> CompletionStage<T> invokeCommand(Address target, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { long start = timeService.time(); CompletionStage<T> request = actual.invokeCommand(target, command, collector, rpcOptions); return request.thenApply(responseMap -> { updateStats(command, true, timeService.timeDuration(start, NANOSECONDS), Collections.singleton(target)); return responseMap; }); }
private static void blockUntilRemoteNodesRespond(final CheckPoint checkPoint, Cache<?, ?> cache) { RpcManager realManager = TestingUtil.extractComponent(cache, RpcManager.class); RpcManager spy = spy(realManager); doAnswer(invocation -> Mocks.blockingCompletableFuture(() -> { try { return (CompletableFuture) invocation.callRealMethod(); } catch (Throwable throwable) { throw new AssertionError(throwable); } }, checkPoint).call() ).when(spy).invokeCommand(any(Address.class), any(StreamIteratorRequestCommand.class), any(), any()); TestingUtil.replaceComponent(cache, RpcManager.class, spy, true); } }
@Override public <T> CompletionStage<T> invokeCommand(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { long start = timeService.time(); CompletionStage<T> request = actual.invokeCommand(targets, command, collector, rpcOptions); return request.thenApply(responseMap -> { updateStats(command, true, timeService.timeDuration(start, NANOSECONDS), targets); return responseMap; }); }
/** * Completes the transaction in the cache when the originator is still in the cache topology. */ private CompletableFuture<Void> forwardCompleteCommand(ByteString cacheName, RpcManager rpcManager, TxState state) { //TODO what if the originator crashes in the meanwhile? //actually, the reaper would rollback the transaction later... Address originator = state.getOriginator(); CacheRpcCommand command = buildForwardCommand(cacheName, state.getTimeout()); return rpcManager.invokeCommand(originator, command, validOnly(), rpcManager.getSyncRpcOptions()) .handle(handler()) .toCompletableFuture(); }
@Override public <T> CompletionStage<T> invokeCommand(Address target, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { rpcCollector.addRPC(new RpcDetail(getAddress(), command, cacheName, Collections.singleton(target))); return delegate.invokeCommand(target, command, collector, rpcOptions); }
@Override public <T> CompletionStage<T> invokeCommand(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, RpcOptions rpcOptions) { rpcCollector.addRPC(new RpcDetail(getAddress(), command, cacheName, targets)); return delegate.invokeCommand(targets, command, collector, rpcOptions); }
public void testInvokeCommandCollectionSuspect() throws Exception { ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L); RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager(); command.setTopologyId(rpcManager0.getTopologyId()); CompletionStage<Map<Address, Response>> stage1 = rpcManager0.invokeCommand(Arrays.asList(SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); Exceptions.expectExecutionException(SuspectException.class, stage1.toCompletableFuture()); CompletionStage<Map<Address, Response>> stage2 = rpcManager0.invokeCommand(Arrays.asList(address(0), SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); Exceptions.expectExecutionException(SuspectException.class, stage2.toCompletableFuture()); CompletionStage<Map<Address, Response>> stage3 = rpcManager0.invokeCommand(Arrays.asList(address(0), address(1), SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); Exceptions.expectExecutionException(SuspectException.class, stage3.toCompletableFuture()); }
public void testInvokeCommandCollection() throws Exception { ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L); RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager(); Exceptions.expectException(IllegalArgumentException.class, () -> rpcManager0.invokeCommand(Arrays.asList(address(0)), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions())); command.setTopologyId(rpcManager0.getTopologyId()); CompletionStage<Map<Address, Response>> stage1 = rpcManager0.invokeCommand(Arrays.asList(address(0)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(Collections.emptyMap(), stage1); CompletionStage<Map<Address, Response>> stage2 = rpcManager0.invokeCommand(Arrays.asList(address(1)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(Collections.singletonMap(address(1), SUCCESSFUL_EMPTY_RESPONSE), stage2); CompletionStage<Map<Address, Response>> stage3 = rpcManager0.invokeCommand(Arrays.asList(address(0), address(1)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(Collections.singletonMap(address(1), SUCCESSFUL_EMPTY_RESPONSE), stage3); }
public void testInvokeCommand1() throws Exception { ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L); RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager(); Exceptions.expectException(IllegalArgumentException.class, () -> rpcManager0.invokeCommand(address(0), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions())); command.setTopologyId(rpcManager0.getTopologyId()); CompletionStage<ValidResponse> stage1 = rpcManager0.invokeCommand(address(0), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(null, stage1); CompletionStage<ValidResponse> stage2 = rpcManager0.invokeCommand(address(1), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); assertResponse(SUCCESSFUL_EMPTY_RESPONSE, stage2); CompletionStage<ValidResponse> stage3 = rpcManager0.invokeCommand(SUSPECT, command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()); Exceptions.expectExecutionException(SuspectException.class, stage3.toCompletableFuture()); }
private void sendRemotely(List<LuceneWork> works, ShardAddress destination, boolean originLocal) { String cacheName = indexManager.getCacheName(); AffinityUpdateCommand indexUpdateCommand = new AffinityUpdateCommand(ByteString.fromString(cacheName)); byte[] serializedModel = indexManager.getSerializer().toSerializedModel(works); indexUpdateCommand.setSerializedWorkList(serializedModel); indexUpdateCommand.setIndexName(destination.getShard()); Address dest = destination.getAddress(); if (this.shouldSendSync(originLocal)) { log.debugf("Sending sync works %s to %s", works, dest); Response response = rpcManager.blocking(rpcManager.invokeCommand(dest, indexUpdateCommand, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions())); log.debugf("Response %s obtained for command %s", response, works); } else { log.debugf("Sending async works %s to %s", works, dest); CompletionStage<ValidResponse> result = rpcManager.invokeCommand( dest, indexUpdateCommand, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()); result.whenComplete((responses, error) -> { if (error != null) { log.error("Error forwarding index job", error); } log.debugf("Async work %s applied successfully with response %s", works, responses); }); } }
when(rpcManager.invokeCommand(any(Address.class), any(StateRequestCommand.class), any(ResponseCollector.class), any(RpcOptions.class))) .thenAnswer(invocation -> {
return rpcManager.invokeCommand(owners, command, MapResponseCollector.ignoreLeavers(owners.size()), rpcManager.getSyncRpcOptions()); } else {