Code example for Cache

Methods: getIfPresentinvalidate

                    transactionID, shard.path());
        // Lookup the cohort entry that was cached previously (or should have been) by 
        // transactionReady (via the ForwardedReadyTransaction message). 
        final CohortEntry cohortEntry = cohortCache.getIfPresent(transactionID);
        if(cohortEntry == null) {
            // Either canCommit was invoked before ready(shouldn't happen)  or a long time passed 
            // between canCommit and ready and the entry was expired from the cache. 
            IllegalStateException ex = new IllegalStateException(
                    String.format("No cohort entry found for transaction %s", transactionID));
            sender.tell(new Status.Failure(ex), shard);
        if(currentCohortEntry != null) {
            // There's already a Tx commit in progress - attempt to queue this entry to be 
            // committed after the current Tx completes. 
            LOG.debug("Transaction {} is already in progress - queueing transaction {}", 
                    currentCohortEntry.getTransactionID(), transactionID);
            if(queuedCohortEntries.size() < queueCapacity) {
            } else { 
                RuntimeException ex = new RuntimeException(
                        String.format("Could not enqueue transaction %s - the maximum commit queue"+
                                      " capacity %d has been reached.", 
                                transactionID, queueCapacity));
                sender.tell(new Status.Failure(ex), shard);
        } else { 
            // No Tx commit currently in progress - make this the current entry and proceed with 
            // canCommit. 
            currentCohortEntry = cohortEntry;
    private void doCanCommit(final CohortEntry cohortEntry) {
        try { 
            // We block on the future here so we don't have to worry about possibly accessing our 
            // state on a different thread outside of our dispatcher. Also, the data store 
            // currently uses a same thread executor anyway. 
            Boolean canCommit = cohortEntry.getCohort().canCommit().get();
                    canCommit ? CAN_COMMIT_REPLY_TRUE : CAN_COMMIT_REPLY_FALSE, cohortEntry.getShard());
            if(!canCommit) {
                // Remove the entry from the cache now since the Tx will be aborted. 
        } catch (InterruptedException | ExecutionException e) {
            LOG.debug("An exception occurred during canCommit", e);
            // Remove the entry from the cache now since the Tx will be aborted. 
            cohortEntry.getCanCommitSender().tell(new Status.Failure(e), cohortEntry.getShard());
     * Returns the cohort entry for the Tx commit currently in progress if the given transaction ID 
     * matches the current entry. 
     * @param transactionID the ID of the transaction 
     * @return the current CohortEntry or null if the given transaction ID does not match the 
     *         current entry. 
    public CohortEntry getCohortEntryIfCurrent(String transactionID) {
        if(isCurrentTransaction(transactionID)) {
            return currentCohortEntry;
        return null; 
    public CohortEntry getCurrentCohortEntry() { 
        return currentCohortEntry;
    public CohortEntry getAndRemoveCohortEntry(String transactionID) {
        CohortEntry cohortEntry = cohortCache.getIfPresent(transactionID);
        return cohortEntry;
    public void removeCohortEntry(String transactionID) {
    public boolean isCurrentTransaction(String transactionID) {
        return currentCohortEntry != null &&
Connect your IDE to all the code out there  Get Codota for Java