Beispiel #1
0
        /// <summary>
        /// Invokes the proxy.
        /// </summary>
        /// <param name="method">Method.</param>
        /// <param name="args">Arguments.</param>
        /// <returns>
        /// Invocation result.
        /// </returns>
        private object InvokeProxyMethod(MethodBase method, object[] args)
        {
            using (var inStream = new PlatformMemoryStream(_memory.Allocate()))
                using (var outStream = new PlatformMemoryStream(_memory.Allocate()))
                {
                    // 1) Write to a stream
                    inStream.WriteBool(SrvKeepBinary); // WriteProxyMethod does not do this, but Java does

                    ServiceProxySerializer.WriteProxyMethod(_marsh.StartMarshal(inStream), method, args);

                    inStream.SynchronizeOutput();

                    inStream.Seek(0, SeekOrigin.Begin);

                    // 2) call InvokeServiceMethod
                    string   mthdName;
                    object[] mthdArgs;

                    ServiceProxySerializer.ReadProxyMethod(inStream, _marsh, out mthdName, out mthdArgs);

                    var result = ServiceProxyInvoker.InvokeServiceMethod(_svc, mthdName, mthdArgs);

                    ServiceProxySerializer.WriteInvocationResult(outStream, _marsh, result.Key, result.Value);

                    _marsh.StartMarshal(outStream).WriteString("unused"); // fake Java exception details

                    outStream.SynchronizeOutput();

                    outStream.Seek(0, SeekOrigin.Begin);

                    return(ServiceProxySerializer.ReadInvocationResult(outStream, _marsh, KeepBinary));
                }
        }
        /// <summary>
        /// Writes the partitions assignment to a stream.
        /// </summary>
        /// <param name="parts">The parts.</param>
        /// <param name="stream">The stream.</param>
        /// <param name="marsh">The marshaller.</param>
        internal static void WritePartitions(IEnumerable <IEnumerable <IClusterNode> > parts,
                                             PlatformMemoryStream stream, Marshaller marsh)
        {
            Debug.Assert(parts != null);
            Debug.Assert(stream != null);
            Debug.Assert(marsh != null);

            IBinaryRawWriter writer = marsh.StartMarshal(stream);

            var partCnt = 0;

            writer.WriteInt(partCnt); // reserve size

            foreach (var part in parts)
            {
                if (part == null)
                {
                    throw new IgniteException("IAffinityFunction.AssignPartitions() returned invalid partition: null");
                }

                partCnt++;

                var nodeCnt = 0;
                var cntPos  = stream.Position;
                writer.WriteInt(nodeCnt); // reserve size

                foreach (var node in part)
                {
                    nodeCnt++;
                    writer.WriteGuid(node.Id);
                }

                var endPos = stream.Position;
                stream.Seek(cntPos, SeekOrigin.Begin);
                stream.WriteInt(nodeCnt);
                stream.Seek(endPos, SeekOrigin.Begin);
            }

            stream.SynchronizeOutput();
            stream.Seek(0, SeekOrigin.Begin);
            writer.WriteInt(partCnt);
        }