Ejemplo n.º 1
0
        /// <summary>
        /// RabitManager constructor.  Creates the manager's thread.
        /// If the user has derived their own Workspace from the RabitWorkspace,
        /// it must be provided when the manager is constructed... otherwise
        /// the standard RabitWorkspace will be used.
        /// </summary>
        public RabitManager()
        {
            //Generate the Manager Name for use in tracking error messages.
            //and setting up queue names.
            managerName = this.GetType().ToString();
            int idx = managerName.LastIndexOf('.');

            managerName = managerName.Substring(idx + 1);

            managerThread      = new Thread(new ThreadStart(managerMain));
            managerThread.Name = managerName;
            shutdownManager    = false;

            MgrStatus = new ManagerStatusMessage();
            //Add all publish subscribe messages this manager relies on to the
            //global workspace here
            string mgrStatusMsgName = string.Concat(ManagerName, "Status");

            AddPublishSubscribeMessage(mgrStatusMsgName, MgrStatus);

            MgrControl = new ManagerControlMessage();
            AddPublishSubscribeMessage("ManagerControl", MgrControl);

            //string mgrMsgQueueName = string.Concat(ManagerName, "MessageQueue");
            MgrMessageQueue = new RabitMessageQueue(100, ManagerName);
            //Add the Message Queue to the Global Workspace
            AddManagerMessageQueue(ManagerName, MgrMessageQueue);

            //Setup Event Handling
            ewhWaitHandle      = new EventWaitHandle(false, EventResetMode.AutoReset);
            wakeupManagerEvent = new PublishSubscribeMessChangedHandler(wakeUpManagerEH);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A manager can register a message queue pick up event if the manager
        /// needs to know when a message has been picked up by the receiving queue.
        /// Registering events should be done in the Manager's startup code.
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="delegateFunction"></param>
        /// <returns></returns>
        public bool RegisterMsgPickedUpEvent(string queueName, PublishSubscribeMessChangedHandler delegateFunction)
        {
            bool error = true;
            RabitMessageQueue msgQueue = null;

            if (messageQueueDict.TryGetValue(queueName, out msgQueue))
            {
                msgQueue.RegisterMsgPickedUpEvent(delegateFunction);
                error = false;
            }
            return(error);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a message to a Manager's Message Queue.
        /// It is assumed the manager added the Message Queue when it
        /// was initialized.
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="msg"></param>
        /// <returns>true if error... not message queue, false otherwise</returns>
        public bool AddMessageToQueue(string queueName, Object msg)
        {
            bool error = true;
            //As long as the messageQueuesDict is not being changed
            //after the Manager's first initialize... it is safe to
            //obtain the message queue without getting a lock.
            RabitMessageQueue msgQueue = null;

            if (messageQueueDict.TryGetValue(queueName, out msgQueue))
            {
                msgQueue.addMessage(msg);
                error = false;
            }
            return(error);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get a reference to the Global Publish Subscribe Message... this is
        /// normally used to get the reference used by the Message.
        /// </summary>
        /// <param name="messageName"></param>
        /// <returns></returns>
        //public PublishSubscribeMessage GetPublishSubscribeMessageRef(string messageName)
        //{
        //    PublishSubscribeMessage psMsgRef = null;
        //    //rwlPublishSubscribeDict.EnterReadLock();
        //    if( publishSubcribeMsgDict.ContainsKey(messageName ) )
        //    {
        //        psMsgRef = publishSubcribeMsgDict[messageName].PSMsg;
        //    }
        //    //rwlPublishSubscribeDict.ExitReadLock();
        //    return psMsgRef;
        //}

        /// <summary>
        /// Add a thread-safe message queue to the Global WorkSpace.
        /// Managers that are on the recieving end of the Queue should add the
        /// message queue to the global workspace.  Other managers may obtain
        /// references to the message queue or add messages to the queue at run
        /// time.
        /// </summary>
        /// <param name="msgQueue"></param>
        /// <returns></returns>
        public void AddManagerMessageQueue(string queueName, RabitMessageQueue msgQueue)
        {
            //rwlMessageQueueDict.EnterWriteLock();
            messageQueueDict[queueName] = msgQueue;
            //rwlMessageQueueDict.ExitWriteLock();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add a thread-safe message queue to the Global WorkSpace.
 /// Managers that are on the recieving end of the Queue should add the
 /// message queue to the global workspace.  Other managers may obtain
 /// references to the message queue or add messages to the queue at run
 /// time.
 /// </summary>
 /// <param name="msgQueue"></param>
 /// <returns></returns>
 public void AddManagerMessageQueue(string queueName, RabitMessageQueue msgQueue)
 {
     RabitWorkspace.GetWorkspace().AddManagerMessageQueue(queueName, msgQueue);
 }