예제 #1
0
            public OperatorStateReader(IOperatorStateReaderFactory factory, ISerializer serializer, Stream stream, IStatefulOperator @operator)
            {
                Debug.Assert(factory != null);
                Debug.Assert(serializer != null);
                Debug.Assert(stream != null);

                _factory    = factory;
                _serializer = serializer;
                _operator   = @operator;

                _underlyingStream = stream;
                _originalPosition = stream.Position;
                _end = _originalPosition;

                var lenBytes  = new byte[8];
                var readCount = stream.Read(lenBytes, 0, 8);

                if (readCount != 8 && @operator is not ITransitioningOperator)
                {
                    var blob = stream.GetBase64Blob();
                    throw new InvalidDataException(string.Format(CultureInfo.InvariantCulture, "Missing length prefix. Operator = {0}/{1}, Position = {2}, State = {3}", _operator.Name, _operator.Version, _originalPosition, blob));
                }
                else if (readCount == 8)
                {
                    var length = BitConverter.ToInt64(lenBytes, 0);
                    _stream = new StreamSegment(stream, stream.Position, length);
                    _end    = stream.Position + length;
                }
            }
        /// <summary>
        /// Loads the state of operators in the <paramref name="subscription"/> from state readers obtained by the specified state reader factory.
        /// </summary>
        /// <param name="subscription">The subscription to save state for.</param>
        /// <param name="factory">State reader factory to obtain state readers for operators from.</param>
        public static void LoadState(ISubscription subscription, IOperatorStateReaderFactory factory)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException(nameof(subscription));
            }

            LoadStateCore(subscription, factory);
        }
        internal static void LoadStateCore(ISubscription subscription, IOperatorStateReaderFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            subscription.Accept(new LoadStateVisitor(factory));
        }
예제 #4
0
        /// <summary>
        /// Initializes the operators in the subscription using the specified operator context, optionally applying state to them.
        /// </summary>
        /// <param name="context">Operator context to set on the operators in the subscription.</param>
        /// <param name="state">State reader factory to read operator state from. This parameter can be left <c>null</c>.</param>
        public void Initialize(IOperatorContext context, IOperatorStateReaderFactory state)
        {
            Subscribe();
            SetContext(context);

            if (state != null)
            {
                LoadState(state);
            }

            Start();
        }
예제 #5
0
        /// <summary>
        /// Loads the state of the specified stateful operator using a reader obtained from the specified state reader factory.
        /// </summary>
        /// <param name="factory">Factory to create an operator state reader to read operator state from.</param>
        /// <param name="node">Operator whose state to read.</param>
        public static void LoadState(this IOperatorStateReaderFactory factory, IStatefulOperator node)
        {
            using var reader = factory.Create(node);

            LoadState(reader, node);
        }
 /// <summary>
 /// Loads the state of operators in the subscription from state readers obtained by the specified state reader factory.
 /// </summary>
 /// <param name="factory">State reader factory to obtain state readers for operators from.</param>
 public void LoadState(IOperatorStateReaderFactory factory) => LoadStateCore(_subscription, factory);
 public LoadStateVisitor(IOperatorStateReaderFactory factory)
 {
     _factory = factory;
 }
예제 #8
0
 /// <summary>
 /// Loads the state of operators in the subscription using the specified operator state reader facotry.
 /// </summary>
 /// <param name="factory">State reader factory to read operator state from.</param>
 public void LoadState(IOperatorStateReaderFactory factory)
 {
     SubscriptionStateVisitor.LoadStateCore(_subscription, factory);
 }