private void advance(boolean accepted, List<String> states, Reply reply) { try { StateSequencerUtil.advanceMultiple(stateSequencer, accepted, states); } catch (TimeoutException e) { reply.reply(new ExceptionResponse(e)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); reply.reply(new ExceptionResponse(e)); } } }
@Override public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) { CountDownLatch latch = this.latch; if (command instanceof RenewBiasCommand && latch != null) { delegate.handle(command, response -> { reply.reply(response); this.latch = null; latch.countDown(); }, order); } else { delegate.handle(command, reply, order); } } }
@Override public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) { if (command instanceof EndInvalidationCommand) { delegate.handle(command, response -> { latch.countDown(); log.tracef("Latch after count down %s", latch); reply.reply(response); }, order); } else { delegate.handle(command, reply, order); } }
@Override public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) { if (!(command instanceof PrepareCommand)) { delegate.handle(command, reply, order); return; } try { prepareReceived.countDown(); prepareBlocked.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new IllegalLifecycleStateException(e); } log.trace("Processing belated prepare"); delegate.handle(command, returnValue -> { prepareExecuted.countDown(); reply.reply(returnValue); }, order); } };
@Override public void handle(CacheRpcCommand cmd, Reply reply, DeliverOrder order) { boolean notifyRehashStarted = false; if (cmd instanceof CacheTopologyControlCommand) { CacheTopologyControlCommand rcc = (CacheTopologyControlCommand) cmd; log.debugf("Intercepted command: %s", cmd); switch (rcc.getType()) { case REBALANCE_START: try { txsReady.await(10, SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); reply.reply(new ExceptionResponse(e)); return; } notifyRehashStarted = true; break; case CH_UPDATE: // TODO Use another type instead, e.g. REBASE_END joinEnded.countDown(); break; } } delegate.handle(cmd, reply, order); if (notifyRehashStarted) rehashStarted.countDown(); } }
@Override protected synchronized boolean beforeHandle(CacheRpcCommand command, Reply reply, DeliverOrder order) { if (command instanceof XSiteStatePushCommand) { boolean fail; synchronized (this) { fail = nFailures == FAIL_FOR_EVER; if (nFailures > 0) { fail = true; nFailures--; } } if (fail) { reply.reply(new ExceptionResponse(new CacheException("Induced Fail."))); return false; } } return true; } }