示例#1
0
        /// <summary>
        /// Processes the given stream to construct a Payload object.
        /// </summary>
        /// <param name="stream">The stream to read from</param>
        /// <returns>
        /// Returns a valid payload object if the stream contains all the necessary data.
        /// Returns null if the stream is already closed at the beginning of the read.
        /// </returns>
        internal Payload Process(Stream stream)
        {
            var payload = new Payload();

            byte[] splitIndexBytes;
            try
            {
                splitIndexBytes = SerDe.ReadBytes(stream, sizeof(int));
                // For socket stream, read on the stream returns 0, which
                // SerDe.ReadBytes() returns as null to denote the stream is closed.
                if (splitIndexBytes == null)
                {
                    return(null);
                }
            }
            catch (ObjectDisposedException)
            {
                // For stream implementation such as MemoryStream will throw
                // ObjectDisposedException if the stream is already closed.
                return(null);
            }

            payload.SplitIndex = BinaryPrimitives.ReadInt32BigEndian(splitIndexBytes);
            payload.Version    = SerDe.ReadString(stream);

            payload.TaskContext = new TaskContextProcessor(_version).Process(stream);
            TaskContextHolder.Set(payload.TaskContext);

            payload.SparkFilesDir = SerDe.ReadString(stream);
            SparkFiles.SetRootDirectory(payload.SparkFilesDir);

            // Register additional assembly handlers after SparkFilesDir has been set
            // and before any deserialization occurs. BroadcastVariableProcessor may
            // deserialize objects from assemblies that are not currently loaded within
            // our current context.
            AssemblyLoaderHelper.RegisterAssemblyHandler();

            if (ConfigurationService.IsDatabricks)
            {
                SerDe.ReadString(stream);
                SerDe.ReadString(stream);
            }

            payload.IncludeItems       = ReadIncludeItems(stream);
            payload.BroadcastVariables = new BroadcastVariableProcessor(_version).Process(stream);

            // TODO: Accumulate registration should be done here.

            payload.Command = new CommandProcessor(_version).Process(stream);

            return(payload);
        }