public CommandsForKey listenerUpdate()

in accord-core/src/main/java/accord/impl/SafeCommandsForKey.java [120:164]


    public <D> CommandsForKey listenerUpdate(Command command)
    {
        if (logger.isTraceEnabled())
            logger.trace("[{}]: updating as listener in response to change on {} with status {} ({})",
                         key(), command.txnId(), command.status(), command);

        CommandsForKey current = current();
        CommandTimeseries.Update<D> byId = (CommandTimeseries.Update<D>) current().byId().beginUpdate();
        CommandTimeseries.Update<D> byExecuteAt = (CommandTimeseries.Update<D>) current().byExecuteAt().beginUpdate();

        // add/remove the command on every listener update to avoid
        // special denormalization handling in Cassandra
        switch (command.status())
        {
            default: throw new AssertionError();
            case PreAccepted:
            case NotWitnessed:
            case Accepted:
            case AcceptedInvalidate:
            case PreCommitted:
                byId.add(command.txnId(), command);
                byExecuteAt.add(command.txnId(), command);
                break;
            case Applied:
            case PreApplied:
            case Committed:
            case ReadyToExecute:
                byId.add(command.txnId(), command);
                byExecuteAt.remove(command.txnId());
                byExecuteAt.add(command.executeAt(), command);
                break;
            case Invalidated:
                byId.remove(command.txnId());
                byExecuteAt.remove(command.txnId());
                break;
        }

        return update(new CommandsForKey(current.key(),
                                         updateMax(current, command.executeAt()),
                                         current.lastExecutedTimestamp(),
                                         current.lastExecutedMicros(),
                                         current.lastWriteTimestamp(),
                                         byId.build(),
                                         byExecuteAt.build()));
    }