예제 #1
0
 protected StateBoundComputed(
     ComputedOptions options,
     State <T> input,
     Result <T> output, LTag version, bool isConsistent)
     : base(options, input, output, version, isConsistent)
 {
 }
예제 #2
0
        //todo: come back to this, setting up for single-unit negation
        public bool Matches(LTag e)
        {
            if (IsComposite)
            {
                if (LeftCondition.Matches(e))
                    LeftMatched = true;
                if (RightCondition.Matches(e))
                    RightMatched = true;

                if (Operator == LOGIC_OP.AND && (CheckNeg() && CheckNeg(false)))
                {
                    Matched = true;
                }
                else if (CheckNeg() || CheckNeg(false)) //must be OR op
                {
                    Matched = true;
                }
            }
            else
            {
                if (Tag.Tag == e.Tag && Negation == false)
                {
                    Matched = true;
                }
                else if (Tag.Tag != e.Tag && Negation == true)
                {
                    Matched = true;
                }
            }
            return Matched;
        }
        public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            var value = (string)reader.Value !;

            // ReSharper disable once HeapView.BoxingAllocation
            return(LTag.Parse(value));
        }
예제 #4
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string s)
     {
         // ReSharper disable once HeapView.BoxingAllocation
         return(LTag.Parse(s));
     }
     return(base.ConvertFrom(context, culture, value));
 }
예제 #5
0
 public virtual IReplica <T> GetOrAdd <T>(
     Symbol publisherId, Symbol publicationId,
     Result <T> output, LTag version, bool isConsistent = true,
     bool requestUpdate = false)
 {
     var(replica, isNew) = Registry.GetOrAdd(publicationId,
                                             () => new Replica <T>(this, publisherId, publicationId, output, version, isConsistent, requestUpdate));
     if (isNew)
     {
         Subscribe(replica);
     }
     return((IReplica <T>)replica);
 }
예제 #6
0
 protected Computed(ComputedOptions options, ComputeMethodInput input, Result <T> output, LTag version, bool isConsistent = true)
     : base(options, input, output, version, isConsistent)
 {
 }
예제 #7
0
 public Computed(ComputedOptions options, ComputeMethodInput input, LTag version)
     : base(options, input, version)
 {
 }
예제 #8
0
 protected internal SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag version)
     : base(options, input, version)
 {
 }
예제 #9
0
 protected SwappingComputed(ComputedOptions options, InterceptedInput input, ResultBox <T> maybeOutput, LTag version, bool isConsistent)
     : base(options, input, default, version, isConsistent)
     => _maybeOutput = maybeOutput;
 protected abstract IComputed <T> CreateComputed(ComputeMethodInput input, LTag tag);
예제 #11
0
 public SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag version)
     : base(options, input, version)
 {
 }
예제 #12
0
 public ReplicaClientComputed(ComputedOptions options, InterceptedInput input, Exception error, LTag version)
     : this(options, null, input, new Result <T>(default !, error), version, false)
 protected override IComputed <T> CreateComputed(InterceptedInput input, LTag tag)
 => new Computed <T>(Options, input, tag);
예제 #14
0
 public ReplicaServiceComputed(ComputedOptions options, InterceptedInput input, Exception error, LTag lTag)
     : this(options, null, input, new Result <T>(default !, error), lTag, false)
예제 #15
0
 public SimpleComputed(ComputedOptions options, SimpleComputedInput input, LTag lTag)
     : base(options, input, lTag)
 {
 }
예제 #16
0
 public ReplicaMethodComputed(ComputedOptions options, ComputeMethodInput input, Exception error, LTag version)
     : this(null, options, input, new Result <T>(default !, error), version, false)
예제 #17
0
 public ReplicaComputed(ComputedOptions options, ReplicaInput input, LTag lTag)
     : base(options, input, lTag)
 {
 }
예제 #18
0
 protected override IComputed <T> CreateComputed(ComputeMethodInput input, LTag tag)
 => new Computed <T>(Options, input, tag);
예제 #19
0
 public ReplicaComputed(ComputedOptions options, ReplicaInput input, Result <T> output, LTag lTag, bool isConsistent = true)
     : base(options, input, output, lTag, isConsistent)
 {
 }
