Example #1
0
        public override void ApplyCommand(ReplicatedTokenRequest tokenRequest, long commandIndex, System.Action <Result> callback)
        {
            lock (this)
            {
                if (commandIndex <= _lastCommittedIndex)
                {
                    return;
                }

                int?tokenId = _tokenRegistry.getId(tokenRequest.TokenName());

                if (tokenId == null)
                {
                    try
                    {
                        ICollection <StorageCommand> commands = ReplicatedTokenRequestSerializer.ExtractCommands(tokenRequest.CommandBytes());
                        tokenId = ApplyToStore(commands, commandIndex);
                    }
                    catch (NoSuchEntryException)
                    {
                        throw new System.InvalidOperationException("Commands did not contain token command");
                    }

                    _tokenRegistry.put(new NamedToken(tokenRequest.TokenName(), tokenId.Value));
                }

                callback(Result.of(tokenId));
            }
        }