Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientSocket" /> class.
        /// </summary>
        /// <param name="clientConfiguration">The client configuration.</param>
        /// <param name="endPoint">The end point to connect to.</param>
        /// <param name="host">The host name (required for SSL).</param>
        /// <param name="version">Protocol version.</param>
        /// <param name="topVerCallback">Topology version update callback.</param>
        /// <param name="marshaller">Marshaller.</param>
        public ClientSocket(IgniteClientConfiguration clientConfiguration, EndPoint endPoint, string host,
                            ClientProtocolVersion?version, Action <AffinityTopologyVersion> topVerCallback,
                            Marshaller marshaller)
        {
            Debug.Assert(clientConfiguration != null);
            Debug.Assert(endPoint != null);
            Debug.Assert(!string.IsNullOrWhiteSpace(host));
            Debug.Assert(topVerCallback != null);
            Debug.Assert(marshaller != null);

            _topVerCallback = topVerCallback;
            _marsh          = marshaller;
            _timeout        = clientConfiguration.SocketTimeout;
            _logger         = (clientConfiguration.Logger ?? NoopLogger.Instance).GetLogger(GetType());

            _socket = Connect(clientConfiguration, endPoint, _logger);
            _stream = GetSocketStream(_socket, clientConfiguration, host);

            ServerVersion = version ?? CurrentProtocolVersion;

            Validate(clientConfiguration);

            _features = Handshake(clientConfiguration, ServerVersion);

            // Check periodically if any request has timed out.
            if (_timeout > TimeSpan.Zero)
            {
                // Minimum Socket timeout is 500ms.
                _timeoutCheckTimer = new Timer(CheckTimeouts, null, _timeout, TimeSpan.FromMilliseconds(500));
            }

            // Continuously and asynchronously wait for data from server.
            // TaskCreationOptions.LongRunning actually means a new thread.
            TaskRunner.Run(WaitForMessages, TaskCreationOptions.LongRunning);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="ClientContextBase"/> class.
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="marshaller">Marshaller.</param>
        /// <param name="features">Features supported by this request.</param>
        protected ClientContextBase(IBinaryStream stream, Marshaller marshaller, ClientFeatures features)
        {
            Debug.Assert(stream != null);
            Debug.Assert(marshaller != null);

            _stream     = stream;
            _marshaller = marshaller;
            _features   = features;
        }
Пример #3
0
        /// <summary>
        /// Performs feature checks when a new default connection is established.
        /// </summary>
        private void OnNewDefaultConnection()
        {
            if (_config.EnablePartitionAwareness && !_socket.Features.HasOp(ClientOp.CachePartitions))
            {
                _config.EnablePartitionAwareness = false;

                _logger.Warn("Partition awareness has been disabled: server protocol version {0} " +
                             "is lower than required {1}",
                             _socket.ServerVersion,
                             ClientFeatures.GetMinVersion(ClientOp.CachePartitions)
                             );
            }

            if (!_socket.Features.HasFeature(ClientBitmaskFeature.ClusterGroupGetNodesEndpoints))
            {
                _enableDiscovery = false;

                _logger.Warn("Automatic server node discovery is not supported by the server");
            }
        }
        /// <summary>
        /// Performs initial checks when the first connection to the cluster has been established.
        /// </summary>
        private void OnFirstConnect()
        {
            if (_config.EnablePartitionAwareness && !_socket.Features.HasOp(ClientOp.CachePartitions))
            {
                _config.EnablePartitionAwareness = false;

                _logger.Warn("Partition awareness has been disabled: server protocol version {0} " +
                             "is lower than required {1}",
                             _socket.ServerVersion,
                             ClientFeatures.GetMinVersion(ClientOp.CachePartitions)
                             );
            }

            if (!_socket.Features.HasFeature(ClientBitmaskFeature.ClusterGroupGetNodesEndpoints))
            {
                _enableDiscovery = false;

                _logger.Warn("Automatic server node discovery is not supported by the server");
            }

            if (_socket.Features.HasFeature(ClientBitmaskFeature.BinaryConfiguration))
            {
                var serverBinaryCfg = _socket.DoOutInOp(
                    ClientOp.BinaryConfigurationGet,
                    ctx => { },
                    ctx => new BinaryConfigurationClientInternal(ctx.Reader.Stream));

                _logger.Debug("Server binary configuration retrieved: " + serverBinaryCfg);

                if (serverBinaryCfg.CompactFooter && !_marsh.CompactFooter)
                {
                    // Changing from full to compact is not safe: some clients do not support compact footers.
                    // Log information, but don't change the configuration.
                    _logger.Info("BinaryConfiguration.CompactFooter is true on the server, but false on the client." +
                                 "Consider enabling this setting to reduce cache entry size.");
                }

                if (!serverBinaryCfg.CompactFooter && _marsh.CompactFooter)
                {
                    // Changing from compact to full footer is safe, do it automatically.
                    _marsh.CompactFooter = false;

                    if (_config.BinaryConfiguration == null)
                    {
                        _config.BinaryConfiguration = new BinaryConfiguration();
                    }

                    _config.BinaryConfiguration.CompactFooter = false;

                    _logger.Info("BinaryConfiguration.CompactFooter set to false on client " +
                                 "according to server configuration.");
                }

                var localNameMapperMode = GetLocalNameMapperMode();

                if (localNameMapperMode != serverBinaryCfg.NameMapperMode)
                {
                    _logger.Warn("Binary name mapper mismatch: local={0}, server={1}",
                                 localNameMapperMode, serverBinaryCfg.NameMapperMode);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of <see cref="ClientRequestContext"/> class.
        /// </summary>
        /// <param name="stream">Stream.</param>
        /// <param name="marshaller">Marshaller.</param>
        /// <param name="features">Features supported by this request.</param>
        public ClientRequestContext(IBinaryStream stream, Marshaller marshaller, ClientFeatures features)
            : base(stream, marshaller, features)

        {
            // No-op.
        }