Esempio n. 1
0
 /// <summary>
 /// Creates a consumer with the given key, secret and status.
 /// </summary>
 /// <param name="key">The consumer key</param>
 /// <param name="secret">The consumer secret</param>
 /// <param name="friendlyName">The consumer's friendly name</param>
 /// <param name="status">The status of the consumer</param>
 public OAuthConsumer(string key, string secret, string friendlyName, ConsumerStatus status)
 {
     this.Key          = key;
     this.Secret       = secret;
     this.FriendlyName = friendlyName;
     this.Status       = status;
 }
Esempio n. 2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ConsumersHealthCheck" /> class.
 /// </summary>
 /// <param name="service">
 ///     The <see cref="IConsumersHealthCheckService" /> implementation to be used to check the consumers.
 /// </param>
 /// <param name="minHealthyStatus">
 ///     The minimum <see cref="ConsumerStatus" /> a consumer must have to be considered healthy.
 /// </param>
 public ConsumersHealthCheck(
     IConsumersHealthCheckService service,
     ConsumerStatus minHealthyStatus)
 {
     _service          = service;
     _minHealthyStatus = minHealthyStatus;
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a consumer with the given key, secret and status.
 /// </summary>
 /// <param name="key">The consumer key</param>
 /// <param name="secret">The consumer secret</param>
 /// <param name="friendlyName">The consumer's friendly name</param>
 /// <param name="status">The status of the consumer</param>
 public OAuthConsumer(string key, string secret, string friendlyName, ConsumerStatus status)
 {
     this.Key = key;
     this.Secret = secret;
     this.FriendlyName = friendlyName;
     this.Status = status;
 }
Esempio n. 4
0
 private static bool IsDisconnected(
     IConsumer consumer,
     ConsumerStatus minStatus,
     TimeSpan gracePeriod) =>
 consumer.StatusInfo.Status < minStatus &&
 (gracePeriod == TimeSpan.Zero ||
  consumer.StatusInfo.History.Count == 0 ||
  GracePeriodElapsed(consumer, gracePeriod));
Esempio n. 5
0
 private static IEnumerable <IConsumer> GetDisconnectedConsumers(
     IBroker broker,
     ConsumerStatus minStatus,
     TimeSpan gracePeriod,
     Func <IConsumerEndpoint, bool>?endpointsFilter) =>
 broker.Consumers.Where(
     consumer => IsToBeTested(consumer.Endpoint, endpointsFilter) &&
     IsDisconnected(consumer, minStatus, gracePeriod));
        public override void StartParser()
        {
            try
            {
                int  noOfBytes = 0;
                bool go        = true;

                do
                {
                    lock (this)
                    {
                        if (_inputDataStream.Lenght == 0 && this.State != ParserState.ReadyToDispatch)
                        {
                            this.Alive = false;
                            return;
                        }
                    }

                    switch (this.State)
                    {
                    case ParserState.Ready:
                        noOfBytes       = _inputDataStream.Read(_rawData, _rawDataOffset, 24 - _rawDataOffset);
                        _rawDataOffset += noOfBytes;
                        if (_rawDataOffset == 24)
                        {
                            _rawDataOffset = 0;
                            this.Parse();
                        }
                        break;

                    case ParserState.WaitingForData:
                        noOfBytes       = _inputDataStream.Read(_rawData, _rawDataOffset, this.CommandDataSize - _rawDataOffset);
                        _rawDataOffset += noOfBytes;
                        if (_rawDataOffset == this.CommandDataSize)
                        {
                            _rawDataOffset = 0;
                            this.Build();
                        }
                        break;

                    case ParserState.ReadyToDispatch:

                        _logManager.Debug("BinaryProtocolParser", _command.Opcode + " command recieved.");
                        ConsumerStatus executionMgrStatus = _commandConsumer.RegisterCommand(_command);    //this.RegisterForExecution(_command);
                        this.State = ParserState.Ready;
                        go         = executionMgrStatus == ConsumerStatus.Running;
                        break;
                    }
                } while (go);
            }
            catch (Exception e)
            {
                _logManager.Fatal("BinaryProtocolParser", "Exception occured while parsing text command. " + e.Message);
                TcpNetworkGateway.DisposeClient(_memTcpClient);
                return;
            }
            this.Dispatch();
        }
Esempio n. 7
0
        public OAuthConsumer(string key, string secret, ConsumerStatus status)
        {
            if (String.IsNullOrEmpty(key))
                throw new ArgumentNullException("key");
            if (String.IsNullOrEmpty(secret))
                throw new ArgumentNullException("secret");

            this.key = key;
            this.status = status;
            this.secret = secret;
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ConsumersHealthCheck" /> class.
 /// </summary>
 /// <param name="service">
 ///     The <see cref="IConsumersHealthCheckService" /> implementation to be used to check the consumers.
 /// </param>
 /// <param name="minHealthyStatus">
 ///     The minimum <see cref="ConsumerStatus" /> a consumer must have to be considered healthy.
 /// </param>
 /// <param name="gracePeriod">
 ///     The grace period to observe after each status change before a consumer is considered unhealthy.
 /// </param>
 /// <param name="endpointsFilter">
 ///     An optional filter to be applied to the endpoints to be tested.
 /// </param>
 public ConsumersHealthCheck(
     IConsumersHealthCheckService service,
     ConsumerStatus minHealthyStatus,
     TimeSpan gracePeriod,
     Func <IConsumerEndpoint, bool>?endpointsFilter)
 {
     _service          = service;
     _minHealthyStatus = minHealthyStatus;
     _gracePeriod      = gracePeriod;
     _endpointsFilter  = endpointsFilter;
 }
Esempio n. 9
0
        public OAuthConsumer(string key, string secret, ConsumerStatus status)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }
            if (String.IsNullOrEmpty(secret))
            {
                throw new ArgumentNullException("secret");
            }

            this.key    = key;
            this.status = status;
            this.secret = secret;
        }
