protected final void commitContextEntries(
      InvocationContext ctx, FlagAffectedCommand command, Metadata metadata) {
    final Flag stateTransferFlag = extractStateTransferFlag(ctx, command);

    if (stateTransferFlag == null) {
      // it is a normal operation
      stopStateTransferIfNeeded(command);
    }

    if (ctx instanceof SingleKeyNonTxInvocationContext) {
      SingleKeyNonTxInvocationContext singleKeyCtx = (SingleKeyNonTxInvocationContext) ctx;
      commitEntryIfNeeded(ctx, command, singleKeyCtx.getCacheEntry(), stateTransferFlag, metadata);
    } else {
      Set<Map.Entry<Object, CacheEntry>> entries = ctx.getLookedUpEntries().entrySet();
      Iterator<Map.Entry<Object, CacheEntry>> it = entries.iterator();
      final Log log = getLog();
      while (it.hasNext()) {
        Map.Entry<Object, CacheEntry> e = it.next();
        CacheEntry entry = e.getValue();
        if (!commitEntryIfNeeded(ctx, command, entry, stateTransferFlag, metadata)) {
          if (trace) {
            if (entry == null)
              log.tracef("Entry for key %s is null : not calling commitUpdate", toStr(e.getKey()));
            else
              log.tracef(
                  "Entry for key %s is not changed(%s): not calling commitUpdate",
                  toStr(e.getKey()), entry);
          }
        }
      }
    }
  }
  private void applyStateInNonTransaction(XSiteState[] chunk) {
    SingleKeyNonTxInvocationContext ctx =
        (SingleKeyNonTxInvocationContext)
            invocationContextFactory.createSingleKeyNonTxInvocationContext();

    for (XSiteState siteState : chunk) {
      PutKeyValueCommand command = createPut(siteState);
      ctx.setLockOwner(command.getLockOwner());
      interceptorChain.invoke(ctx, command);
      ctx.resetState(); // re-use same context. Old context is not longer needed
      if (trace) {
        log.tracef("Successfully applied key'%s'", siteState);
      }
    }
    if (debug) {
      log.debugf("Successfully applied state. %s keys inserted", chunk.length);
    }
  }