public void Run(ISourceContext <long> ctx)
 {
     while (_isRunning && _counter < 1000)
     {
         lock (ctx.GetCheckpointLock())
         {
             ctx.Collect(_counter);
             _counter++;
         }
     }
 }
        public void Run(ISourceContext <T> ctx)
        {
            var stream = new MemoryStream(_elementsSerialized);
            var input  = new DataInputViewStreamWrapper(stream);

            // if we are restored from a checkpoint and need to skip elements, skip them now.
            var toSkip = _numElementsToSkip;

            if (toSkip <= 0)
            {
                return;
            }

            try
            {
                while (toSkip > 0)
                {
                    _serializer.Deserialize(input);
                    toSkip--;
                }
            }
            catch (Exception e)
            {
                throw new IOException("Failed to deserialize an element from the source. " +
                                      "If you are using user-defined serialization (Value and Writable types), check the " +
                                      "serialization functions.\nSerializer is " + _serializer, e);
            }

            _numElementsEmitted = _numElementsToSkip;

            var mutex = ctx.GetCheckpointLock();

            while (_isRunning && _numElementsEmitted < _numElements)
            {
                T next;
                try
                {
                    next = _serializer.Deserialize(input);
                }
                catch (Exception e)
                {
                    throw new IOException("Failed to deserialize an element from the source. " +
                                          "If you are using user-defined serialization (Value and Writable types), check the " +
                                          "serialization functions.\nSerializer is " + _serializer, e);
                }

                lock (mutex)
                {
                    ctx.Collect(next);
                    _numElementsEmitted++;
                }
            }
        }