Example #1
0
        /// <summary>
        /// Execute remote command from client to cache using <see cref="QueueMessage"/>.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public NetStream ExecRemote(QueueMessage message)
        {
            QueueState state       = QueueState.Ok;
            DateTime   requestTime = DateTime.Now;

            try
            {
                switch (message.Command)
                {
                case QueueCmd.Reply:
                    return(QueueEntry.GetAckStream(QueueState.Ok, QueueCmd.Reply, message.Key));

                case QueueCmd.AddItem:
                    return(message.AsyncAckTask(() => AddItemWithAck(message), message.Command));

                case QueueCmd.GetValue:
                    return(message.AsyncAckTask(() => GetValueStream(message.Key), message.Command));

                case QueueCmd.FetchValue:
                    return(message.AsyncAckTask(() => FetchValueStream(message.Key), message.Command));

                case QueueCmd.GetItem:
                    return(message.AsyncAckTask(() => GetItemStream(message.Key), message.Command));

                case QueueCmd.FetchItem:
                    return(message.AsyncAckTask(() => FetchItemStream(message.Key), message.Command));

                case QueueCmd.ViewItem:
                    return(message.AsyncAckTask(() => ViewItemStream(message.Key), message.Command));

                case QueueCmd.RemoveItem:
                    return(message.AsyncAckTask(() => RemoveItem(message), message.Command));

                case QueueCmd.RemoveItemAsync:
                    message.AsyncTask(() => RemoveItemAsync(message.Key));
                    break;

                case QueueCmd.CopyItem:
                {
                    var args = message.GetArgs();
                    return(message.AsyncAckTask(() => CopyItemInternal(args.Get <string>(KnowsArgs.Source), args.Get <string>(KnowsArgs.Destination), message.Expiration), message.Command));
                }

                case QueueCmd.CutItem:
                {
                    var args = message.GetArgs();
                    return(message.AsyncAckTask(() => CutItemInternal(args.Get <string>(KnowsArgs.Source), args.Get <string>(KnowsArgs.Destination), message.Expiration), message.Command));
                }

                case QueueCmd.KeepAliveItem:
                    message.AsyncTask(() => KeepAliveItem(message.Key));
                    break;

                case QueueCmd.RemoveQueueSessionItems:
                    return(message.AsyncAckTask(() => RemoveQueueSessionItemsAsync(message), message.Command));

                case QueueCmd.LoadData:
                    return(message.AsyncAckTask(() => LoadData(message), message.Command));
                }
            }
            catch (QueueException ce)
            {
                state = ce.State;
                LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote QueueException error: " + ce.Message);
            }
            catch (System.Runtime.Serialization.SerializationException se)
            {
                state = QueueState.SerializationError;
                LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote SerializationException error: " + se.Message);
            }
            catch (ArgumentException aex)
            {
                state = QueueState.ArgumentsError;
                QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote ArgumentException: " + aex.Message);
            }
            catch (Exception ex)
            {
                state = QueueState.UnexpectedError;
                LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote error: " + ex.Message);
            }
            finally
            {
                if (QueueSettings.EnablePerformanceCounter)
                {
                    if (QueueSettings.EnableAsyncTask)
                    {
                        AgentManager.PerformanceTasker.Add(new Nistec.Threading.TaskItem(() => PerformanceCounter.AddResponse(requestTime, state, true), QueueDefaults.DefaultTaskTimeout));
                    }
                    else
                    {
                        Task.Factory.StartNew(() => PerformanceCounter.AddResponse(requestTime, state, true));
                    }
                }
            }

            return(QueueEntry.GetAckStream(state, message.Command));
        }
