Example #1
0
        /// <summary>
        /// Prepare lifecycle beans.
        /// </summary>
        /// <param name="reader">Reader.</param>
        /// <param name="outStream">Output stream.</param>
        /// <param name="handleRegistry">Handle registry.</param>
        private static void PrepareLifecycleBeans(BinaryReader reader, PlatformMemoryStream outStream, 
            HandleRegistry handleRegistry)
        {
            IList<LifecycleBeanHolder> beans = new List<LifecycleBeanHolder>();

            // 1. Read beans defined in Java.
            int cnt = reader.ReadInt();

            for (int i = 0; i < cnt; i++)
                beans.Add(new LifecycleBeanHolder(CreateLifecycleBean(reader)));

            // 2. Append beans definied in local configuration.
            ICollection<ILifecycleBean> nativeBeans = _startup.Configuration.LifecycleBeans;

            if (nativeBeans != null)
            {
                foreach (ILifecycleBean nativeBean in nativeBeans)
                    beans.Add(new LifecycleBeanHolder(nativeBean));
            }

            // 3. Write bean pointers to Java stream.
            outStream.WriteInt(beans.Count);

            foreach (LifecycleBeanHolder bean in beans)
                outStream.WriteLong(handleRegistry.AllocateCritical(bean));

            outStream.SynchronizeOutput();

            // 4. Set beans to STARTUP object.
            _startup.LifecycleBeans = beans;
        }
Example #2
0
 public void TestPlatformMemoryStream()
 {
     var stream = new PlatformMemoryStream(GetMemory());
     TestStream(stream, false, () => stream.SynchronizeOutput());
 }
Example #3
0
        /// <summary>
        /// Preapare configuration.
        /// </summary>
        /// <param name="reader">Reader.</param>
        /// <param name="outStream">Response stream.</param>
        private static void PrepareConfiguration(BinaryReader reader, PlatformMemoryStream outStream)
        {
            // 1. Load assemblies.
            IgniteConfiguration cfg = _startup.Configuration;

            LoadAssemblies(cfg.Assemblies);

            ICollection<string> cfgAssembllies;
            BinaryConfiguration binaryCfg;

            BinaryUtils.ReadConfiguration(reader, out cfgAssembllies, out binaryCfg);

            LoadAssemblies(cfgAssembllies);

            // 2. Create marshaller only after assemblies are loaded.
            if (cfg.BinaryConfiguration == null)
                cfg.BinaryConfiguration = binaryCfg;

            _startup.Marshaller = new Marshaller(cfg.BinaryConfiguration);

            // 3. Send configuration details to Java
            cfg.Write(_startup.Marshaller.StartMarshal(outStream));
        }
Example #4
0
        /// <summary>
        /// Prepare callback invoked from Java.
        /// </summary>
        /// <param name="inStream">Intput stream with data.</param>
        /// <param name="outStream">Output stream.</param>
        /// <param name="handleRegistry">Handle registry.</param>
        internal static void OnPrepare(PlatformMemoryStream inStream, PlatformMemoryStream outStream, 
            HandleRegistry handleRegistry)
        {
            try
            {
                BinaryReader reader = BinaryUtils.Marshaller.StartUnmarshal(inStream);

                PrepareConfiguration(reader, outStream);

                PrepareLifecycleBeans(reader, outStream, handleRegistry);
            }
            catch (Exception e)
            {
                _startup.Error = e;

                throw;
            }
        }
Example #5
0
        /// <summary>
        /// Execute job serializing result to the stream.
        /// </summary>
        /// <param name="cancel">Whether the job must be cancelled.</param>
        /// <param name="stream">Stream.</param>
        public void ExecuteRemote(PlatformMemoryStream stream, bool cancel)
        {
            // 1. Execute job.
            object res;
            bool success;

            Execute0(cancel, out res, out success);

            // 2. Try writing result to the stream.
            ClusterGroupImpl prj = _ignite.ClusterGroup;

            BinaryWriter writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                // 3. Marshal results.
                BinaryUtils.WriteInvocationResult(writer, success, res);
            }
            finally
            {
                // 4. Process metadata.
                prj.FinishMarshal(writer);
            }
        }
Example #6
0
        /// <summary>
        /// Prepare callback invoked from Java.
        /// </summary>
        /// <param name="inStream">Intput stream with data.</param>
        /// <param name="outStream">Output stream.</param>
        /// <param name="handleRegistry">Handle registry.</param>
        internal static void OnPrepare(PlatformMemoryStream inStream, PlatformMemoryStream outStream, 
            HandleRegistry handleRegistry)
        {
            try
            {
                PortableReaderImpl reader = PU.Marshaller.StartUnmarshal(inStream);

                PrepareConfiguration(reader.ReadObject<InteropDotNetConfiguration>());

                PrepareLifecycleBeans(reader, outStream, handleRegistry);
            }
            catch (Exception e)
            {
                _startup.Error = e;

                throw;
            }
        }
        /// <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);
        }