Esempio n. 10
0
        /// <inheritdoc cref="IConsumersHealthCheckService.GetDisconnectedConsumersAsync" />
        public Task <IReadOnlyCollection <IConsumer> > GetDisconnectedConsumersAsync(ConsumerStatus minStatus)
        {
            // The check is skipped when the application is shutting down, because all consumers will be
            // disconnected and since the shutdown could take a while we don't want to report the application
            // as unhealthy.
            if (_applicationIsStopping)
            {
                return(Task.FromResult((IReadOnlyCollection <IConsumer>)Array.Empty <IConsumer>()));
            }

            IReadOnlyCollection <IConsumer> disconnectedConsumers =
                _brokerCollection.SelectMany(
                    broker => broker.Consumers.Where(consumer => consumer.StatusInfo.Status < minStatus))
                .ToList();

            return(Task.FromResult(disconnectedConsumers));
        }
Esempio n. 11
0
        public virtual void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }
            _status = ConsumerStatus.Disposing;

            //NOTE: Wait all current running tasks to finish and after that dispose the objects
            DateTime timeOut = DateTime.Now.AddSeconds(Global.ConsumerDisposeTimeoutInSeconds);

            while (MessageInProgressCount() > 0 && DateTime.Now <= timeOut)
            {
                _watcher.InfoFormat("Wait for {0} messages in progress", MessageInProgressCount());
                Thread.Sleep(1000);
            }
            _status = ConsumerStatus.Disposed;
            _pool.Dispose();
            CloseQueue();
        }
Esempio n. 12
0
        /// <inheritdoc cref="IConsumersHealthCheckService.GetDisconnectedConsumersAsync" />
        public Task <IReadOnlyCollection <IConsumer> > GetDisconnectedConsumersAsync(
            ConsumerStatus minStatus,
            TimeSpan gracePeriod,
            Func <IConsumerEndpoint, bool>?endpointsFilter)
        {
            // The check is skipped when the application is shutting down, because all consumers will be
            // disconnected and since the shutdown could take a while we don't want to report the application
            // as unhealthy.
            if (_applicationIsStopping)
            {
                return(Task.FromResult((IReadOnlyCollection <IConsumer>)Array.Empty <IConsumer>()));
            }

            IReadOnlyCollection <IConsumer> disconnectedConsumers =
                _brokerCollection
                .SelectMany(
                    broker => GetDisconnectedConsumers(broker, minStatus, gracePeriod, endpointsFilter))
                .ToList();

            return(Task.FromResult(disconnectedConsumers));
        }
Esempio n. 13
0
 public void ChangeStatus(ConsumerStatus newStatus)
 {
     statusChanged = status != newStatus;
     status        = newStatus;
 }
Esempio n. 14
0
        public void StartSequentialExecution()
        {
            bool go = false;

            do
            {
                AbstractCommand command;
                lock (this)
                {
                    command = _commandsQueue.Dequeue();
                }
                try
                {
                    _logManager.Debug("SequentialExecutionManager", " Executing command : " + command.Opcode);
                    if (command.ErrorMessage == null)
                    {
                        command.Execute(_cacheProvider);
                    }
                    else
                    {
                        _logManager.Debug("SequentialExecutionManager", "\tCannot execute command: " + command.Opcode + "  Error:" + command.ErrorMessage);
                    }
                }
                catch (Alachisoft.NCache.Integrations.Memcached.Provider.Exceptions.InvalidArgumentsException e)
                {
                    _logManager.Error("SequentialExecutionManager.StartSequentialExecution()", "\tError while executing command. CommandType = " + command.Opcode.ToString() + "  " + e.Message);
                    command.ExceptionOccured = true;
                    command.ErrorMessage     = e.Message;
                }
                catch (Alachisoft.NCache.Integrations.Memcached.Provider.Exceptions.CacheRuntimeException e)
                {
                    _logManager.Error("SequentialExecutionManager.StartSequentialExecution()", "\tError while executing command. CommandType = " + command.Opcode.ToString() + "  " + e.Message);
                    command.ExceptionOccured = true;
                    command.ErrorMessage     = e.Message;
                }

                ConsumerStatus responseMgrStatus = _commandConsumer.RegisterCommand(command);

                lock (this)
                {
                    go = (responseMgrStatus == ConsumerStatus.Running) && _commandsQueue.Count > 0;
                }
            } while (go);


            lock (this)
            {
                if (_commandsQueue.Count > 0)
                {
                    ThreadPool.ExecuteTask(this);
                }
                else
                {
                    _alive = false;
                }
            }

            if (_commandConsumer != null)
            {
                _commandConsumer.Start();
            }
        }
