Пример #1
0
        internal Connection(Broker container, OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs, PerfStatsCollector perfStatsCollector, ResponseIntegrator rspIntegraotr, string bindIP, string cacheName)
        {
            _container          = container;
            _commandRecieved    = commandRecieved;
            _serverLost         = serverLost;
            _logger             = logs;
            _responseIntegrator = rspIntegraotr;
            _cacheId            = cacheName;
            _perfStatsColl      = perfStatsCollector;

            SetBindIP(bindIP);
            if (System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"] != null)
            {
                _nagglingEnabled = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"]);
            }

            //read the naggling size from app.config and covert it to bytes.
            if (System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"] != null)
            {
                _nagglingSize = 1024 * Convert.ToInt64(System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"]);
            }

            if (System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"] != null)
            {
                _supportDualSocket = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"]);
            }
        }
Пример #2
0
        public void ReadMesagge()
        {
            new Task(() =>
            {
                try
                {
                    string arg;
                    stream = this.client.GetStream();
                    BinaryReader reader = new BinaryReader(stream);

                    while (client.Connected)
                    {
                        arg = reader.ReadString();
                        CommandRecievedEventArgs e = JsonConvert.DeserializeObject <CommandRecievedEventArgs>(arg);
                        //if (e.CommandID == (int)CommandEnum.ExitCommand)
                        //{
                        //    // Client want to exit.
                        //    break;
                        //}
                        OnCommandRecieved?.Invoke(this, e);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    client.Close();
                }
            }).Start();
        }
Пример #3
0
        private void Initialize(Broker container, OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs,
                                PerfStatsCollector perfStatsCollector, ResponseIntegrator rspIntegraotr, string bindIP, string cacheName)
        {
            _commandRecieved            = null;
            _serverLost                 = null;
            _isConnected                = true;
            _primaryClient              = null;
            _secondaryClient            = null;
            _ipAddress                  = string.Empty;
            _intendedRecipientIPAddress = string.Empty;
            _port                    = 0;
            _connectionMutex         = new object();
            _connectionStatusLatch   = new Latch(ConnectionStatus.Disconnected);
            s_receiveBufferSize      = 2048000;
            _processID               = System.Diagnostics.Process.GetCurrentProcess().Id;
            _primaryReceiveThread    = null;
            _secondaryReceiveThread  = null;
            _notificationsRegistered = false;
            _isReconnecting          = false;
            _forcedDisconnect        = false;
            _nagglingEnabled         = false;
            _nagglingSize            = 5 * 100 * 1024; //500k
            _supportDualSocket       = false;
            _syncLock                = new object();
            _perfStatsColl           = null;
            _socketSelectionMutex    = new object();
            _usePrimary              = true;
            _optimized               = false;
            _isIdle                  = false;
            _container               = container;
            _commandRecieved         = commandRecieved;
            _serverLost              = serverLost;
            _logger                  = logs;
            _responseIntegrator      = rspIntegraotr;
            _cacheId                 = cacheName;
            _perfStatsColl           = perfStatsCollector;

            SetBindIP(bindIP);
            if (System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"] != null)
            {
                _nagglingEnabled =
                    Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"]);
            }

            //read the naggling size from app.config and covert it to bytes.
            if (System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"] != null)
            {
                _nagglingSize =
                    1024 * Convert.ToInt64(System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"]);
            }

            if (System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"] != null)
            {
                _supportDualSocket =
                    Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"]);
            }
        }
Пример #4
0
        /// <summary>
        /// it transfers the existing connection to a new connection without changing the object container
        /// </summary>
        /// <param name="container"></param>
        /// <param name="commandRecieved"></param>
        /// <param name="serverLost"></param>
        /// <param name="logs"></param>
        /// <param name="perfStatsCollector"></param>
        /// <param name="rspIntegraotr"></param>
        /// <param name="bindIP"></param>
        /// <param name="cacheName"></param>
        /// <param name="ipAddress"></param>
        /// <param name="cachePort"></param>
        /// <returns></returns>
        public bool SwitchTo(Broker container, OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs,
                             PerfStatsCollector perfStatsCollector, ResponseIntegrator rspIntegraotr, string bindIP, string cacheName,
                             IPAddress ipAddress, int cachePort)
        {
            int oldPort = Port;

            Initialize(container, commandRecieved, serverLost, logs, perfStatsCollector, rspIntegraotr, bindIP,
                       cacheName);
            if (this.Connect(Address, cachePort))
            {
                _hostPort = cachePort;
                this.Port = oldPort;
                return(true);
            }

            return(false);
        }
Пример #5
0
        private Task HandleConnectionAsync(TcpClient client)
        {
            return(Task.Run(async() =>
            {
                using (NetworkStream stream = client.GetStream())
                {
                    bool running = true;
                    BinaryReader reader = new BinaryReader(stream);
                    string msg = string.Empty;
                    SetConfigsAndLogs(client);

                    while (running)
                    {
                        try
                        {
                            msg = reader.ReadString();
                            Console.WriteLine("msg: {0}", msg);
                            CommandRecievedEventArgs cmd = JsonConvert.DeserializeObject <CommandRecievedEventArgs>(msg);
                            Console.WriteLine("command is: {0}", cmd);
                            // client exit
                            if (cmd.CommandID == (int)CommandEnum.ExitCommand)
                            {
                                client.Close();
                                clients.Remove(client);
                                Console.WriteLine("Client removed");
                                break;
                            }
                            OnCommandRecieved?.Invoke(this, cmd);
                        }
                        catch (Exception ex)
                        {
                            running = false;
                            clients.Remove(client);
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Console.WriteLine("closing client");
                }
            }));
        }
Пример #6
0
        internal Connection(OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs, PerfStatsCollector perfStatsCollector,ResponseIntegrator rspIntegraotr, string bindIP)
        {
            _commandRecieved = commandRecieved;
            _serverLost = serverLost;
            _logger = logs;
            _responseIntegrator = rspIntegraotr;

            _perfStatsColl = perfStatsCollector;

            SetBindIP(bindIP);
            if (System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"] != null)
                _nagglingEnabled = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableNaggling"]);

            //read the naggling size from app.config and covert it to bytes.
            if (System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"] != null)
                _nagglingSize = 1024 * Convert.ToInt64(System.Configuration.ConfigurationSettings.AppSettings["NagglingSize"]);

            if (System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"] != null)
                _supportDualSocket = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["EnableDualSockets"]);
        }
Пример #7
0
 internal Connection(Broker container, OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs,
                     PerfStatsCollector perfStatsCollector, ResponseIntegrator rspIntegraotr, string bindIP, string cacheName)
 {
     Initialize(container, commandRecieved, serverLost, logs, perfStatsCollector, rspIntegraotr, bindIP,
                cacheName);
 }
Пример #8
0
 internal Connection(Broker container, OnCommandRecieved commandRecieved, OnServerLost serverLost, Logs logs, StatisticsCounter perfStatsCollector, ResponseIntegrator rspIntegraotr, string bindIP, string cacheName)
 {
     _connectionStatusLatch = new Latch(ConnectionStatus.Disconnected);
     Initialize(container, commandRecieved, serverLost, logs, perfStatsCollector, rspIntegraotr, bindIP, cacheName);
 }
Пример #9
0
        private Broker(RemoteCache cache, bool importHashMap, PerfStatsCollector2 perfStatsColl,
            CacheInitParams initParams)
        {
            _bulkEventCallback = new WaitCallback(RaiseBulkEvent);
            this._clientConfig = new ClientConfiguration(cache.CacheId, initParams);
            this._cache = cache;
            this._balanceNode = _clientConfig.BalanceNodes;
            this._importHashmap = _clientConfig.ImportHashmap;

            this._operationTimeout = _clientConfig.Timeout;
            this._connectionTimeout = _clientConfig.ConnectionTimeout;
            this._connectionRetries = _clientConfig.ConnectionRetries;
            this._retryInterval = _clientConfig.RetryInterval;

            this._retryConnnectionDelay = _clientConfig.RetryConnectionDelay;
            this._retryConnectionDelayInMinutes = Convert.ToDouble(_retryConnnectionDelay)/60000;
                //Conversion to minutes from milliseconds;
            _perfStatsColl2 = perfStatsColl;

            int pid = System.Diagnostics.Process.GetCurrentProcess().Id;
            string instanceName = "Client." + cache.CacheId + "." + pid;

            if (_perfStatsColl == null || !_perfStatsColl.InstanceName.Equals(instanceName))
            {
                _perfStatsColl = new PerfStatsCollector(instanceName, 0);
            }

            this._commandReieved = new OnCommandRecieved(CommandReceived);
            this._serverLost = new OnServerLost(ServerLost);
            this._requestTable = Hashtable.Synchronized(new Hashtable(10000, 0.75f));
            this._pool = new ConnectionPool();
        }