Example #2
0
        /// <summary>
        /// Execute remote command from client to queue managment using <see cref="QueueMessage"/>.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        internal static NetStream ExecManager(QueueMessage message)
        {
            QueueState state = QueueState.Ok;

            try
            {
                NetStream stream = null;
                switch (message.Command)
                {
                case QueueManagerCmd.Reply:
                    return(QueueEntry.GetAckStream(QueueState.Ok, QueueManagerCmd.Reply, message.Key));

                case QueueManagerCmd.QueueProperties:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.PerformanceCounter.GetPerformanceProperties(), message.Command));


                case QueueManagerCmd.CloneItems:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    var       args = message.GetArgs();
                    CloneType ct   = EnumExtension.Parse <CloneType>(args.Get <string>("value"), CloneType.All);
                    return(message.AsyncTask(() => Queue.CloneItems(ct), message.Command));

                case QueueManagerCmd.GetAllKeys:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.GetAllKeys(), message.Command));

                case QueueManagerCmd.GetAllKeysIcons:
                    if (_Queue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Queue.GetAllKeysIcons(), message.Command));

                case QueueManagerCmd.StateCounterQueue:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.Queue), message.Command));

                case QueueManagerCmd.StateCounterSync:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.SyncQueue), message.Command));

                case QueueManagerCmd.StateCounterSession:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.SessionQueue), message.Command));

                case QueueManagerCmd.StateCounterDataQueue:
                    return(message.AsyncTask(() => QueueStateCounter(QueueAgentType.DataQueue), message.Command));

                case QueueManagerCmd.GetStateCounterReport:
                    return(message.AsyncTask(() => QueueStateCounter(), message.Command));

                case QueueManagerCmd.GetPerformanceReport:
                    return(message.AsyncTask(() => PerformanceReport(), message.Command));

                case QueueManagerCmd.GetAgentPerformanceReport:
                    QueueAgentType agentType = QueuePerformanceCounter.GetAgent(message.Key);
                    return(message.AsyncTask(() => PerformanceReport(agentType), message.Command));

                case QueueManagerCmd.ResetPerformanceCounter:
                    message.AsyncTask(() => ResetPerformanceCounter());
                    return(null);

                case QueueManagerCmd.GetAllDataKeys:
                    if (_DbQueue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => DbQueue.GetAllDataKeys(), message.Command));

                case QueueManagerCmd.GetAllSyncQueueKeys:
                    if (_SyncQueue == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => SyncQueue.QueueKeys().ToArray(), message.Command));

                case QueueManagerCmd.QueueLog:
                    return(message.AsyncTask(() => QueueLogger.Logger.QueueLog(), message.Command));

                case QueueManagerCmd.GetAllSessionsKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Session.GetAllSessionsKeys(), message.Command));

                case QueueManagerCmd.GetAllSessionsStateKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    stream = new NetStream();
                    SessionState st = (SessionState)message.GetArgs().Get <int>("state");
                    return(message.AsyncTask(() => Session.GetAllSessionsStateKeys(st), message.Command));

                case QueueManagerCmd.GetSessionItemsKeys:
                    if (_Session == null)
                    {
                        return(null);
                    }
                    return(message.AsyncTask(() => Session.GetSessionsItemsKeys(message.Id), message.Command));

                //=== Queue api===================================================
                case QueueCmd.ViewItem:
                case QueueCmd.RemoveItem:
                    return(Queue.ExecRemote(message));

                //=== Data Queue api===================================================
                case DataQueueCmd.GetItemProperties:
                case DataQueueCmd.RemoveTable:
                //case DataQueueCmd.GetDataStatistic:
                case DataQueueCmd.GetDataTable:

                    return(DbQueue.ExecRemote(message));

                //=== Sync Queue api===================================================

                case SyncQueueCmd.RemoveSyncItem:
                case SyncQueueCmd.GetSyncItem:
                //case SyncQueueCmd.GetSyncStatistic:
                case SyncQueueCmd.GetItemsReport:

                    return(SyncQueue.ExecRemote(message));

                //=== Session Queue api===================================================

                case SessionCmd.RemoveSession:
                case SessionCmd.GetExistingSession:

                    return(Session.ExecRemote(message));
                }
            }
            catch (System.Runtime.Serialization.SerializationException se)
            {
                state = QueueState.SerializationError;
                QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "ExecManager error: " + se.Message);
            }
            catch (Exception ex)
            {
                state = QueueState.UnexpectedError;
                QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "ExecManager error: " + ex.Message);
            }

            return(QueueEntry.GetAckStream(state, message.Command)); //null;
        }