예제 #20
0
 public SimpleComputed(ComputedOptions options, SimpleComputedInput input,
                       Result <T> output, LTag version, bool isConsistent = true)
     : base(options, input, output, version, isConsistent)
 {
 }
예제 #21
0
 public StateBoundComputed(
     ComputedOptions options,
     State <T> input, LTag version)
     : base(options, input, version)
 {
 }
예제 #22
0
 public SwappingComputed(ComputedOptions options, InterceptedInput input, LTag version)
     : base(options, input, version)
 {
 }
예제 #23
0
        public IComputed?TryGetCachedComputed(LTag lTag, IComputed?usedBy = null)
        {
            var computed = TryGetCachedComputed(usedBy);

            return(computed == null ? computed : computed.LTag == lTag ? computed : null);
        }
예제 #24
0
 protected ReplicaComputed(ComputedOptions options, ReplicaInput input, LTag version)
     : base(options, input, version)
 {
 }
예제 #25
0
        protected override async ValueTask <IComputed <T> > ComputeAsync(
            InterceptedInput input, IComputed <T>?cached,
            CancellationToken cancellationToken)
        {
            var method = input.Method;

            // 1. Trying to update the Replica first
            if (cached is IReplicaServiceComputed <T> rsc && rsc.Replica != null)
            {
                try {
                    var replica  = rsc.Replica;
                    var computed = await replica.Computed
                                   .UpdateAsync(true, cancellationToken).ConfigureAwait(false);

                    var replicaComputed = (IReplicaComputed <T>)computed;
                    var output          = new ReplicaServiceComputed <T>(
                        method.Options, replicaComputed, input);
                    return(output);
                }
                catch (OperationCanceledException) {
                    if (_isLogDebugEnabled)
                    {
                        _log.LogDebug($"{nameof(ComputeAsync)}: Cancelled (1).");
                    }
                    throw;
                }
                catch (Exception e) {
                    if (_isLogDebugEnabled)
                    {
                        _log.LogError(e, $"{nameof(ComputeAsync)}: Error on Replica update.");
                    }
                }
            }

            // 2. Replica update failed, let's refresh it
            try {
                using var replicaCapture = new ReplicaCapture();
                var result = input.InvokeOriginalFunction(cancellationToken);
                if (method.ReturnsComputed)
                {
                    if (method.ReturnsValueTask)
                    {
                        var task = (ValueTask <IComputed <T> >)result;
                        await task.ConfigureAwait(false);
                    }
                    else
                    {
                        var task = (Task <IComputed <T> >)result;
                        await task.ConfigureAwait(false);
                    }
                }
                else
                {
                    if (method.ReturnsValueTask)
                    {
                        var task = (ValueTask <T>)result;
                        await task.ConfigureAwait(false);
                    }
                    else
                    {
                        var task = (Task <T>)result;
                        await task.ConfigureAwait(false);
                    }
                }
                var replica  = replicaCapture.GetCapturedReplica <T>();
                var computed = await replica.Computed
                               .UpdateAsync(true, cancellationToken).ConfigureAwait(false);

                var replicaComputed = (IReplicaComputed <T>)computed;
                var output          = new ReplicaServiceComputed <T>(
                    method.Options, replicaComputed, input);
                return(output);
            }
            catch (OperationCanceledException) {
                if (_isLogDebugEnabled)
                {
                    _log.LogDebug($"{nameof(ComputeAsync)}: Cancelled (2).");
                }
                throw;
            }
            catch (Exception e) {
                if (_isLogDebugEnabled)
                {
                    _log.LogError(e, $"{nameof(ComputeAsync)}: Error on update.");
                }
                // We need a unique LTag here, so we use a range that's supposed
                // to be unused by LTagGenerators.
                var lTag   = new LTag(LTagGenerator.Next().Value ^ (1L << 62));
                var output = new ReplicaServiceComputed <T>(
                    method.Options, null, input, new Result <T>(default !, e), lTag);
예제 #26
0
 public ReplicaComputed(ComputedOptions options, ReplicaInput input, Result <T> output, LTag version, bool isConsistent)
     : base(options, input, output, version, isConsistent)
 {
 }
예제 #27
0
 protected abstract IComputed <T> CreateComputed(InterceptedInput input, LTag tag);