You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/09/21 16:27:35 UTC

[39/52] [partial] ignite git commit: IGNITE-1513: Moved .Net.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
new file mode 100644
index 0000000..5f764c1
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Ignite.cs
@@ -0,0 +1,511 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using System;
+    using System.Collections.Concurrent;
+    using System.Collections.Generic;
+    using System.Diagnostics;
+    using System.Linq;
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using Apache.Ignite.Core.Datastream;
+    using Apache.Ignite.Core.Events;
+    using Apache.Ignite.Core.Impl.Cache;
+    using Apache.Ignite.Core.Impl.Cluster;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Impl.Datastream;
+    using Apache.Ignite.Core.Impl.Handle;
+    using Apache.Ignite.Core.Impl.Portable;
+    using Apache.Ignite.Core.Impl.Transactions;
+    using Apache.Ignite.Core.Impl.Unmanaged;
+    using Apache.Ignite.Core.Lifecycle;
+    using Apache.Ignite.Core.Messaging;
+    using Apache.Ignite.Core.Portable;
+    using Apache.Ignite.Core.Services;
+    using Apache.Ignite.Core.Transactions;
+    using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
+
+    /// <summary>
+    /// Native Ignite wrapper.
+    /// </summary>
+    internal class Ignite : IIgnite, IClusterGroupEx, ICluster
+    {
+        /** */
+        private readonly IgniteConfiguration _cfg;
+
+        /** Grid name. */
+        private readonly string _name;
+
+        /** Unmanaged node. */
+        private readonly IUnmanagedTarget _proc;
+
+        /** Marshaller. */
+        private readonly PortableMarshaller _marsh;
+
+        /** Initial projection. */
+        private readonly ClusterGroupImpl _prj;
+
+        /** Portables. */
+        private readonly PortablesImpl _portables;
+
+        /** Cached proxy. */
+        private readonly IgniteProxy _proxy;
+
+        /** Lifecycle beans. */
+        private readonly IList<LifecycleBeanHolder> _lifecycleBeans;
+
+        /** Local node. */
+        private IClusterNode _locNode;
+
+        /** Transactions facade. */
+        private readonly Lazy<TransactionsImpl> _transactions;
+
+        /** Callbacks */
+        private readonly UnmanagedCallbacks _cbs;
+
+        /** Node info cache. */
+
+        private readonly ConcurrentDictionary<Guid, ClusterNodeImpl> _nodes =
+            new ConcurrentDictionary<Guid, ClusterNodeImpl>();
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        /// <param name="name">Grid name.</param>
+        /// <param name="proc">Interop processor.</param>
+        /// <param name="marsh">Marshaller.</param>
+        /// <param name="lifecycleBeans">Lifecycle beans.</param>
+        /// <param name="cbs">Callbacks.</param>
+        public Ignite(IgniteConfiguration cfg, string name, IUnmanagedTarget proc, PortableMarshaller marsh,
+            IList<LifecycleBeanHolder> lifecycleBeans, UnmanagedCallbacks cbs)
+        {
+            Debug.Assert(cfg != null);
+            Debug.Assert(proc != null);
+            Debug.Assert(marsh != null);
+            Debug.Assert(lifecycleBeans != null);
+            Debug.Assert(cbs != null);
+
+            _cfg = cfg;
+            _name = name;
+            _proc = proc;
+            _marsh = marsh;
+            _lifecycleBeans = lifecycleBeans;
+            _cbs = cbs;
+
+            marsh.Ignite = this;
+
+            _prj = new ClusterGroupImpl(proc, UU.ProcessorProjection(proc), marsh, this, null);
+
+            _portables = new PortablesImpl(marsh);
+
+            _proxy = new IgniteProxy(this);
+
+            cbs.Initialize(this);
+
+            // Grid is not completely started here, can't initialize interop transactions right away.
+            _transactions = new Lazy<TransactionsImpl>(
+                    () => new TransactionsImpl(UU.ProcessorTransactions(proc), marsh, GetLocalNode().Id));
+        }
+
+        /// <summary>
+        /// On-start routine.
+        /// </summary>
+        internal void OnStart()
+        {
+            foreach (var lifecycleBean in _lifecycleBeans)
+                lifecycleBean.OnStart(this);
+        }
+
+        /// <summary>
+        /// Gets Ignite proxy.
+        /// </summary>
+        /// <returns>Proxy.</returns>
+        public IgniteProxy Proxy
+        {
+            get { return _proxy; }
+        }
+
+        /** <inheritdoc /> */
+        public string Name
+        {
+            get { return _name; }
+        }
+
+        /** <inheritdoc /> */
+
+        public ICluster GetCluster()
+        {
+            return this;
+        }
+
+        /** <inheritdoc /> */
+        IIgnite IClusterGroup.Ignite
+        {
+            get { return this; }
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForLocal()
+        {
+            return _prj.ForNodes(GetLocalNode());
+        }
+
+        /** <inheritdoc /> */
+        public ICompute GetCompute()
+        {
+            return _prj.GetCompute();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodes(IEnumerable<IClusterNode> nodes)
+        {
+            return ((IClusterGroup) _prj).ForNodes(nodes);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodes(params IClusterNode[] nodes)
+        {
+            return _prj.ForNodes(nodes);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(IEnumerable<Guid> ids)
+        {
+            return ((IClusterGroup) _prj).ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(ICollection<Guid> ids)
+        {
+            return _prj.ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(params Guid[] ids)
+        {
+            return _prj.ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForPredicate(Func<IClusterNode, bool> p)
+        {
+            IgniteArgumentCheck.NotNull(p, "p");
+
+            return _prj.ForPredicate(p);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForAttribute(string name, string val)
+        {
+            return _prj.ForAttribute(name, val);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForCacheNodes(string name)
+        {
+            return _prj.ForCacheNodes(name);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForDataNodes(string name)
+        {
+            return _prj.ForDataNodes(name);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForClientNodes(string name)
+        {
+            return _prj.ForClientNodes(name);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForRemotes()
+        {
+            return _prj.ForRemotes();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForHost(IClusterNode node)
+        {
+            IgniteArgumentCheck.NotNull(node, "node");
+
+            return _prj.ForHost(node);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForRandom()
+        {
+            return _prj.ForRandom();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForOldest()
+        {
+            return _prj.ForOldest();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForYoungest()
+        {
+            return _prj.ForYoungest();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForDotNet()
+        {
+            return _prj.ForDotNet();
+        }
+
+        /** <inheritdoc /> */
+        public ICollection<IClusterNode> GetNodes()
+        {
+            return _prj.GetNodes();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterNode GetNode(Guid id)
+        {
+            return _prj.GetNode(id);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterNode GetNode()
+        {
+            return _prj.GetNode();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterMetrics GetMetrics()
+        {
+            return _prj.GetMetrics();
+        }
+
+        /** <inheritdoc /> */
+        public void Dispose()
+        {
+            Ignition.Stop(Name, true);
+        }
+
+        /// <summary>
+        /// Internal stop routine.
+        /// </summary>
+        /// <param name="cancel">Cancel flag.</param>
+        internal unsafe void Stop(bool cancel)
+        {
+            UU.IgnitionStop(_proc.Context, Name, cancel);
+
+            _cbs.Cleanup();
+
+            foreach (var bean in _lifecycleBeans)
+                bean.OnLifecycleEvent(LifecycleEventType.AfterNodeStop);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetCache<TK, TV>(string name)
+        {
+            return Cache<TK, TV>(UU.ProcessorCache(_proc, name));
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetOrCreateCache<TK, TV>(string name)
+        {
+            return Cache<TK, TV>(UU.ProcessorGetOrCreateCache(_proc, name));
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> CreateCache<TK, TV>(string name)
+        {
+            return Cache<TK, TV>(UU.ProcessorCreateCache(_proc, name));
+        }
+
+        /// <summary>
+        /// Gets cache from specified native cache object.
+        /// </summary>
+        /// <param name="nativeCache">Native cache.</param>
+        /// <param name="keepPortable">Portable flag.</param>
+        /// <returns>
+        /// New instance of cache wrapping specified native cache.
+        /// </returns>
+        public ICache<TK, TV> Cache<TK, TV>(IUnmanagedTarget nativeCache, bool keepPortable = false)
+        {
+            var cacheImpl = new CacheImpl<TK, TV>(this, nativeCache, _marsh, false, keepPortable, false, false);
+
+            return new CacheProxyImpl<TK, TV>(cacheImpl);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterNode GetLocalNode()
+        {
+            return _locNode ?? (_locNode = GetNodes().FirstOrDefault(x => x.IsLocal));
+        }
+
+        /** <inheritdoc /> */
+        public bool PingNode(Guid nodeId)
+        {
+            return _prj.PingNode(nodeId);
+        }
+
+        /** <inheritdoc /> */
+        public long TopologyVersion
+        {
+            get { return _prj.TopologyVersion; }
+        }
+
+        /** <inheritdoc /> */
+        public ICollection<IClusterNode> GetTopology(long ver)
+        {
+            return _prj.Topology(ver);
+        }
+
+        /** <inheritdoc /> */
+        public void ResetMetrics()
+        {
+            UU.ProjectionResetMetrics(_prj.Target);
+        }
+
+        /** <inheritdoc /> */
+        public IDataStreamer<TK, TV> GetDataStreamer<TK, TV>(string cacheName)
+        {
+            return new DataStreamerImpl<TK, TV>(UU.ProcessorDataStreamer(_proc, cacheName, false),
+                _marsh, cacheName, false);
+        }
+
+        /** <inheritdoc /> */
+        public IPortables GetPortables()
+        {
+            return _portables;
+        }
+
+        /** <inheritdoc /> */
+        public ICacheAffinity GetAffinity(string cacheName)
+        {
+            return new CacheAffinityImpl(UU.ProcessorAffinity(_proc, cacheName), _marsh, false, this);
+        }
+
+        /** <inheritdoc /> */
+
+        public ITransactions GetTransactions()
+        {
+            return _transactions.Value;
+        }
+
+        /** <inheritdoc /> */
+        public IMessaging GetMessaging()
+        {
+            return _prj.GetMessaging();
+        }
+
+        /** <inheritdoc /> */
+        public IEvents GetEvents()
+        {
+            return _prj.GetEvents();
+        }
+
+        /** <inheritdoc /> */
+        public IServices GetServices()
+        {
+            return _prj.GetServices();
+        }
+
+        /// <summary>
+        /// Gets internal projection.
+        /// </summary>
+        /// <returns>Projection.</returns>
+        internal ClusterGroupImpl ClusterGroup
+        {
+            get { return _prj; }
+        }
+
+        /// <summary>
+        /// Marshaller.
+        /// </summary>
+        internal PortableMarshaller Marshaller
+        {
+            get { return _marsh; }
+        }
+
+        /// <summary>
+        /// Configuration.
+        /// </summary>
+        internal IgniteConfiguration Configuration
+        {
+            get { return _cfg; }
+        }
+
+        /// <summary>
+        /// Put metadata to Grid.
+        /// </summary>
+        /// <param name="metas">Metadata.</param>
+        internal void PutMetadata(IDictionary<int, IPortableMetadata> metas)
+        {
+            _prj.PutMetadata(metas);
+        }
+
+        /** <inheritDoc /> */
+        public IPortableMetadata Metadata(int typeId)
+        {
+            return _prj.Metadata(typeId);
+        }
+
+        /// <summary>
+        /// Handle registry.
+        /// </summary>
+        public HandleRegistry HandleRegistry
+        {
+            get { return _cbs.HandleRegistry; }
+        }
+
+        /// <summary>
+        /// Updates the node information from stream.
+        /// </summary>
+        /// <param name="memPtr">Stream ptr.</param>
+        public void UpdateNodeInfo(long memPtr)
+        {
+            var stream = IgniteManager.Memory.Get(memPtr).Stream();
+
+            IPortableRawReader reader = Marshaller.StartUnmarshal(stream, false);
+
+            var node = new ClusterNodeImpl(reader);
+
+            node.Init(this);
+
+            _nodes[node.Id] = node;
+        }
+
+        /// <summary>
+        /// Gets the node from cache.
+        /// </summary>
+        /// <param name="id">Node id.</param>
+        /// <returns>Cached node.</returns>
+        public ClusterNodeImpl GetNode(Guid? id)
+        {
+            return id == null ? null : _nodes[id.Value];
+        }
+
+        /// <summary>
+        /// Gets the interop processor.
+        /// </summary>
+        internal IUnmanagedTarget InteropProcessor
+        {
+            get { return _proc; }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteConfigurationEx.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteConfigurationEx.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteConfigurationEx.cs
new file mode 100644
index 0000000..358e805
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteConfigurationEx.cs
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    /// <summary>
+    /// Internal extensions for IgniteConfiguration.
+    /// </summary>
+    internal class IgniteConfigurationEx : IgniteConfiguration
+    {
+        /// <summary>
+        /// Default constructor.
+        /// </summary>
+        public IgniteConfigurationEx()
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Copying constructor.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        public IgniteConfigurationEx(IgniteConfiguration cfg) : base(cfg)
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Copying constructor.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        public IgniteConfigurationEx(IgniteConfigurationEx cfg)
+            : this((IgniteConfiguration) cfg)
+        {
+            GridName = cfg.GridName;
+        }
+
+        /// <summary>
+        /// Grid name which is used if not provided in configuration file.
+        /// </summary>
+        public string GridName { get; set; }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
new file mode 100644
index 0000000..8fd8825
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteManager.cs
@@ -0,0 +1,490 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Diagnostics.CodeAnalysis;
+    using System.IO;
+    using System.Linq;
+    using System.Reflection;
+    using System.Runtime.InteropServices;
+    using System.Text;
+    using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Impl.Memory;
+    using Apache.Ignite.Core.Impl.Unmanaged;
+    using UU = Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils;
+
+    /// <summary>
+    /// Native interface manager.
+    /// </summary>
+    internal static unsafe class IgniteManager
+    {
+        /** Environment variable: IGNITE_HOME. */
+        internal const string EnvIgniteHome = "IGNITE_HOME";
+
+        /** Environment variable: whether to set test classpath or not. */
+        internal const string EnvIgniteNativeTestClasspath = "IGNITE_NATIVE_TEST_CLASSPATH";
+        
+        /** Classpath prefix. */
+        private const string ClasspathPrefix = "-Djava.class.path=";
+
+        /** Java Command line argument: Xms. Case sensitive. */
+        private const string CmdJvmMinMemJava = "-Xms";
+
+        /** Java Command line argument: Xmx. Case sensitive. */
+        private const string CmdJvmMaxMemJava = "-Xmx";
+
+        /** Monitor for DLL load synchronization. */
+        private static readonly object SyncRoot = new object();
+
+        /** First created context. */
+        private static void* _ctx;
+
+        /** Configuration used on JVM start. */
+        private static JvmConfiguration _jvmCfg;
+
+        /** Memory manager. */
+        private static PlatformMemoryManager _mem;
+
+        /// <summary>
+        /// Static initializer.
+        /// </summary>
+        static IgniteManager()
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Create JVM.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        /// <param name="cbs">Callbacks.</param>
+        /// <returns>Context.</returns>
+        internal static void* GetContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
+        {
+            lock (SyncRoot)
+            {
+                // 1. Warn about possible configuration inconsistency.
+                JvmConfiguration jvmCfg = JvmConfig(cfg);
+
+                if (!cfg.SuppressWarnings && _jvmCfg != null)
+                {
+                    if (!_jvmCfg.Equals(jvmCfg))
+                    {
+                        Console.WriteLine("Attempting to start Ignite node with different Java " +
+                            "configuration; current Java configuration will be ignored (consider " +
+                            "starting node in separate process) [oldConfig=" + _jvmCfg +
+                            ", newConfig=" + jvmCfg + ']');
+                    }
+                }
+
+                // 2. Create unmanaged pointer.
+                void* ctx = CreateJvm(cfg, cbs);
+
+                cbs.SetContext(ctx);
+
+                // 3. If this is the first JVM created, preserve it.
+                if (_ctx == null)
+                {
+                    _ctx = ctx;
+                    _jvmCfg = jvmCfg;
+                    _mem = new PlatformMemoryManager(1024);
+                }
+
+                return ctx;
+            }
+        }
+        
+        /// <summary>
+        /// Memory manager attached to currently running JVM.
+        /// </summary>
+        internal static PlatformMemoryManager Memory
+        {
+            get { return _mem; }
+        }
+
+        /// <summary>
+        /// Destroy JVM.
+        /// </summary>
+        public static void DestroyJvm()
+        {
+            lock (SyncRoot)
+            {
+                if (_ctx != null)
+                {
+                    UU.DestroyJvm(_ctx);
+
+                    _ctx = null;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Create JVM.
+        /// </summary>
+        /// <returns>JVM.</returns>
+        private static void* CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs)
+        {
+            var ggHome = GetIgniteHome(cfg);
+
+            var cp = CreateClasspath(ggHome, cfg, false);
+
+            var jvmOpts = GetMergedJvmOptions(cfg);
+            
+            var hasGgHome = !string.IsNullOrWhiteSpace(ggHome);
+
+            var opts = new sbyte*[1 + jvmOpts.Count + (hasGgHome ? 1 : 0)];
+
+            int idx = 0;
+                
+            opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp);
+
+            if (hasGgHome)
+                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged("-DIGNITE_HOME=" + ggHome);
+
+            foreach (string cfgOpt in jvmOpts)
+                opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt);
+
+            try
+            {
+                IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8);
+
+                fixed (sbyte** opts0 = opts)
+                {
+                    PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8);
+                }
+
+                try
+                {
+                    return UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer);
+                }
+                finally
+                {
+                    Marshal.FreeHGlobal(mem);
+                }
+            }
+            finally
+            {
+                foreach (sbyte* opt in opts)
+                    Marshal.FreeHGlobal((IntPtr)opt);
+            }
+        }
+
+        /// <summary>
+        /// Gets JvmOptions collection merged with individual properties (Min/Max mem, etc) according to priority.
+        /// </summary>
+        private static IList<string> GetMergedJvmOptions(IgniteConfiguration cfg)
+        {
+            var jvmOpts = cfg.JvmOptions == null ? new List<string>() : cfg.JvmOptions.ToList();
+
+            // JvmInitialMemoryMB / JvmMaxMemoryMB have lower priority than CMD_JVM_OPT
+            if (!jvmOpts.Any(opt => opt.StartsWith(CmdJvmMinMemJava, StringComparison.OrdinalIgnoreCase)))
+                jvmOpts.Add(string.Format("{0}{1}m", CmdJvmMinMemJava, cfg.JvmInitialMemoryMb));
+
+            if (!jvmOpts.Any(opt => opt.StartsWith(CmdJvmMaxMemJava, StringComparison.OrdinalIgnoreCase)))
+                jvmOpts.Add(string.Format("{0}{1}m", CmdJvmMaxMemJava, cfg.JvmMaxMemoryMb));
+
+            return jvmOpts;
+        }
+
+        /// <summary>
+        /// Create JVM configuration value object.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        /// <returns>JVM configuration.</returns>
+        private static JvmConfiguration JvmConfig(IgniteConfiguration cfg)
+        {
+            return new JvmConfiguration
+            {
+                Home = cfg.IgniteHome,
+                Dll = cfg.JvmDllPath,
+                Classpath = cfg.JvmClasspath,
+                Options = cfg.JvmOptions
+            };
+        }
+
+        /// <summary>
+        /// Append jars from the given path.
+        /// </summary>
+        /// <param name="path">Path.</param>
+        /// <param name="cpStr">Classpath string builder.</param>
+        private static void AppendJars(string path, StringBuilder cpStr)
+        {
+            if (Directory.Exists(path))
+            {
+                foreach (string jar in Directory.EnumerateFiles(path, "*.jar"))
+                {
+                    cpStr.Append(jar);
+                    cpStr.Append(';');
+                }
+            }
+        }
+
+        /// <summary>
+        /// Calculate Ignite home.
+        /// </summary>
+        /// <param name="cfg">Configuration.</param>
+        /// <returns></returns>
+        internal static string GetIgniteHome(IgniteConfiguration cfg)
+        {
+            var home = cfg == null ? null : cfg.IgniteHome;
+
+            if (string.IsNullOrWhiteSpace(home))
+                home = Environment.GetEnvironmentVariable(EnvIgniteHome);
+            else if (!IsIgniteHome(new DirectoryInfo(home)))
+                throw new IgniteException(string.Format("IgniteConfiguration.IgniteHome is not valid: '{0}'", home));
+
+            if (string.IsNullOrWhiteSpace(home))
+                home = ResolveIgniteHome();
+            else if (!IsIgniteHome(new DirectoryInfo(home)))
+                throw new IgniteException(string.Format("{0} is not valid: '{1}'", EnvIgniteHome, home));
+
+            return home;
+        }
+
+        /// <summary>
+        /// Automatically resolve Ignite home directory.
+        /// </summary>
+        /// <returns>Ignite home directory.</returns>
+        private static string ResolveIgniteHome()
+        {
+            var probeDirs = new[]
+            {
+                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
+                Directory.GetCurrentDirectory()
+            };
+
+            foreach (var probeDir in probeDirs.Where(x => !string.IsNullOrEmpty(x)))
+            {
+                var dir = new DirectoryInfo(probeDir);
+
+                while (dir != null)
+                {
+                    if (IsIgniteHome(dir))
+                        return dir.FullName;
+
+                    dir = dir.Parent;
+                }
+            }
+
+            return null;
+        }
+
+        /// <summary>
+        /// Determines whether specified dir looks like a Ignite home.
+        /// </summary>
+        /// <param name="dir">Directory.</param>
+        /// <returns>Value indicating whether specified dir looks like a Ignite home.</returns>
+        private static bool IsIgniteHome(DirectoryInfo dir)
+        {
+            return dir.Exists && dir.EnumerateDirectories().Count(x => x.Name == "examples" || x.Name == "bin") == 2;
+        }
+
+        /// <summary>
+        /// Creates classpath from the given configuration, or default classpath if given config is null.
+        /// </summary>
+        /// <param name="cfg">The configuration.</param>
+        /// <param name="forceTestClasspath">Append test directories even if <see cref="EnvIgniteNativeTestClasspath" /> is not set.</param>
+        /// <returns>
+        /// Classpath string.
+        /// </returns>
+        internal static string CreateClasspath(IgniteConfiguration cfg = null, bool forceTestClasspath = false)
+        {
+            return CreateClasspath(GetIgniteHome(cfg), cfg, forceTestClasspath);
+        }
+
+        /// <summary>
+        /// Creates classpath from the given configuration, or default classpath if given config is null.
+        /// </summary>
+        /// <param name="ggHome">The home dir.</param>
+        /// <param name="cfg">The configuration.</param>
+        /// <param name="forceTestClasspath">Append test directories even if
+        ///     <see cref="EnvIgniteNativeTestClasspath" /> is not set.</param>
+        /// <returns>
+        /// Classpath string.
+        /// </returns>
+        private static string CreateClasspath(string ggHome, IgniteConfiguration cfg, bool forceTestClasspath)
+        {
+            var cpStr = new StringBuilder();
+
+            if (cfg != null && cfg.JvmClasspath != null)
+            {
+                cpStr.Append(cfg.JvmClasspath);
+
+                if (!cfg.JvmClasspath.EndsWith(";"))
+                    cpStr.Append(';');
+            }
+
+            if (!string.IsNullOrWhiteSpace(ggHome))
+                AppendHomeClasspath(ggHome, forceTestClasspath, cpStr);
+
+            return ClasspathPrefix + cpStr;
+        }
+
+        /// <summary>
+        /// Appends classpath from home directory, if it is defined.
+        /// </summary>
+        /// <param name="ggHome">The home dir.</param>
+        /// <param name="forceTestClasspath">Append test directories even if
+        ///     <see cref="EnvIgniteNativeTestClasspath"/> is not set.</param>
+        /// <param name="cpStr">The classpath string.</param>
+        private static void AppendHomeClasspath(string ggHome, bool forceTestClasspath, StringBuilder cpStr)
+        {
+            // Append test directories (if needed) first, because otherwise build *.jar will be picked first.
+            if (forceTestClasspath || "true".Equals(Environment.GetEnvironmentVariable(EnvIgniteNativeTestClasspath)))
+            {
+                AppendTestClasses(ggHome + "\\examples", cpStr);
+                AppendTestClasses(ggHome + "\\modules", cpStr);
+            }
+
+            string ggLibs = ggHome + "\\libs";
+
+            AppendJars(ggLibs, cpStr);
+
+            if (Directory.Exists(ggLibs))
+            {
+                foreach (string dir in Directory.EnumerateDirectories(ggLibs))
+                {
+                    if (!dir.EndsWith("optional"))
+                        AppendJars(dir, cpStr);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Append target (compile) directories to classpath (for testing purposes only).
+        /// </summary>
+        /// <param name="path">Path</param>
+        /// <param name="cp">Classpath builder.</param>
+        private static void AppendTestClasses(string path, StringBuilder cp)
+        {
+            if (Directory.Exists(path))
+            {
+                AppendTestClasses0(path, cp);
+
+                foreach (string moduleDir in Directory.EnumerateDirectories(path))
+                    AppendTestClasses0(moduleDir, cp);
+            }
+        }
+
+        /// <summary>
+        /// Internal routine to append classes and jars from eploded directory.
+        /// </summary>
+        /// <param name="path">Path.</param>
+        /// <param name="cp">Classpath builder.</param>
+        private static void AppendTestClasses0(string path, StringBuilder cp)
+        {
+            if (path.EndsWith("rest-http", StringComparison.OrdinalIgnoreCase))
+                return;
+            
+            if (Directory.Exists(path + "\\target\\classes"))
+                cp.Append(path + "\\target\\classes;");
+
+            if (Directory.Exists(path + "\\target\\test-classes"))
+                cp.Append(path + "\\target\\test-classes;");
+
+            if (Directory.Exists(path + "\\target\\libs"))
+                AppendJars(path + "\\target\\libs", cp);
+        }
+
+        /// <summary>
+        /// JVM configuration.
+        /// </summary>
+        private class JvmConfiguration
+        {
+            /// <summary>
+            /// Gets or sets the home.
+            /// </summary>
+            public string Home { get; set; }
+
+            /// <summary>
+            /// Gets or sets the DLL.
+            /// </summary>
+            public string Dll { get; set; }
+
+            /// <summary>
+            /// Gets or sets the cp.
+            /// </summary>
+            public string Classpath { get; set; }
+
+            /// <summary>
+            /// Gets or sets the options.
+            /// </summary>
+            public ICollection<string> Options { get; set; }
+
+            /** <inheritDoc /> */
+            public override int GetHashCode()
+            {
+                return 0;
+            }
+
+            /** <inheritDoc /> */
+            [SuppressMessage("ReSharper", "FunctionComplexityOverflow")]
+            public override bool Equals(object obj)
+            {
+                JvmConfiguration other = obj as JvmConfiguration;
+
+                if (other == null)
+                    return false;
+
+                if (!string.Equals(Home, other.Home, StringComparison.OrdinalIgnoreCase))
+                    return false;
+
+                if (!string.Equals(Classpath, other.Classpath, StringComparison.OrdinalIgnoreCase))
+                    return false;
+
+                if (!string.Equals(Dll, other.Dll, StringComparison.OrdinalIgnoreCase))
+                    return false;
+
+                return (Options == null && other.Options == null) ||
+                       (Options != null && other.Options != null && Options.Count == other.Options.Count
+                        && !Options.Except(other.Options).Any());
+            }
+
+            /** <inheritDoc /> */
+            public override string ToString()
+            {
+                var sb = new StringBuilder("[IgniteHome=" + Home + ", JvmDllPath=" + Dll);
+
+                if (Options != null && Options.Count > 0)
+                {
+                    sb.Append(", JvmOptions=[");
+
+                    bool first = true;
+
+                    foreach (string opt in Options)
+                    {
+                        if (first)
+                            first = false;
+                        else
+                            sb.Append(", ");
+
+                        sb.Append(opt);
+                    }
+
+                    sb.Append(']');
+                }
+
+                sb.Append(", Classpath=" + Classpath + ']');
+
+                return sb.ToString();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
new file mode 100644
index 0000000..2e01a5b
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteProxy.cs
@@ -0,0 +1,333 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using System;
+    using System.Collections.Generic;
+    using Apache.Ignite.Core.Cache;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using Apache.Ignite.Core.Datastream;
+    using Apache.Ignite.Core.Events;
+    using Apache.Ignite.Core.Impl.Cluster;
+    using Apache.Ignite.Core.Impl.Portable;
+    using Apache.Ignite.Core.Messaging;
+    using Apache.Ignite.Core.Portable;
+    using Apache.Ignite.Core.Services;
+    using Apache.Ignite.Core.Transactions;
+
+    /// <summary>
+    /// Grid proxy with fake serialization.
+    /// </summary>
+    [Serializable]
+    internal class IgniteProxy : IIgnite, IClusterGroupEx, IPortableWriteAware, ICluster
+    {
+        /** */
+        [NonSerialized]
+        private readonly IIgnite _ignite;
+
+        /// <summary>
+        /// Default ctor for marshalling.
+        /// </summary>
+        public IgniteProxy()
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="ignite">Grid.</param>
+        public IgniteProxy(IIgnite ignite)
+        {
+            _ignite = ignite;
+        }
+
+        /** <inheritdoc /> */
+        public string Name
+        {
+            get { return _ignite.Name; }
+        }
+
+        /** <inheritdoc /> */
+
+        public ICluster GetCluster()
+        {
+            return this;
+        }
+
+        /** <inheritdoc /> */
+        public IIgnite Ignite
+        {
+            get { return this; }
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForLocal()
+        {
+            return _ignite.GetCluster().ForLocal();
+        }
+
+        /** <inheritdoc /> */
+        public ICompute GetCompute()
+        {
+            return _ignite.GetCompute();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodes(IEnumerable<IClusterNode> nodes)
+        {
+            return _ignite.GetCluster().ForNodes(nodes);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodes(params IClusterNode[] nodes)
+        {
+            return _ignite.GetCluster().ForNodes(nodes);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(IEnumerable<Guid> ids)
+        {
+            return _ignite.GetCluster().ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(ICollection<Guid> ids)
+        {
+            return _ignite.GetCluster().ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForNodeIds(params Guid[] ids)
+        {
+            return _ignite.GetCluster().ForNodeIds(ids);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForPredicate(Func<IClusterNode, bool> p)
+        {
+            return _ignite.GetCluster().ForPredicate(p);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForAttribute(string name, string val)
+        {
+            return _ignite.GetCluster().ForAttribute(name, val);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForCacheNodes(string name)
+        {
+            return _ignite.GetCluster().ForCacheNodes(name);
+        }
+        
+        /** <inheritdoc /> */
+        public IClusterGroup ForDataNodes(string name)
+        {
+            return _ignite.GetCluster().ForDataNodes(name);
+        }
+        
+        /** <inheritdoc /> */
+        public IClusterGroup ForClientNodes(string name)
+        {
+            return _ignite.GetCluster().ForClientNodes(name);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForRemotes()
+        {
+            return _ignite.GetCluster().ForRemotes();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForHost(IClusterNode node)
+        {
+            return _ignite.GetCluster().ForHost(node);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForRandom()
+        {
+            return _ignite.GetCluster().ForRandom();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForOldest()
+        {
+            return _ignite.GetCluster().ForOldest();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForYoungest()
+        {
+            return _ignite.GetCluster().ForYoungest();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterGroup ForDotNet()
+        {
+            return _ignite.GetCluster().ForDotNet();
+        }
+
+        /** <inheritdoc /> */
+        public ICollection<IClusterNode> GetNodes()
+        {
+            return _ignite.GetCluster().GetNodes();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterNode GetNode(Guid id)
+        {
+            return _ignite.GetCluster().GetNode(id);
+        }
+
+        /** <inheritdoc /> */
+        public IClusterNode GetNode()
+        {
+            return _ignite.GetCluster().GetNode();
+        }
+
+        /** <inheritdoc /> */
+        public IClusterMetrics GetMetrics()
+        {
+            return _ignite.GetCluster().GetMetrics();
+        }
+
+        /** <inheritdoc /> */
+        public void Dispose()
+        {
+            _ignite.Dispose();
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetCache<TK, TV>(string name)
+        {
+            return _ignite.GetCache<TK, TV>(name);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> GetOrCreateCache<TK, TV>(string name)
+        {
+            return _ignite.GetOrCreateCache<TK, TV>(name);
+        }
+
+        /** <inheritdoc /> */
+        public ICache<TK, TV> CreateCache<TK, TV>(string name)
+        {
+            return _ignite.CreateCache<TK, TV>(name);
+        }
+
+        /** <inheritdoc /> */
+
+        public IClusterNode GetLocalNode()
+        {
+            return _ignite.GetCluster().GetLocalNode();
+        }
+
+        /** <inheritdoc /> */
+        public bool PingNode(Guid nodeId)
+        {
+            return _ignite.GetCluster().PingNode(nodeId);
+        }
+
+        /** <inheritdoc /> */
+        public long TopologyVersion
+        {
+            get { return _ignite.GetCluster().TopologyVersion; }
+        }
+
+        /** <inheritdoc /> */
+        public ICollection<IClusterNode> GetTopology(long ver)
+        {
+            return _ignite.GetCluster().GetTopology(ver);
+        }
+
+        /** <inheritdoc /> */
+        public void ResetMetrics()
+        {
+            _ignite.GetCluster().ResetMetrics();
+        }
+
+        /** <inheritdoc /> */
+        public IDataStreamer<TK, TV> GetDataStreamer<TK, TV>(string cacheName)
+        {
+            return _ignite.GetDataStreamer<TK, TV>(cacheName);
+        }
+
+        /** <inheritdoc /> */
+        public IPortables GetPortables()
+        {
+            return _ignite.GetPortables();
+        }
+
+        /** <inheritdoc /> */
+        public ICacheAffinity GetAffinity(string name)
+        {
+            return _ignite.GetAffinity(name);
+        }
+
+        /** <inheritdoc /> */
+
+        public ITransactions GetTransactions()
+        {
+            return _ignite.GetTransactions();
+        }
+
+        /** <inheritdoc /> */
+        public IMessaging GetMessaging()
+        {
+            return _ignite.GetMessaging();
+        }
+
+        /** <inheritdoc /> */
+        public IEvents GetEvents()
+        {
+            return _ignite.GetEvents();
+        }
+
+        /** <inheritdoc /> */
+        public IServices GetServices()
+        {
+            return _ignite.GetServices();
+        }
+
+        /** <inheritdoc /> */
+        public void WritePortable(IPortableWriter writer)
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Target grid.
+        /// </summary>
+        internal IIgnite Target
+        {
+            get
+            {
+                return _ignite;
+            }
+        }
+
+        /** <inheritdoc /> */
+        public IPortableMetadata Metadata(int typeId)
+        {
+            return ((IClusterGroupEx)_ignite).Metadata(typeId);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
new file mode 100644
index 0000000..265fd0d
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -0,0 +1,438 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using System;
+    using System.Collections.Generic;
+    using System.IO;
+    using System.Linq;
+    using System.Reflection;
+    using System.Runtime.InteropServices;
+    using System.Text;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Common;
+    using Apache.Ignite.Core.Impl.Cluster;
+    using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Impl.Portable;
+    using Apache.Ignite.Core.Impl.Unmanaged;
+    using Apache.Ignite.Core.Portable;
+
+    /// <summary>
+    /// Native utility methods.
+    /// </summary>
+    internal static class IgniteUtils
+    {
+        /** Environment variable: JAVA_HOME. */
+        private const string EnvJavaHome = "JAVA_HOME";
+
+        /** Directory: jre. */
+        private const string DirJre = "jre";
+
+        /** Directory: bin. */
+        private const string DirBin = "bin";
+
+        /** Directory: server. */
+        private const string DirServer = "server";
+
+        /** File: jvm.dll. */
+        private const string FileJvmDll = "jvm.dll";
+
+        /** File: Ignite.Common.dll. */
+        internal const string FileIgniteJniDll = "ignite.common.dll";
+        
+        /** Prefix for temp directory names. */
+        private const string DirIgniteTmp = "Ignite_";
+        
+        /** Loaded. */
+        private static bool _loaded;        
+
+        /** Thread-local random. */
+        [ThreadStatic]
+        private static Random _rnd;
+
+        /// <summary>
+        /// Initializes the <see cref="IgniteUtils"/> class.
+        /// </summary>
+        static IgniteUtils()
+        {
+            TryCleanTempDirectories();
+        }
+
+        /// <summary>
+        /// Gets thread local random.
+        /// </summary>
+        /// <returns>Thread local random.</returns>
+        public static Random ThreadLocalRandom()
+        {
+            if (_rnd == null)
+                _rnd = new Random();
+
+            return _rnd;
+        }
+
+        /// <summary>
+        /// Returns shuffled list copy.
+        /// </summary>
+        /// <returns>Shuffled list copy.</returns>
+        public static IList<T> Shuffle<T>(IList<T> list)
+        {
+            int cnt = list.Count;
+
+            if (cnt > 1) {
+                List<T> res = new List<T>(list);
+
+                Random rnd = ThreadLocalRandom();
+
+                while (cnt > 1)
+                {
+                    cnt--;
+                    
+                    int idx = rnd.Next(cnt + 1);
+
+                    T val = res[idx];
+                    res[idx] = res[cnt];
+                    res[cnt] = val;
+                }
+
+                return res;
+            }
+            return list;
+        }
+
+        /// <summary>
+        /// Load JVM DLL if needed.
+        /// </summary>
+        /// <param name="configJvmDllPath">JVM DLL path from config.</param>
+        public static void LoadDlls(string configJvmDllPath)
+        {
+            if (_loaded) return;
+
+            // 1. Load JNI dll.
+            LoadJvmDll(configJvmDllPath);
+
+            // 2. Load GG JNI dll.
+            UnmanagedUtils.Initialize();
+
+            _loaded = true;
+        }
+
+        /// <summary>
+        /// Create new instance of specified class.
+        /// </summary>
+        /// <param name="assemblyName">Assembly name.</param>
+        /// <param name="clsName">Class name</param>
+        /// <returns>New Instance.</returns>
+        public static object CreateInstance(string assemblyName, string clsName)
+        {
+            IgniteArgumentCheck.NotNullOrEmpty(clsName, "clsName");
+
+            var type = new TypeResolver().ResolveType(clsName, assemblyName);
+
+            if (type == null)
+                throw new IgniteException("Failed to create class instance [assemblyName=" + assemblyName +
+                    ", className=" + clsName + ']');
+
+            return Activator.CreateInstance(type);
+        }
+
+        /// <summary>
+        /// Set properties on the object.
+        /// </summary>
+        /// <param name="target">Target object.</param>
+        /// <param name="props">Properties.</param>
+        public static void SetProperties(object target, IEnumerable<KeyValuePair<string, object>> props)
+        {
+            if (props == null)
+                return;
+
+            IgniteArgumentCheck.NotNull(target, "target");
+
+            Type typ = target.GetType();
+
+            foreach (KeyValuePair<string, object> prop in props)
+            {
+                PropertyInfo prop0 = typ.GetProperty(prop.Key, 
+                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+
+                if (prop0 == null)
+                    throw new IgniteException("Property is not found [type=" + typ.Name + 
+                        ", property=" + prop.Key + ']');
+
+                prop0.SetValue(target, prop.Value, null);
+            }
+        }
+
+        /// <summary>
+        /// Loads the JVM DLL.
+        /// </summary>
+        private static void LoadJvmDll(string configJvmDllPath)
+        {
+            var messages = new List<string>();
+            foreach (var dllPath in GetJvmDllPaths(configJvmDllPath))
+            {
+                var errCode = LoadDll(dllPath.Value, FileJvmDll);
+                if (errCode == 0)
+                    return;
+
+                messages.Add(string.Format("[option={0}, path={1}, errorCode={2}]", 
+                    dllPath.Key, dllPath.Value, errCode));
+
+                if (dllPath.Value == configJvmDllPath)
+                    break;  // if configJvmDllPath is specified and is invalid - do not try other options
+            }
+
+            if (!messages.Any())  // not loaded and no messages - everything was null
+                messages.Add(string.Format("Please specify IgniteConfiguration.JvmDllPath or {0}.", EnvJavaHome));
+
+            if (messages.Count == 1)
+                throw new IgniteException(string.Format("Failed to load {0} ({1})", FileJvmDll, messages[0]));
+
+            var combinedMessage = messages.Aggregate((x, y) => string.Format("{0}\n{1}", x, y));
+            throw new IgniteException(string.Format("Failed to load {0}:\n{1}", FileJvmDll, combinedMessage));
+        }
+
+        /// <summary>
+        /// Try loading DLLs first using file path, then using it's simple name.
+        /// </summary>
+        /// <param name="filePath"></param>
+        /// <param name="simpleName"></param>
+        /// <returns>Zero in case of success, error code in case of failure.</returns>
+        private static int LoadDll(string filePath, string simpleName)
+        {
+            int res = 0;
+
+            IntPtr ptr;
+
+            if (filePath != null)
+            {
+                ptr = NativeMethods.LoadLibrary(filePath);
+
+                if (ptr == IntPtr.Zero)
+                    res = Marshal.GetLastWin32Error();
+                else
+                    return res;
+            }
+
+            // Failed to load using file path, fallback to simple name.
+            ptr = NativeMethods.LoadLibrary(simpleName);
+
+            if (ptr == IntPtr.Zero)
+            {
+                // Preserve the first error code, if any.
+                if (res == 0)
+                    res = Marshal.GetLastWin32Error();
+            }
+            else
+                res = 0;
+
+            return res;
+        }
+
+        /// <summary>
+        /// Gets the JVM DLL paths in order of lookup priority.
+        /// </summary>
+        private static IEnumerable<KeyValuePair<string, string>> GetJvmDllPaths(string configJvmDllPath)
+        {
+            if (!string.IsNullOrEmpty(configJvmDllPath))
+                yield return new KeyValuePair<string, string>("IgniteConfiguration.JvmDllPath", configJvmDllPath);
+
+            var javaHomeDir = Environment.GetEnvironmentVariable(EnvJavaHome);
+
+            if (!string.IsNullOrEmpty(javaHomeDir))
+                yield return
+                    new KeyValuePair<string, string>(EnvJavaHome, GetJvmDllPath(Path.Combine(javaHomeDir, DirJre)));
+        }
+
+        /// <summary>
+        /// Gets the JVM DLL path from JRE dir.
+        /// </summary>
+        private static string GetJvmDllPath(string jreDir)
+        {
+            return Path.Combine(jreDir, DirBin, DirServer, FileJvmDll);
+        }
+
+        /// <summary>
+        /// Unpacks an embedded resource into a temporary folder and returns the full path of resulting file.
+        /// </summary>
+        /// <param name="resourceName">Resource name.</param>
+        /// <returns>Path to a temp file with an unpacked resource.</returns>
+        public static string UnpackEmbeddedResource(string resourceName)
+        {
+            var dllRes = Assembly.GetExecutingAssembly().GetManifestResourceNames()
+                .Single(x => x.EndsWith(resourceName, StringComparison.OrdinalIgnoreCase));
+
+            return WriteResourceToTempFile(dllRes, resourceName);
+        }
+
+        /// <summary>
+        /// Writes the resource to temporary file.
+        /// </summary>
+        /// <param name="resource">The resource.</param>
+        /// <param name="name">File name prefix</param>
+        /// <returns>Path to the resulting temp file.</returns>
+        private static string WriteResourceToTempFile(string resource, string name)
+        {
+            // Dll file name should not be changed, so we create a temp folder with random name instead.
+            var file = Path.Combine(GetTempDirectoryName(), name);
+
+            using (var src = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
+            using (var dest = File.OpenWrite(file))
+            {
+                // ReSharper disable once PossibleNullReferenceException
+                src.CopyTo(dest);
+
+                return file;
+            }
+        }
+
+        /// <summary>
+        /// Tries to clean temporary directories created with <see cref="GetTempDirectoryName"/>.
+        /// </summary>
+        private static void TryCleanTempDirectories()
+        {
+            foreach (var dir in Directory.GetDirectories(Path.GetTempPath(), DirIgniteTmp + "*"))
+            {
+                try
+                {
+                    Directory.Delete(dir, true);
+                }
+                catch (IOException)
+                {
+                    // Expected
+                }
+                catch (UnauthorizedAccessException)
+                {
+                    // Expected
+                }
+            }
+        }
+
+        /// <summary>
+        /// Creates a uniquely named, empty temporary directory on disk and returns the full path of that directory.
+        /// </summary>
+        /// <returns>The full path of the temporary directory.</returns>
+        private static string GetTempDirectoryName()
+        {
+            while (true)
+            {
+                var dir = Path.Combine(Path.GetTempPath(), DirIgniteTmp + Path.GetRandomFileName());
+
+                try
+                {
+                    return Directory.CreateDirectory(dir).FullName;
+                }
+                catch (IOException)
+                {
+                    // Expected
+                }
+                catch (UnauthorizedAccessException)
+                {
+                    // Expected
+                }
+            }
+        }
+
+        /// <summary>
+        /// Convert unmanaged char array to string.
+        /// </summary>
+        /// <param name="chars">Char array.</param>
+        /// <param name="charsLen">Char array length.</param>
+        /// <returns></returns>
+        public static unsafe string Utf8UnmanagedToString(sbyte* chars, int charsLen)
+        {
+            IntPtr ptr = new IntPtr(chars);
+
+            if (ptr == IntPtr.Zero)
+                return null;
+
+            byte[] arr = new byte[charsLen];
+
+            Marshal.Copy(ptr, arr, 0, arr.Length);
+
+            return Encoding.UTF8.GetString(arr);
+        }
+
+        /// <summary>
+        /// Convert string to unmanaged byte array.
+        /// </summary>
+        /// <param name="str">String.</param>
+        /// <returns>Unmanaged byte array.</returns>
+        public static unsafe sbyte* StringToUtf8Unmanaged(string str)
+        {
+            var ptr = IntPtr.Zero;
+
+            if (str != null)
+            {
+                byte[] strBytes = Encoding.UTF8.GetBytes(str);
+
+                ptr = Marshal.AllocHGlobal(strBytes.Length + 1);
+
+                Marshal.Copy(strBytes, 0, ptr, strBytes.Length);
+
+                *((byte*)ptr.ToPointer() + strBytes.Length) = 0; // NULL-terminator.
+            }
+            
+            return (sbyte*)ptr.ToPointer();
+        }
+
+        /// <summary>
+        /// Reads node collection from stream.
+        /// </summary>
+        /// <param name="reader">Reader.</param>
+        /// <param name="pred">The predicate.</param>
+        /// <returns> Nodes list or null. </returns>
+        public static List<IClusterNode> ReadNodes(IPortableRawReader reader, Func<ClusterNodeImpl, bool> pred = null)
+        {
+            var cnt = reader.ReadInt();
+
+            if (cnt < 0)
+                return null;
+
+            var res = new List<IClusterNode>(cnt);
+
+            var ignite = ((PortableReaderImpl)reader).Marshaller.Ignite;
+
+            if (pred == null)
+            {
+                for (var i = 0; i < cnt; i++)
+                    res.Add(ignite.GetNode(reader.ReadGuid()));
+            }
+            else
+            {
+                for (var i = 0; i < cnt; i++)
+                {
+                    var node = ignite.GetNode(reader.ReadGuid());
+                    
+                    if (pred(node))
+                        res.Add(node);
+                }
+            }
+
+            return res;
+        }
+
+        /// <summary>
+        /// Gets the asynchronous mode disabled exception.
+        /// </summary>
+        /// <returns>Asynchronous mode disabled exception.</returns>
+        public static InvalidOperationException GetAsyncModeDisabledException()
+        {
+            return new InvalidOperationException("Asynchronous mode is disabled");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/InteropExceptionHolder.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/InteropExceptionHolder.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/InteropExceptionHolder.cs
new file mode 100644
index 0000000..98d57da
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/InteropExceptionHolder.cs
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using System;
+    using System.Runtime.Serialization.Formatters.Binary;
+    using Apache.Ignite.Core.Impl.Portable;
+    using Apache.Ignite.Core.Impl.Portable.IO;
+    using Apache.Ignite.Core.Portable;
+
+    /// <summary>
+    /// Holder of exception which must be serialized to Java and then backwards to the native platform.
+    /// </summary>
+    internal class InteropExceptionHolder : IPortableMarshalAware
+    {
+        /** Initial exception. */
+        private Exception _err;
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        public InteropExceptionHolder()
+        {
+            // No-op.
+        }
+
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="err">Error.</param>
+        public InteropExceptionHolder(Exception err)
+        {
+            _err = err;
+        }
+
+        /// <summary>
+        /// Underlying exception.
+        /// </summary>
+        public Exception Error
+        {
+            get { return _err; }
+        }
+
+        /** <inheritDoc /> */
+        public void WritePortable(IPortableWriter writer)
+        {
+            var writer0 = (PortableWriterImpl) writer.RawWriter();
+
+            if (writer0.IsPortable(_err))
+            {
+                writer0.WriteBoolean(true);
+                writer0.WriteObject(_err);
+            }
+            else
+            {
+                writer0.WriteBoolean(false);
+
+                BinaryFormatter bf = new BinaryFormatter();
+
+                bf.Serialize(new PortableStreamAdapter(writer0.Stream), _err);
+            }
+        }
+
+        /** <inheritDoc /> */
+        public void ReadPortable(IPortableReader reader)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs
new file mode 100644
index 0000000..cce4ec5
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl
+{
+    using Apache.Ignite.Core.Impl.Resource;
+    using Apache.Ignite.Core.Lifecycle;
+
+    /// <summary>
+    /// Lifecycle bean holder.
+    /// </summary>
+    internal class LifecycleBeanHolder : ILifecycleBean
+    {
+        /** Target bean. */
+        private readonly ILifecycleBean _target;
+
+        /** Whether start event was invoked. */
+        private volatile bool _startEvt;
+        
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="target">Target bean.</param>
+        public LifecycleBeanHolder(ILifecycleBean target)
+        {
+            _target = target;
+        }
+
+        /** <inheritDoc /> */
+        public void OnLifecycleEvent(LifecycleEventType evt)
+        {
+            if (evt == LifecycleEventType.AfterNodeStart)
+                // This event cannot be propagated right away because at this point we
+                // do not have Ignite instance yet. So just schedule it.
+                _startEvt = true;
+            else
+                _target.OnLifecycleEvent(evt);
+        }
+
+        /// <summary>
+        /// Grid start callback.
+        /// </summary>
+        /// <param name="grid">Ignite instance.</param>
+        internal void OnStart(Ignite grid)
+        {
+            ResourceProcessor.Inject(_target, grid);
+
+            if (_startEvt)
+                _target.OnLifecycleEvent(LifecycleEventType.AfterNodeStart);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/IPlatformMemory.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/IPlatformMemory.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/IPlatformMemory.cs
new file mode 100644
index 0000000..93fd164
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/IPlatformMemory.cs
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Memory
+{
+    using System;
+
+    /// <summary>
+    /// Platform memory chunk.
+    /// </summary>
+    [CLSCompliant(false)]
+    public interface IPlatformMemory
+    {
+        /// <summary>
+        /// Gets stream for read/write operations on the given memory chunk.
+        /// </summary>
+        /// <returns></returns>
+        PlatformMemoryStream Stream();
+
+        /// <summary>
+        /// Cross-platform pointer.
+        /// </summary>
+        long Pointer { get; }
+
+        /// <summary>
+        /// Data pointer.
+        /// </summary>
+        long Data { get; }
+
+        /// <summary>
+        /// CalculateCapacity.
+        /// </summary>
+        int Capacity { get; }
+
+        /// <summary>
+        /// Length.
+        /// </summary>
+        int Length { get; set; }
+
+        /// <summary>
+        /// Reallocates memory chunk.
+        /// </summary>
+        /// <param name="cap">Minimum capacity.</param>
+        void Reallocate(int cap);
+
+        /// <summary>
+        /// Release memory.
+        /// </summary>
+        void Release();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropExternalMemory.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropExternalMemory.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropExternalMemory.cs
new file mode 100644
index 0000000..d356b5e
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropExternalMemory.cs
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Memory
+{
+    /// <summary>
+    /// Interop external memory chunk.
+    /// </summary>
+    internal class InteropExternalMemory : PlatformMemory
+    {
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="memPtr">Memory pointer.</param>
+        public InteropExternalMemory(long memPtr) : base(memPtr)
+        {
+            // No-op.
+        }
+
+        /** <inheritdoc /> */
+        public override void Reallocate(int cap)
+        {
+            InteropMemoryUtils.ReallocateExternal(Pointer, cap);
+        }
+
+        /** <inheritdoc /> */
+        public override void Release()
+        {
+            // Memory can only be released by native platform.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropMemoryUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropMemoryUtils.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropMemoryUtils.cs
new file mode 100644
index 0000000..485d3db
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/InteropMemoryUtils.cs
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Memory
+{
+    using Apache.Ignite.Core.Impl.Unmanaged;
+
+    /// <summary>
+    /// Utility methods for interop memory management.
+    /// </summary>
+    internal static class InteropMemoryUtils
+    {
+        /// <summary>
+        /// Re-allocate external memory chunk.
+        /// </summary>
+        /// <param name="memPtr">Memory pointer.</param>
+        /// <param name="cap">CalculateCapacity.</param>
+        /// <returns>New memory pointer.</returns>
+        public static void ReallocateExternal(long memPtr, int cap)
+        {
+            UnmanagedUtils.Reallocate(memPtr, cap);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f2eb16cd/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/PlatformBigEndianMemoryStream.cs
----------------------------------------------------------------------
diff --git a/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/PlatformBigEndianMemoryStream.cs b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/PlatformBigEndianMemoryStream.cs
new file mode 100644
index 0000000..33a0487
--- /dev/null
+++ b/modules/platform/dotnet/Apache.Ignite.Core/Impl/Memory/PlatformBigEndianMemoryStream.cs
@@ -0,0 +1,483 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Ignite.Core.Impl.Memory
+{
+    /// <summary>
+    /// Platform memory stream for big endian platforms.
+    /// </summary>
+    internal class PlatformBigEndianMemoryStream : PlatformMemoryStream
+    {
+        /// <summary>
+        /// Constructor.
+        /// </summary>
+        /// <param name="mem"></param>
+        public PlatformBigEndianMemoryStream(IPlatformMemory mem) : base(mem)
+        {
+            // No-op.
+        }
+
+        #region WRITE
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteShort(short val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(Len2);
+
+            byte* valPtr = (byte*)&val;
+
+            curPos[0] = valPtr[1];
+            curPos[1] = valPtr[0];
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteShortArray(short[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift2);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                short val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteChar(char val)
+        {
+            WriteShort(*(short*)(&val));
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteCharArray(char[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift2);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                char val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteInt(int val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(Len4);
+
+            byte* valPtr = (byte*)&val;
+
+            curPos[0] = valPtr[3];
+            curPos[1] = valPtr[2];
+            curPos[2] = valPtr[1];
+            curPos[3] = valPtr[0];
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteInt(int writePos, int val)
+        {
+            EnsureWriteCapacity(writePos + 4);
+
+            byte* curPos = Data + writePos;
+
+            byte* valPtr = (byte*)&val;
+
+            curPos[0] = valPtr[3];
+            curPos[1] = valPtr[2];
+            curPos[2] = valPtr[1];
+            curPos[3] = valPtr[0];
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteIntArray(int[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift4);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                int val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[3];
+                *curPos++ = valPtr[2];
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteLong(long val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(Len8);
+
+            byte* valPtr = (byte*)&val;
+
+            curPos[0] = valPtr[7];
+            curPos[1] = valPtr[6];
+            curPos[2] = valPtr[5];
+            curPos[3] = valPtr[4];
+            curPos[4] = valPtr[3];
+            curPos[5] = valPtr[2];
+            curPos[6] = valPtr[1];
+            curPos[7] = valPtr[0];
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteLongArray(long[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift8);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                long val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[7];
+                *curPos++ = valPtr[6];
+                *curPos++ = valPtr[5];
+                *curPos++ = valPtr[4];
+                *curPos++ = valPtr[3];
+                *curPos++ = valPtr[2];
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteFloat(float val)
+        {
+            WriteInt(*(int*)(&val));
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteFloatArray(float[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift4);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                float val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[3];
+                *curPos++ = valPtr[2];
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteDouble(double val)
+        {
+            WriteLong(*(long*)(&val));
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe void WriteDoubleArray(double[] val)
+        {
+            byte* curPos = Data + EnsureWriteCapacityAndShift(val.Length << Shift8);
+
+            for (int i = 0; i < val.Length; i++)
+            {
+                double val0 = val[i];
+
+                byte* valPtr = (byte*)&(val0);
+
+                *curPos++ = valPtr[7];
+                *curPos++ = valPtr[6];
+                *curPos++ = valPtr[5];
+                *curPos++ = valPtr[4];
+                *curPos++ = valPtr[3];
+                *curPos++ = valPtr[2];
+                *curPos++ = valPtr[1];
+                *curPos++ = valPtr[0];
+            }
+        }
+
+        #endregion
+
+        #region READ
+
+        /** <inheritDoc /> */
+        public override unsafe short ReadShort()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len2);
+
+            short val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe short[] ReadShortArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift2);
+
+            short[] res = new short[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                short val;
+
+                byte* valPtr = (byte*)&val;
+
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe char ReadChar()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len2);
+
+            char val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe char[] ReadCharArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift2);
+
+            char[] res = new char[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                char val;
+
+                byte* valPtr = (byte*)&val;
+
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe int ReadInt()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len4);
+
+            int val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[3] = *(Data + curPos++);
+            valPtr[2] = *(Data + curPos++);
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe int[] ReadIntArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift4);
+
+            int[] res = new int[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                int val;
+
+                byte* valPtr = (byte*)&val;
+
+                valPtr[3] = *(Data + curPos++);
+                valPtr[2] = *(Data + curPos++);
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe long ReadLong()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len8);
+
+            long val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[7] = *(Data + curPos++);
+            valPtr[6] = *(Data + curPos++);
+            valPtr[5] = *(Data + curPos++);
+            valPtr[4] = *(Data + curPos++);
+            valPtr[3] = *(Data + curPos++);
+            valPtr[2] = *(Data + curPos++);
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+
+        public override unsafe long[] ReadLongArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift8);
+
+            long[] res = new long[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                long val;
+
+                byte* valPtr = (byte*) &val;
+
+                valPtr[7] = *(Data + curPos++);
+                valPtr[6] = *(Data + curPos++);
+                valPtr[5] = *(Data + curPos++);
+                valPtr[4] = *(Data + curPos++);
+                valPtr[3] = *(Data + curPos++);
+                valPtr[2] = *(Data + curPos++);
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe float ReadFloat()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len4);
+
+            float val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[3] = *(Data + curPos++);
+            valPtr[2] = *(Data + curPos++);
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe float[] ReadFloatArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift4);
+
+            float[] res = new float[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                float val;
+
+                byte* valPtr = (byte*)&val;
+
+                valPtr[3] = *(Data + curPos++);
+                valPtr[2] = *(Data + curPos++);
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe double ReadDouble()
+        {
+            int curPos = EnsureReadCapacityAndShift(Len8);
+
+            double val;
+
+            byte* valPtr = (byte*)&val;
+
+            valPtr[7] = *(Data + curPos++);
+            valPtr[6] = *(Data + curPos++);
+            valPtr[5] = *(Data + curPos++);
+            valPtr[4] = *(Data + curPos++);
+            valPtr[3] = *(Data + curPos++);
+            valPtr[2] = *(Data + curPos++);
+            valPtr[1] = *(Data + curPos++);
+            valPtr[0] = *(Data + curPos);
+
+            return val;
+        }
+
+        /** <inheritDoc /> */
+        public override unsafe double[] ReadDoubleArray(int len)
+        {
+            int curPos = EnsureReadCapacityAndShift(len << Shift8);
+
+            double[] res = new double[len];
+
+            for (int i = 0; i < len; i++)
+            {
+                double val;
+
+                byte* valPtr = (byte*)&val;
+
+                valPtr[7] = *(Data + curPos++);
+                valPtr[6] = *(Data + curPos++);
+                valPtr[5] = *(Data + curPos++);
+                valPtr[4] = *(Data + curPos++);
+                valPtr[3] = *(Data + curPos++);
+                valPtr[2] = *(Data + curPos++);
+                valPtr[1] = *(Data + curPos++);
+                valPtr[0] = *(Data + curPos++);
+
+                res[i] = val;
+            }
+
+            return res;
+        }
+
+        #endregion
+    }
+}