Esempio n. 1
0
        /// <summary>
        /// Reads a single single response from the stream and processes it.
        /// </summary>
        /// <param name="stream"></param>
        private void ProcessResponse(byte[] cmdBytes)
        {
            Response response;

            using (Stream tempStream = new ClusteredMemoryStream(cmdBytes))
            {
                response = ProtoBuf.Serializer.Deserialize <Response>(tempStream);
            }

            CommandResponse cmdRespose = null;

            if (response != null)
            {
                cmdRespose         = new CommandResponse(false, new Address());
                cmdRespose.CacheId = _cacheId;
                cmdRespose.Result  = response;
            }

            if (_perfStatsColl.IsEnabled)
            {
                _perfStatsColl.IncrementClientResponsesPerSecStats(1);
            }

            if (cmdRespose != null)
            {
                _container.ProcessResponse(cmdRespose, _serverAddress);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Reads a single single response from the stream and processes it.
        /// </summary>
        /// <param name="stream"></param>
        private void ProcessResponse(Stream stream)
        {
            Response response;

            //Reading  a response's header...
            byte[] cmdSzBytes = new byte[CmdSizeHolderBytesCount];
            stream.Read(cmdSzBytes, 0, CmdSizeHolderBytesCount);
            int commandSize = HelperFxn.ToInt32(cmdSzBytes, 0, CmdSizeHolderBytesCount);

            byte[] cmdBytes = new byte[commandSize];
            stream.Read(cmdBytes, 0, commandSize);

            using (Stream tempStream = new ClusteredMemoryStream(cmdBytes))
            {
                response = ProtoBuf.Serializer.Deserialize <Response>(tempStream);
            }

            CommandResponse cmdRespose = null;

            if (response != null)
            {
                cmdRespose         = new CommandResponse(false, new Address());
                cmdRespose.CacheId = _cacheId;
                cmdRespose.Result  = response;
            }

            if (_perfStatsColl.IsEnabled)
            {
                _perfStatsColl.IncrementClientResponsesPerSecStats(1);
            }

            if (cmdRespose != null)
            {
                _container.ProcessResponse(cmdRespose, _serverAddress);
            }
        }
Esempio n. 3
0
        private void RecieveThread(object clientSocket)

        {
            while (true)
            {
                try
                {
                    CommandResponse response = null;
                    Socket          client   = null;


                    if (clientSocket != null && clientSocket is Socket)
                    {
                        client = clientSocket as Socket;
                    }

                    response = RecieveCommandResponse(client);

                    if (_perfStatsColl.IsEnabled)
                    {
                        _perfStatsColl.IncrementClientResponsesPerSecStats(1);
                    }

                    string serverAddress = ((IPEndPoint)client.RemoteEndPoint).Address.ToString();

                    if (response != null)
                    {
                        _commandRecieved(response, _serverAddress);
                    }
                }
                catch (ConnectionException ce)
                {
                    if (_forcedDisconnect)
                    {
                        if (_logger.IsErrorLogsEnabled)
                        {
                            _logger.NCacheLog.Error("Connection.ReceivedThread", "Connection with server lost gracefully");
                        }
                    }
                    else
                    if (_logger.IsErrorLogsEnabled)
                    {
                        _logger.NCacheLog.Error("Connection.ReceivedThread", "An established connection with the server is lost. Error:" + ce.ToString());
                    }

                    if (!_forcedDisconnect)
                    {
                        _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                    }
                    _primaryReceiveThread = null;
                    _serverLost(_serverAddress, _forcedDisconnect);
                    break;
                }
                catch (ThreadAbortException te)
                {
                    if (AppDomain.CurrentDomain.IsFinalizingForUnload())
                    {
                        return;
                    }
                    if (_forcedDisconnect)
                    {
                        if (_logger.IsErrorLogsEnabled)
                        {
                            _logger.NCacheLog.Error("Connection.ReceivedThread", "Connection with server lost gracefully");
                            _logger.NCacheLog.Flush();
                        }
                    }
                    if (!_forcedDisconnect)
                    {
                        _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                    }
                    _serverLost(_serverAddress, _forcedDisconnect);
                    break;
                }
                catch (ThreadInterruptedException tae)
                {
                    if (AppDomain.CurrentDomain.IsFinalizingForUnload())
                    {
                        return;
                    }
                    if (_forcedDisconnect)
                    {
                        if (_logger.IsErrorLogsEnabled)
                        {
                            _logger.NCacheLog.Error("Connection.ReceivedThread", "Connection with server lost gracefully");
                            _logger.NCacheLog.Flush();
                        }
                    }
                    if (!_forcedDisconnect)
                    {
                        _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                    }
                    _primaryReceiveThread = null;
                    _serverLost(_serverAddress, _forcedDisconnect);
                    break;
                }
                catch (Exception e)
                {
                    if (_logger.IsErrorLogsEnabled)
                    {
                        _logger.NCacheLog.Error("Connection.ReceivedThread", e.ToString());
                        _logger.NCacheLog.Flush();
                    }
                    if (!_forcedDisconnect)
                    {
                        _connectionStatusLatch.SetStatusBit(ConnectionStatus.Disconnected, ConnectionStatus.Connected);
                    }
                    _serverLost(_serverAddress, _forcedDisconnect);
                }
            }
        }