Exemplo n.º 1
0
        //EventDataCache m_edCache;

        /// <summary>
        /// Creates a new instance of the <see cref="T:LocalEventQueue"/> class.
        /// </summary>
        /// <param name="exec">The executive that this LocalEventQueue services.</param>
        /// <param name="capacity">The capacity.</param>
        /// <param name="eer">The <see cref="Highpoint.Sage.SimCore.ExecEventReceiver"/> that this LocalEventQueue manages callbacks into.</param>
        public LocalEventQueue(IExecutive exec, int capacity, ExecEventReceiver eer)
        {
            m_exec       = exec;
            m_capacity   = capacity;
            m_eer        = eer;
            m_targetName = ((IHasName)m_eer.Target).Name;

            m_dequeueHandler = Dequeue;

            m_circQueue = new EventData[capacity];
            for (int i = 0; i < capacity; i++)
            {
                m_circQueue[i] = new EventData();
            }
            //m_edCache = new EventDataCache(capacity);
            m_head = 0;
            m_tail = 0;

#if USING_CANNED_HEAP
            m_heap = new Heap(Heap.HEAP_RULE.MinValue);
#endif

            if (m_capacity < 1)
            {
                throw new ArgumentException("LocalEventQueue created with a negative or zero capacity - it must be positive!");
            }
        }
Exemplo n.º 2
0
            public _ExecEvent Take(ExecEventReceiver eer, DateTime when, object userData, long key, bool isDaemon)
            {
                if (m_head == m_tail)
                {
                    // Queue is empty!
                    m_tail           = m_numExecEvents;
                    m_head           = 0;
                    m_numExecEvents *= 2;
                    m_execEventCache = new _ExecEvent[m_numExecEvents];
                    for (int i = m_head; i < m_tail; i++)
                    {
                        m_execEventCache[i] = new _ExecEvent();
                    }
                }
                _ExecEvent retval = m_execEventCache[m_head++];

                if (m_head == m_numExecEvents)
                {
                    m_head = 0;
                }

                retval.Eer      = eer;
                retval.Key      = key;
                retval.UserData = userData;
                retval.When     = when.Ticks;
                retval.IsDaemon = isDaemon;

                return(retval);
            }
