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)); } }
private sbyte[] CreateCommands(string tokenName) { StorageEngine storageEngine = _storageEngineSupplier.get(); ICollection <StorageCommand> commands = new List <StorageCommand>(); TransactionState txState = new TxState(); int tokenId = Math.toIntExact(_idGeneratorFactory.get(_tokenIdType).nextId()); _tokenCreator.createToken(txState, tokenName, tokenId); try { using (StorageReader statement = storageEngine.NewReader()) { storageEngine.CreateCommands(commands, txState, statement, [email protected]_Fields.None, long.MaxValue, NO_DECORATION); } } catch (Exception e) when(e is CreateConstraintFailureException || e is TransactionFailureException || e is ConstraintValidationException) { throw new Exception("Unable to create token '" + tokenName + "'", e); } return(ReplicatedTokenRequestSerializer.CommandBytes(commands)); }