Beispiel #1
0
        private void HousekeepConnections(object notUsed)
        {
            // calls are accumulative, not discrete
            if (Interlocked.Decrement(ref _housekeepCallsPart1) > 0)
            {
                return;
            }

            try
            {
                DateTimeOffset dtCommenced  = DateTimeOffset.Now;
                int            activeCount  = 0;
                var            expiredConns = new List <IConnection>();
                foreach (IConnection connection in _connectionIndex.GetValues())
                {
                    bool removeConnection = false;
                    if (connection.HasFaulted)
                    {
                        removeConnection = true;
                        Logger.LogDebug("Connection: '{0}' faulted ({1})", connection.ClientId, connection.ReplyAddress);
                    }
                    if (connection.HasExpired)
                    {
                        removeConnection = true;
                        Logger.LogDebug("Connection: '{0}' expired ({1})", connection.ClientId, connection.ReplyAddress);
                    }
                    if (removeConnection)
                    {
                        // client not found or expired
                        expiredConns.Add(connection);
                    }
                    else
                    {
                        activeCount++;
                    }
                }
                foreach (IConnection connection in expiredConns)
                {
                    _connectionIndex.Remove(connection.ClientId);
                    _cacheEngine.DeleteConnectionState(connection.ClientId);
                }
                DateTimeOffset dtCompleted = DateTimeOffset.Now;
                TimeSpan       duration    = dtCompleted - dtCommenced;
                Logger.LogDebug("---------- Housekeep Connections ----------");
                Logger.LogDebug("Connections");
                Logger.LogDebug("  Active    : {0}", activeCount);
                Logger.LogDebug("  Expired   : {0}", expiredConns.Count);
                Logger.LogDebug("Duration    : {0}s", duration.TotalSeconds);
                Logger.LogDebug("---------- Housekeep Connections ----------");
            }
            catch (Exception e)
            {
                Logger.LogError("HousekeepConnections failed: {0}", e);
            }

            // ---------------------------------------- next part ----------------------------------------
            //Interlocked.Increment(ref _HousekeepCallsPart2);
            //_MainCommsDispatcher.Dispatch<object>(null, HousekeeperPart2);
        }
Beispiel #2
0
        // ICoreClient subscription methods
        public void Unsubscribe(Guid subscriptionId)
        {
            Client.Unsubscribe(subscriptionId);
            _Subscriptions.Remove(subscriptionId);
            var cacheItems = Cache.GetCacheItems();

            foreach (var cacheItem in cacheItems)
            {
                if (cacheItem.UserParam.SubscriptionId == subscriptionId)
                {
                    Cache.Remove(cacheItem.UserKey, cacheItem.UserParam);
                }
            }
        }
Beispiel #3
0
        private void ProgressCallback(ISubscription subscription, ICoreItem item)
        {
            try
            {
                ProgressObj oldProgress = null;
                ProgressObj newProgress = null;
                if (item != null)
                {
                    // get old request view object
                    Guid requestId = item.AppProps.GetValue <Guid>(RequestBase.Prop.RequestId, true);
                    oldProgress = _ProgressCache.Remove(requestId);
                    // build the new request view object
                    if (item.IsCurrent())
                    {
                        if (item.DataType.IsSubclassOf(typeof(RequestBase)))
                        {
                            RequestBase request = item.Data as RequestBase;
                            if (request != null)
                            {
                                newProgress = new ProgressObj(requestId, item.Created, oldProgress, request);
                            }
                        }
                        else if (item.DataType.IsSubclassOf(typeof(ResponseBase)))
                        {
                            ResponseBase response = item.Data as ResponseBase;
                            if (response != null)
                            {
                                newProgress = new ProgressObj(requestId, item.Created, oldProgress, response);
                            }
                        }
                        else
                        {
                            throw new NotSupportedException(String.Format("Type: '{0}'", item.DataType.Name));
                        }
                    }
                    if (newProgress != null)
                    {
                        _ProgressCache.Set(requestId, newProgress);
                    }
                }
                else
                {
                    throw new ArgumentNullException("item");
                }

                // determine the change type
                CacheChange change = CacheChange.Undefined;
                if (oldProgress != null)
                {
                    // updated or deleted
                    if (newProgress != null)
                    {
                        change = CacheChange.ItemUpdated;
                    }
                    else
                    {
                        change = CacheChange.ItemRemoved;
                    }
                }
                else
                {
                    // created or ???
                    if (newProgress != null)
                    {
                        change = CacheChange.ItemCreated;
                    }
                }
                if (change != CacheChange.Undefined)
                {
                    _ProgressView.UpdateData(new ViewChangeNotification <ProgressObj>()
                    {
                        Change = change, OldData = oldProgress, NewData = newProgress
                    });
                }
            }
            catch (Exception excp)
            {
                _MainLog.Log(excp);
            }
        }