Esempio n. 15
0
        public virtual void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }
            _status = ConsumerStatus.Disposing;

            //NOTE: Wait all current running tasks to finish and after that dispose the objects
            DateTime timeOut = DateTime.Now.AddSeconds(Global.ConsumerDisposeTimeoutInSeconds);

            while (MessageInProgressCount() > 0 && DateTime.Now <= timeOut)
            {
                _watcher.InfoFormat("Wait for {0} messages in progress", MessageInProgressCount());
                Thread.Sleep(1000);
            }
            _status = ConsumerStatus.Disposed;
            _pool.Dispose();
            CloseQueue();
        }
 public ConsumerStatusChange(ConsumerStatus status)
     : this(status, DateTime.UtcNow)
 {
 }
 public ConsumerStatusChange(ConsumerStatus status, DateTime timestamp)
 {
     Status    = status;
     Timestamp = timestamp;
 }
Esempio n. 18
0
 public void ChangeStatus(ConsumerStatus newStatus)
 {
     statusChanged = status != newStatus;
     status = newStatus;
 }
Esempio n. 19
0
        public override void StartParser()
        {
            try
            {
                string command   = null;
                int    noOfBytes = 0;
                bool   go        = true;

                do
                {
                    lock (this)
                    {
                        if (_inputDataStream.Lenght == 0 && this.State != ParserState.ReadyToDispatch)
                        {
                            this.Alive = false;
                            return;
                        }
                    }

                    switch (this.State)
                    {
                    case ParserState.Ready:
                        noOfBytes       = _inputDataStream.Read(_rawData, _rawDataOffset, 1);
                        _rawDataOffset += noOfBytes;

                        if (_rawDataOffset > 1 && (char)_rawData[_rawDataOffset - 2] == '\r' && (char)_rawData[_rawDataOffset - 1] == '\n')
                        {
                            command = MemcachedEncoding.BinaryConverter.GetString(_rawData, 0, (_rawDataOffset - 2));
                            this.Parse(command);
                            _rawDataOffset = 0;
                        }
                        if (_rawDataOffset == _rawData.Length)
                        {
                            byte[] newBuffer = new byte[_rawData.Length * 2];
                            Buffer.BlockCopy(_rawData, 0, newBuffer, 0, _rawData.Length);
                            _rawData = newBuffer;
                        }
                        if (_rawDataOffset > MemConfiguration.MaximumCommandLength)
                        {
                            TcpNetworkGateway.DisposeClient(_memTcpClient);
                            return;
                        }
                        break;

                    case ParserState.WaitingForData:
                        noOfBytes       = _inputDataStream.Read(_rawData, _rawDataOffset, this.CommandDataSize + 2 - _rawDataOffset);
                        _rawDataOffset += noOfBytes;

                        if (_rawDataOffset == this.CommandDataSize + 2)
                        {
                            _rawDataOffset = 0;
                            this.Build(_rawData);
                        }
                        break;

                    case ParserState.ReadyToDispatch:
                        _logManager.Debug("TextProtocolParser", _command.Opcode + " command recieved.");
                        ConsumerStatus executionMgrStatus = _commandConsumer.RegisterCommand(_command);
                        this.State = ParserState.Ready;
                        go         = executionMgrStatus == ConsumerStatus.Running;
                        break;
                    }
                } while (go);
            }
            catch (Exception e)
            {
                _logManager.Fatal("TextProtocolParser", "Exception occured while parsing text command. " + e.Message);
                TcpNetworkGateway.DisposeClient(_memTcpClient);
                return;
            }
            this.Dispatch();
        }
Esempio n. 20
0
 public ConsumerStatusChange(ConsumerStatus status)
 {
     Status    = status;
     Timestamp = DateTime.Now;
 }
Esempio n. 21
0
 public FakeConsumer(string key, string secret, ConsumerStatus status)
 {
     this.key    = key;
     this.status = status;
     this.secret = secret;
 }
Esempio n. 22
0
 public FakeConsumer(string key, string secret, ConsumerStatus status)
 {
     this.key = key;
     this.status = status;
     this.secret = secret;
 }
Esempio n. 23
0
 private void ChangeStatus(ConsumerStatus status)
 {
     Status = status;
     _history.Add(new ConsumerStatusChange(status));
 }