Exemplo n.º 3
0
        private void Model_Starting(IModel theModel)
        {
            ExecEventReceiver eer  = new ExecEventReceiver(AdjustPriority);
            DateTime          when = theModel.Executive.Now + TimeSpan.FromMinutes(15);

            theModel.Executive.RequestEvent(eer, when, 0.0, null, ExecEventType.Synchronous);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Requests that the executive queue up an event to be serviced at a specific time and
 /// priority.
 /// </summary>
 /// <param name="eer">The ExecEventReceiver callback that is to receive the callback.</param>
 /// <param name="when">The date &amp; time at which the callback is to be made.</param>
 /// <param name="priority">The priority of the callback. This executive forces all priorities to zero.</param>
 /// <param name="userData">Object data to be provided in the callback.</param>
 /// <returns>
 /// A code that can subsequently be used to identify the request, e.g. for removal.
 /// </returns>
 public long RequestEvent(ExecEventReceiver eer, DateTime when, double priority, object userData)
 {
     if (when < m_now)
     {
         if (!_ignoreCausalityViolations)
         {
             string who = eer.Target.GetType().FullName;
             if (eer.Target is IHasName)
             {
                 who = ((IHasName)eer.Target).Name;
             }
             string method = eer.Method.Name + "(...)";
             string msg    = string.Format("Executive was asked to service an event prior to current time. This is a causality violation. The call was made from {0}.{1}.", who, method);
             //throw new ApplicationException(msg);
             Console.WriteLine(msg);
         }
         else
         {
             when = m_now;
         }
     }
     m_key++;
     Enqueue(new _ExecEvent(eer, when, userData, m_key, false));
     //Enqueue(m_execEventCache.Take(eer,when,userData,m_key));
     return(m_key);
 }
Exemplo n.º 5
0
        private void Executive_EventAboutToFire(long key, ExecEventReceiver eer, double priority, DateTime when, object userData, ExecEventType eventType)
        {
            string method = eer.Method.ToString();

            method = method.Replace(",", ":");
            m_logFile.WriteLine(when.ToString(CultureInfo.InvariantCulture) + ", " + priority + ", " + eer.Target + ", " + method + ", " +
                                (userData?.ToString() ?? "<null>") + ", " + eventType);
        }
Exemplo n.º 6
0
 public _ExecEvent()
 {
     Eer      = null;
     When     = 0L;
     UserData = null;
     Key      = 0L;
     IsDaemon = false;
 }
Exemplo n.º 7
0
 public _ExecEvent(ExecEventReceiver eer, DateTime when, object userData, long key, bool isDaemon)
 {
     Eer      = eer;
     When     = when.Ticks;
     UserData = userData;
     Key      = key;
     IsDaemon = isDaemon;
 }
Exemplo n.º 8
0
            private void ScheduleMyResourceAction(IModel theModel)
            {
                ExecEventReceiver eer      = new ExecEventReceiver(DoResourceAction);
                DateTime          when     = theModel.Executive.Now + TimeSpan.FromMinutes(5.0);
                double            priority = 0.0;
                ExecEventType     eet      = ExecEventType.Detachable;

                theModel.Executive.RequestEvent(eer, when, priority, null, eet);
            }
Exemplo n.º 9
0
        public void TestExecutiveUnRequestTarget()
        {
            IExecutive  exec = ExecFactory.Instance.CreateExecutive();
            DateTime    now  = DateTime.Now;
            DateTime    when;
            double      priority;
            OtherTarget ot = null;

            // initialize validation variables
            m_error             = false;
            m_validateUnRequest = new ArrayList();
            Debug.WriteLine("");
            Debug.WriteLine("Start test TestExecutiveUnRequestTarget");
            Debug.WriteLine("");

            for (int i = 0; i < NUM_EVENTS; i++)
            {
                when     = new DateTime(now.Ticks + m_random.Next());
                priority = m_random.NextDouble();
                Debug.WriteLine("Primary requesting event service " + i);
                switch (i)
                {
                case 1:
                case 2:
                case 3:
                case 5:
                case 7:
                case 11:
                    m_validateUnRequest.Add(i);
                    ot = new OtherTarget(m_validateUnRequest, m_error);
                    ExecEventReceiver eer = new ExecEventReceiver(ot.ExecEventRecieverUnRequestEventReceiver);
                    exec.RequestEvent(eer, when, priority, i, m_execEventType);
                    exec.UnRequestEvents(ot);
                    break;

                default:
                    exec.RequestEvent(new ExecEventReceiver(this.ExecEventRecieverUnRequestEventReceiver), when, priority, i, m_execEventType);
                    break;
                }
                ;
            }


            Debug.WriteLine("");

// AEL			exec.UnRequestEvents(new OtherTarget(m_validateUnRequest, m_error));

            exec.Start();

            Debug.WriteLine("");

            // test validation variable
            Assert.IsTrue(!m_error, "Executive did fire a unrequested event");

            Debug.WriteLine("");
        }
Exemplo n.º 10
0
 public Recurrence(IExecutive exec, DateTime baseline, DateTime stopAfter, double priority)
 {
     NextOccurrence         = baseline;
     StopAfterDate          = stopAfter;
     Priority               = priority;
     Exec                   = exec;
     Exec.ExecutiveStarted += new ExecutiveEvent(ScheduleNext);
     UseDaemonEvents        = stopAfter.Equals(DateTime.MaxValue);
     Eer = new ExecEventReceiver(_Occurrence);
 }
Exemplo n.º 11
0
 public Recurrence(IExecutive exec, DateTime baseline, int numberOfRecurrences, double priority)
 {
     NextOccurrence         = baseline;
     NumRecurrences         = numberOfRecurrences;
     Priority               = priority;
     Exec                   = exec;
     Exec.ExecutiveStarted += new ExecutiveEvent(ScheduleNext);
     UseDaemonEvents        = numberOfRecurrences < 0;
     Eer = new ExecEventReceiver(_Occurrence);
 }
Exemplo n.º 12
0
 public TupleTester()
 {
     m_exec           = ExecFactory.Instance.CreateExecutive();
     m_t              = new DateTime(2004, 07, 15, 05, 23, 14);
     m_postIt         = new ExecEventReceiver(PostTuple);
     m_readIt         = new ExecEventReceiver(ReadTuple);
     m_takeIt         = new ExecEventReceiver(TakeTuple);
     m_blockingPostIt = new ExecEventReceiver(BlockingPostTuple);
     m_blockingReadIt = new ExecEventReceiver(BlockingReadTuple);
     m_blockingTakeIt = new ExecEventReceiver(BlockingTakeTuple);
     m_blockTilGone   = new ExecEventReceiver(BlockTilGoneTuple);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Abstract base class constructor for the Metronome_Base class.
 /// </summary>
 /// <param name="exec">The executive that will be serving the events.</param>
 /// <param name="startAt">The start time for the event train.</param>
 /// <param name="finishAfter">The end time for the event train.</param>
 /// <param name="period">The periodicity of the event train.</param>
 protected MetronomeBase(IExecutive exec, DateTime startAt, DateTime finishAfter, TimeSpan period)
 {
     m_startAt                     = startAt;
     m_finishAfter                 = finishAfter;
     m_period                      = period;
     m_executive                   = exec;
     m_autoFinish                  = false;
     m_autoStart                   = false;
     m_execEvent                   = OnExecEvent;
     TotalTicksExpected            = (int)((m_finishAfter.Ticks - m_startAt.Ticks) / m_period.Ticks);
     m_executive.ExecutiveStarted += m_executive_ExecutiveStarted;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Abstract base class constructor for the Metronome_Base class. Assumes both autostart
 /// and autofinish for this metronome.
 /// </summary>
 /// <param name="exec">The executive that will be serving the events.</param>
 /// <param name="period">The periodicity of the event train.</param>
 protected MetronomeBase(IExecutive exec, TimeSpan period)
 {
     m_startAt     = DateTime.MinValue;
     m_finishAfter = DateTime.MaxValue;
     m_period      = period;
     m_executive   = exec;
     m_autoFinish  = true;
     m_autoStart   = true;
     m_execEvent   = OnExecEvent;
     m_executive.EventAboutToFire += m_executive_EventAboutToFire;
     TotalTicksExpected            = int.MaxValue;
 }
Exemplo n.º 15
0
            private void AcqireResource(IModel theModel)
            {
                Console.WriteLine("Acquiring the resource at " + theModel.Executive.Now);
                m_rscReq = new SimpleResourceRequest(1.0, m_smr);
                m_smr.Acquire(m_rscReq, false);

                ExecEventReceiver eer      = new ExecEventReceiver(ReleaseResource);
                DateTime          when     = theModel.Executive.Now + TimeSpan.FromMinutes(10.0);
                double            priority = 0.0;
                ExecEventType     eet      = ExecEventType.Synchronous;

                theModel.Executive.RequestEvent(eer, when, priority, null, eet);
            }
Exemplo n.º 16
0
 /// <summary>
 /// Creates a new instance of the <see cref="T:Ticker"/> class.
 /// </summary>
 /// <param name="model">The model in which this object runs.</param>
 /// <param name="periodicity">The periodicity of the ticker.</param>
 /// <param name="autoStart">if set to <c>true</c> the ticker will start automatically, immediately on model start, and cycle indefinitely.</param>
 /// <param name="nPulses">The number of pulses to be served.</param>
 public Ticker(IModel model, IPeriodicity periodicity, bool autoStart, long nPulses)
 {
     m_periodicity       = periodicity;
     m_model             = model;
     m_autoStart         = autoStart;
     m_nPulses           = nPulses;
     m_execEventReceiver = new ExecEventReceiver(OnExecEvent);
     if (autoStart)
     {
         m_model.Starting += new ModelEvent(OnModelStarting);
     }
     m_model.Stopping += new ModelEvent(OnModelStopping);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates a channel for which the transit rate is fixed, and which can hold a specified
 /// capacity of payload.
 /// </summary>
 /// <param name="model">The model in which this FixedRateChannel exists.</param>
 /// <param name="name">The name of this FixedRateChannel.</param>
 /// <param name="guid">The GUID of this FixedRateChannel.</param>
 /// <param name="exec">The executive that controls this channel.</param>
 /// <param name="transitPeriod">How long it takes an object to transit the channel.</param>
 /// <param name="capacity">How many objects the channel can hold.</param>
 public FixedRateChannel(IModel model, string name, Guid guid, IExecutive exec, TimeSpan transitPeriod, double capacity)
 {
     m_exec          = exec;
     m_transitPeriod = transitPeriod;
     m_capacity      = capacity;
     m_entryPeriod   = TimeSpan.FromTicks((long)((double)m_transitPeriod.Ticks / m_capacity));
     m_queue         = new Queue();
     m_entry         = new SimpleInputPort(model, "Entry", Guid.NewGuid(), this, new DataArrivalHandler(OnEntryAttempted));
     m_exit          = new SimpleOutputPort(model, "Exit", Guid.NewGuid(), this, new DataProvisionHandler(CantTakeFromChannel), new DataProvisionHandler(CantPeekFromChannel));
     //m_ports.AddPort(m_entry); <-- Done in port's ctor.
     //m_ports.AddPort(m_exit); <-- Done in port's ctor.
     m_dequeueEventHandler = new ExecEventReceiver(DequeueEventHandler);
 }
Exemplo n.º 18
0
 public PulseSource(IModel model, IPeriodicity periodicity, bool initialPulse)
 {
     m_model        = model;
     m_periodicity  = periodicity;
     m_initialPulse = initialPulse;
     m_doPulse      = new ExecEventReceiver(DoPulse);
     if (m_model.Executive.State.Equals(ExecState.Stopped) || m_model.Executive.State.Equals(ExecState.Finished))
     {
         m_model.Executive.ExecutiveStarted += new ExecutiveEvent(StartPulsing);
     }
     else
     {
         StartPulsing(model.Executive);
     }
 }
Exemplo n.º 19
0
        private MultiChannelDelayServer(IModel model, string name, Guid guid)
        {
            InitializeIdentity(model, name, null, guid);

            m_entryPort = new SimpleInputPort(model, "Input", Guid.NewGuid(), this, new DataArrivalHandler(OnDataArrived));
            m_exitPort  = new SimpleOutputPort(model, "Output", Guid.NewGuid(), this, null, null); // No take, no peek.

            // AddPort(m_entryPort); <-- Done in port's ctor.
            // AddPort(m_exitPort); <-- Done in port's ctor.

            m_releaseObject = new ExecEventReceiver(ReleaseObject);

            m_inService = new ArrayList();
            m_pending   = 0;

            IMOHelper.RegisterWithModel(this);
        }
Exemplo n.º 20
0
 public bool SelectThisEvent(ExecEventReceiver eer, DateTime when, double priority, object userData,
                             ExecEventType eet)
 {
     return(eer.Target != null && eer.Target.GetType() == m_targetType);
 }
Exemplo n.º 21
0
 private void m_executive_EventAboutToFire(long key, ExecEventReceiver eer, double priority, DateTime when, object userData, ExecEventType eventType)
 {
     m_executive.RequestEvent(m_execEvent, when, priority + double.Epsilon, null);
     m_executive.EventAboutToFire -= m_executive_EventAboutToFire;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Requests that the executive queue up an event to be serviced at a specific time and
 /// priority.
 /// </summary>
 /// <param name="eer">The ExecEventReceiver callback that is to receive the callback.</param>
 /// <param name="when">The date &amp; time at which the callback is to be made.</param>
 /// <param name="priority">The priority of the callback. This executive forces all priorities to zero.</param>
 /// <param name="userData">Object data to be provided in the callback.</param>
 /// <param name="execEventType">The way the event is to be served by the executive.</param>
 /// <returns>
 /// A code that can subsequently be used to identify the request, e.g. for removal.
 /// </returns>
 long IExecutive.RequestEvent(ExecEventReceiver eer, DateTime when, double priority, object userData, ExecEventType execEventType)
 {
     //if ( !execEventType.Equals(ExecEventType.Synchronous) ) throw new ApplicationException("This high performance exec can currently only handler synchronous events.");
     return(RequestEvent(eer, when, priority, userData));
 }
Exemplo n.º 23
0
 public void Kickoff(long key, ExecEventReceiver eer, double priority, DateTime when, object userData, ExecEventType eventType)
 {
     m_exec.EventAboutToFire -= Kickoff;
     m_parent.Begin(m_parent.m_executive, m_parent.m_userData);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Requests that the executive queue up an event to be serviced at the current executive time and
 /// priority.
 /// </summary>
 /// <param name="eer">The ExecEventReceiver callback that is to receive the callback.</param>
 /// <param name="userData">Object data to be provided in the callback.</param>
 /// <param name="eet">The EventType that declares how the event is to be served by the executive.</param>
 /// <returns>A code that can subsequently be used to identify the request, e.g. for removal.</returns>
 public long RequestImmediateEvent(ExecEventReceiver eer, object userData, ExecEventType eet)
 {
     throw new NotSupportedException("The selected executive type does not support contemporaneous enqueueing.");
 }
Exemplo n.º 25
0
 /// <summary>
 /// Requests that the executive queue up an event to be serviced at a specific time. Priority is assumed
 /// to be zero.
 /// </summary>
 /// <param name="eer">The ExecEventReceiver callback that is to receive the callback.</param>
 /// <param name="when">The date &amp; time at which the callback is to be made.</param>
 /// <param name="userData">Object data to be provided in the callback.</param>
 /// <returns>
 /// A code that can subsequently be used to identify the request, e.g. for removal.
 /// </returns>
 public long RequestEvent(ExecEventReceiver eer, DateTime when, object userData)
 {
     return(RequestEvent(eer, when, 0.0, userData));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Requests that the executive queue up an event to be serviced at a specific time. Priority is assumed
 /// to be zero, and the userData object is assumed to be null.
 /// </summary>
 /// <param name="eer">The ExecEventReceiver callback that is to receive the callback.</param>
 /// <param name="when">The date &amp; time at which the callback is to be made.</param>
 /// <returns>
 /// A code that can subsequently be used to identify the request, e.g. for removal.
 /// </returns>
 public long RequestEvent(ExecEventReceiver eer, DateTime when)
 {
     return(RequestEvent(eer, when, 0.0, null));
 }