Repository: ignite Updated Branches: refs/heads/ignite-5896 4241f5d2c -> 50f6bdcb2
http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs index d78276d..90de835 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/Marshaller.cs @@ -185,6 +185,7 @@ namespace Apache.Ignite.Core.Impl.Binary if (ignite != null && metas != null && metas.Count > 0) { ignite.BinaryProcessor.PutBinaryTypes(metas); + OnBinaryTypesSent(metas); } } @@ -300,8 +301,9 @@ namespace Apache.Ignite.Core.Impl.Binary if (Ignite != null) { - ICollection<BinaryType> metas = new[] {new BinaryType(desc, this)}; + var metas = new[] {new BinaryType(desc, this)}; Ignite.BinaryProcessor.PutBinaryTypes(metas); + OnBinaryTypesSent(metas); } } @@ -349,7 +351,7 @@ namespace Apache.Ignite.Core.Impl.Binary /// Callback invoked when metadata has been sent to the server and acknowledged by it. /// </summary> /// <param name="newMetas">Binary types.</param> - public void OnBinaryTypesSent(IEnumerable<BinaryType> newMetas) + private void OnBinaryTypesSent(IEnumerable<BinaryType> newMetas) { foreach (var meta in newMetas) { http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheClient.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheClient.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheClient.cs index b8bf95e..b4fae54 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheClient.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/CacheClient.cs @@ -23,7 +23,6 @@ namespace Apache.Ignite.Core.Impl.Cache using System.Diagnostics; using System.IO; using System.Threading.Tasks; - using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cache; using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Cache.Expiry; @@ -34,36 +33,38 @@ namespace Apache.Ignite.Core.Impl.Cache using Apache.Ignite.Core.Impl.Binary.IO; using Apache.Ignite.Core.Impl.Client; using Apache.Ignite.Core.Impl.Common; + using BinaryWriter = Apache.Ignite.Core.Impl.Binary.BinaryWriter; /// <summary> /// Client cache implementation. /// </summary> internal class CacheClient<TK, TV> : ICache<TK, TV> { - /** Socket. */ - private readonly ClientSocket _socket; - /** Cache name. */ private readonly string _name; /** Cache id. */ private readonly int _id; - /** Marshaller */ - private readonly Marshaller _marsh = BinaryUtils.Marshaller; + /** Ignite. */ + private readonly IgniteClient _ignite; + + /** Marshaller. */ + private readonly Marshaller _marsh; /// <summary> /// Initializes a new instance of the <see cref="CacheClient{TK, TV}" /> class. /// </summary> - /// <param name="socket">The socket.</param> + /// <param name="ignite">Ignite.</param> /// <param name="name">Cache name.</param> - public CacheClient(ClientSocket socket, string name) + public CacheClient(IgniteClient ignite, string name) { - Debug.Assert(socket != null); + Debug.Assert(ignite != null); Debug.Assert(name != null); - _socket = socket; _name = name; + _ignite = ignite; + _marsh = _ignite.Marshaller; _id = BinaryUtils.GetCacheId(name); } @@ -202,19 +203,15 @@ namespace Apache.Ignite.Core.Impl.Cache /** <inheritDoc /> */ public TV this[TK key] { - get - { - return Get(key); - } - set - { - Put(key, value); - } + get { return Get(key); } + set { Put(key, value); } } /** <inheritDoc /> */ public TV Get(TK key) { + IgniteArgumentCheck.NotNull(key, "key"); + return DoOutInOp(ClientOp.CacheGet, w => w.WriteObject(key), UnmarshalNotNull<TV>); } @@ -254,7 +251,11 @@ namespace Apache.Ignite.Core.Impl.Cache IgniteArgumentCheck.NotNull(key, "key"); IgniteArgumentCheck.NotNull(val, "val"); - throw new NotImplementedException(); + DoOutOp(ClientOp.CachePut, w => + { + w.WriteObjectDetached(key); + w.WriteObjectDetached(val); + }); } /** <inheritDoc /> */ @@ -596,22 +597,34 @@ namespace Apache.Ignite.Core.Impl.Cache /// <summary> /// Does the out in op. /// </summary> - private T DoOutInOp<T>(ClientOp opId, Action<IBinaryRawWriter> writeAction, + private T DoOutInOp<T>(ClientOp opId, Action<BinaryWriter> writeAction, Func<IBinaryStream, T> readFunc) { - return _socket.DoOutInOp(opId, stream => + return _ignite.Socket.DoOutInOp(opId, stream => { stream.WriteInt(_id); stream.WriteByte(0); // Flags (skipStore, etc). if (writeAction != null) { - writeAction(_marsh.StartMarshal(stream)); + var writer = _marsh.StartMarshal(stream); + + writeAction(writer); + + _marsh.FinishMarshal(writer); } }, readFunc); } /// <summary> + /// Does the out op. + /// </summary> + private void DoOutOp(ClientOp opId, Action<BinaryWriter> writeAction) + { + DoOutInOp<object>(opId, writeAction, null); + } + + /// <summary> /// Unmarshals the value, throwing an exception for nulls. /// </summary> private T UnmarshalNotNull<T>(IBinaryStream stream) http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientOp.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientOp.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientOp.cs index 0039085..d2efdcb 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientOp.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientOp.cs @@ -22,6 +22,11 @@ namespace Apache.Ignite.Core.Impl.Client /// </summary> internal enum ClientOp : short { - CacheGet = 1 + CacheGet = 1, + GetBinaryTypeName = 2, + GetBinaryTypeSchema = 3, + CachePut = 4, + RegisterBinaryTypeName = 5, + PutBinaryTypes = 6 } } http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientProtocolVersion.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientProtocolVersion.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientProtocolVersion.cs index d06b97d..bfdf5a3 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientProtocolVersion.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientProtocolVersion.cs @@ -87,6 +87,18 @@ namespace Apache.Ignite.Core.Impl.Client } /** <inheritdoc /> */ + public static bool operator ==(ClientProtocolVersion left, ClientProtocolVersion right) + { + return left.Equals(right); + } + + /** <inheritdoc /> */ + public static bool operator !=(ClientProtocolVersion left, ClientProtocolVersion right) + { + return !left.Equals(right); + } + + /** <inheritdoc /> */ public override int GetHashCode() { unchecked http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs index 886e454..b9cfb04 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/ClientSocket.cs @@ -20,6 +20,7 @@ namespace Apache.Ignite.Core.Impl.Client using System; using System.Collections.Generic; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using System.Net; using System.Net.Sockets; using System.Threading; @@ -73,7 +74,6 @@ namespace Apache.Ignite.Core.Impl.Client var resBytes = SendReceive(_socket, stream => { stream.WriteShort((short) opId); - stream.WriteByte(0); // Flags (compression, etc) stream.WriteInt(requestId); if (writeAction != null) @@ -87,8 +87,6 @@ namespace Apache.Ignite.Core.Impl.Client var resRequestId = stream.ReadInt(); Debug.Assert(requestId == resRequestId); - stream.ReadByte(); // Flags - if (readFunc != null) { return readFunc(stream); @@ -246,6 +244,8 @@ namespace Apache.Ignite.Core.Impl.Client /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> + [SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", + Justification = "There is no finalizer.")] public void Dispose() { _socket.Dispose(); http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/IgniteClient.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/IgniteClient.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/IgniteClient.cs index 4afcdee..d0157f0 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/IgniteClient.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Client/IgniteClient.cs @@ -20,6 +20,7 @@ namespace Apache.Ignite.Core.Impl.Client using System; using System.Collections.Generic; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using Apache.Ignite.Core.Binary; using Apache.Ignite.Core.Cache; using Apache.Ignite.Core.Cache.Configuration; @@ -29,8 +30,12 @@ namespace Apache.Ignite.Core.Impl.Client using Apache.Ignite.Core.Datastream; using Apache.Ignite.Core.DataStructures; using Apache.Ignite.Core.Events; + using Apache.Ignite.Core.Impl.Binary; using Apache.Ignite.Core.Impl.Cache; + using Apache.Ignite.Core.Impl.Cluster; using Apache.Ignite.Core.Impl.Common; + using Apache.Ignite.Core.Impl.Handle; + using Apache.Ignite.Core.Impl.Plugin; using Apache.Ignite.Core.Lifecycle; using Apache.Ignite.Core.Log; using Apache.Ignite.Core.Messaging; @@ -41,11 +46,17 @@ namespace Apache.Ignite.Core.Impl.Client /// <summary> /// Thin client implementation /// </summary> - internal class IgniteClient : IIgnite + internal class IgniteClient : IIgniteInternal { /** Socket. */ private readonly ClientSocket _socket; + /** Marshaller. */ + private readonly Marshaller _marsh; + + /** Binary processor. */ + private readonly IBinaryProcessor _binProc; + /// <summary> /// Initializes a new instance of the <see cref="IgniteClient"/> class. /// </summary> @@ -55,9 +66,26 @@ namespace Apache.Ignite.Core.Impl.Client Debug.Assert(clientConfiguration != null); _socket = new ClientSocket(clientConfiguration); + + _marsh = new Marshaller(clientConfiguration.BinaryConfiguration) + { + Ignite = this + }; + + _binProc = clientConfiguration.BinaryProcessor ?? new BinaryProcessorClient(_socket); + } + + /// <summary> + /// Gets the socket. + /// </summary> + public ClientSocket Socket + { + get { return _socket; } } /** <inheritDoc /> */ + [SuppressMessage("Microsoft.Usage", "CA1816:CallGCSuppressFinalizeCorrectly", + Justification = "There is no finalizer.")] public void Dispose() { _socket.Dispose(); @@ -66,19 +94,19 @@ namespace Apache.Ignite.Core.Impl.Client /** <inheritDoc /> */ public string Name { - get { throw new NotImplementedException(); } + get { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public ICluster GetCluster() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICompute GetCompute() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ @@ -86,215 +114,265 @@ namespace Apache.Ignite.Core.Impl.Client { IgniteArgumentCheck.NotNull(name, "name"); - return new CacheClient<TK, TV>(_socket, name); + return new CacheClient<TK, TV>(this, name); } /** <inheritDoc /> */ public ICache<TK, TV> GetOrCreateCache<TK, TV>(string name) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> GetOrCreateCache<TK, TV>(CacheConfiguration configuration, NearCacheConfiguration nearConfiguration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> CreateCache<TK, TV>(string name) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> CreateCache<TK, TV>(CacheConfiguration configuration, NearCacheConfiguration nearConfiguration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public void DestroyCache(string name) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IDataStreamer<TK, TV> GetDataStreamer<TK, TV>(string cacheName) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IBinary GetBinary() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICacheAffinity GetAffinity(string name) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ITransactions GetTransactions() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IMessaging GetMessaging() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IEvents GetEvents() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IServices GetServices() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IAtomicLong GetAtomicLong(string name, long initialValue, bool create) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IAtomicSequence GetAtomicSequence(string name, long initialValue, bool create) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IAtomicReference<T> GetAtomicReference<T>(string name, T initialValue, bool create) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IgniteConfiguration GetConfiguration() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> CreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICache<TK, TV> GetOrCreateNearCache<TK, TV>(string name, NearCacheConfiguration configuration) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICollection<string> GetCacheNames() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ILogger Logger { - get { throw new NotImplementedException(); } + get { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public event EventHandler Stopping { - add { throw new NotImplementedException(); } - remove { throw new NotImplementedException(); } + add { throw GetClientNotSupportedException(); } + remove { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public event EventHandler Stopped { - add { throw new NotImplementedException(); } - remove { throw new NotImplementedException(); } + add { throw GetClientNotSupportedException(); } + remove { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public event EventHandler ClientDisconnected { - add { throw new NotImplementedException(); } - remove { throw new NotImplementedException(); } + add { throw GetClientNotSupportedException(); } + remove { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public event EventHandler<ClientReconnectEventArgs> ClientReconnected { - add { throw new NotImplementedException(); } - remove { throw new NotImplementedException(); } + add { throw GetClientNotSupportedException(); } + remove { throw GetClientNotSupportedException(); } } /** <inheritDoc /> */ public T GetPlugin<T>(string name) where T : class { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public void ResetLostPartitions(IEnumerable<string> cacheNames) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public void ResetLostPartitions(params string[] cacheNames) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public ICollection<IMemoryMetrics> GetMemoryMetrics() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IMemoryMetrics GetMemoryMetrics(string memoryPolicyName) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public void SetActive(bool isActive) { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public bool IsActive() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); } /** <inheritDoc /> */ public IPersistentStoreMetrics GetPersistentStoreMetrics() { - throw new NotImplementedException(); + throw GetClientNotSupportedException(); + } + + /** <inheritDoc /> */ + public IBinaryProcessor BinaryProcessor + { + get { return _binProc; } + } + + /** <inheritDoc /> */ + public IgniteConfiguration Configuration + { + get { throw GetClientNotSupportedException(); } + } + + /** <inheritDoc /> */ + public HandleRegistry HandleRegistry + { + get { throw GetClientNotSupportedException(); } + } + + /** <inheritDoc /> */ + public ClusterNodeImpl GetNode(Guid? id) + { + throw GetClientNotSupportedException(); + } + + /** <inheritDoc /> */ + public Marshaller Marshaller + { + get { return _marsh; } + } + + /** <inheritDoc /> */ + public PluginProcessor PluginProcessor + { + get { throw GetClientNotSupportedException(); } + } + + /** <inheritDoc /> */ + public IDataStreamer<TK, TV> GetDataStreamer<TK, TV>(string cacheName, bool keepBinary) + { + throw GetClientNotSupportedException(); + } + + /// <summary> + /// Gets the client not supported exception. + /// </summary> + private static NotSupportedException GetClientNotSupportedException() + { + return new NotSupportedException("Operation is not supported in thin client mode."); } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IIgniteInternal.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IIgniteInternal.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IIgniteInternal.cs index 789633b..5fd6faa 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IIgniteInternal.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IIgniteInternal.cs @@ -32,7 +32,7 @@ namespace Apache.Ignite.Core.Impl /// <summary> /// Gets the binary processor. /// </summary> - BinaryProcessor BinaryProcessor { get; } + IBinaryProcessor BinaryProcessor { get; } /// <summary> /// Configuration. http://git-wip-us.apache.org/repos/asf/ignite/blob/50f6bdcb/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs index 630aa85..59dfe2a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs @@ -804,7 +804,7 @@ namespace Apache.Ignite.Core.Impl /// <summary> /// Gets the binary processor. /// </summary> - public BinaryProcessor BinaryProcessor + public IBinaryProcessor BinaryProcessor { get { return _binaryProc; } }
