Ejemplo n.º 1
0
        /// <summary>
        /// Creates a synchronization between two or more vertices, where the vertices
        /// are, once all are able to fire, fired in the order specified in the 'vertices'
        /// array.
        /// </summary>
        /// <param name="exec">The executive in whose simulation this VS is currently running.</param>
        /// <param name="vertices">An array of vertices to be synchronized.</param>
        /// <param name="vertexFiringType">The type of ExecEvent that successor edges to this vertex
        /// should be called with.</param>
        public VertexSynchronizer(IExecutive exec, Vertex[] vertices, ExecEventType vertexFiringType)
        {
            m_vertices  = vertices;
            m_exec      = exec;
            m_eventType = vertexFiringType;
            //Trace.Write("CREATING SYNCHRONIZER WITH TASKS ( " );

            foreach (Vertex vertex in m_vertices)
            {
                if (vertex.PrincipalEdge is Tasks.Task)
                {
                    ((Tasks.Task)vertex.PrincipalEdge).SelfValidState = false;
                }
            }

            foreach (Vertex vertex in m_vertices)
            {
                //Trace.Write(vertex.Name + ", ");
                if (vertex.Role.Equals(Vertex.WhichVertex.Post))
                {
                    throw new ApplicationException("Cannot synchronize postVertices at this time.");
                }
                else
                {
                    vertex.SetSynchronizer(this);
                }
            }
            //_Debug.WriteLine(" )");
        }
Ejemplo n.º 2
0
        public void TestEventJoinDetachable()
        {
            IExecutive    exec1     = ExecFactory.Instance.CreateExecutive("Highpoint.Sage.SimCore.Executive", Guid.NewGuid());
            DateTime      setupTime = new DateTime(2008, 11, 24, 12, 15, 44);
            ExecEventType eet       = ExecEventType.Detachable; // Don't change this one. Join must be done on a detachable event.

            exec1.RequestEvent(new ExecEventReceiver(JoinDetachableSetup), setupTime, 0.0, null, eet);
            exec1.Start();
        }
Ejemplo n.º 3
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);
            }
Ejemplo n.º 4
0
 public virtual void DeserializeFrom(XmlSerializationContext xmlsc)
 {
     m_model                    = (Model)xmlsc.ContextEntities["Model"];
     m_eet                      = (ExecEventType)xmlsc.LoadObject("ExecEventType");
     m_guid                     = (Guid)xmlsc.LoadObject("Guid");
     m_keepGraphContexts        = (bool)xmlsc.LoadObject("KeepGCs");
     m_masterTask               = (Task)xmlsc.LoadObject("MasterTask");
     m_name                     = (string)xmlsc.LoadObject("Name");
     m_startConditionsSpecified = (bool)xmlsc.LoadObject("StartCondSpec");
     m_when                     = (DateTime)xmlsc.LoadObject("When");
 }
Ejemplo n.º 5
0
        public TaskProcessor(IModel model, string name, Guid guid, Task task)
        {
            InitializeIdentity(model, name, null, guid);

            m_masterTask = task;
            m_priority   = 0.0;
            m_when       = DateTime.MinValue;
            m_eet        = ExecEventType.Synchronous;
            Model.GetService <ITaskManagementService>().AddTaskProcessor(this);

            IMOHelper.RegisterWithModel(this);
        }
Ejemplo n.º 6
0
        public virtual void DeserializeFrom(XmlSerializationContext xmlsc)
        {
            // TODO:  Add Vertex.DeserializeFrom implementation
            m_exec      = ((Model)xmlsc.ContextEntities["Model"]).Executive;
            m_eventType = (ExecEventType)xmlsc.LoadObject("EventType");
            int vertexCount = (int)xmlsc.LoadObject("VertexCount");

            m_vertices = new Vertex[vertexCount];
            //for ( int i = 0 ; i < vertexCount ; i++ ) {
            throw new NotImplementedException("Vertex deserialization not yet implemented in VertexSynchronizers.");
            //}
        }
Ejemplo n.º 7
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);
            }
 private void FireTheVertex(IDictionary graphContext)
 {
     if (m_model.Executive.Now < m_earliest)
     {
         TimeSpan ts = (m_earliest - m_model.Executive.Now);
         // _Debug.WriteLine(m_model.Executive.Now + " : " + "Will fire vertex " + m_vertex.Name + " after a delay of " + string.Format("{0:d2}:{1:d2}:{2:d2}",ts.Hours,ts.Minutes,ts.Seconds));
         ExecEventType eet = m_model.Executive.CurrentEventType;
         m_model.Executive.RequestEvent(new ExecEventReceiver(_FireTheVertex), m_earliest, 0, graphContext, eet);
     }
     else
     {
         // _Debug.WriteLine(m_model.Executive.Now + " : " + "Firing vertex " + m_vertex.Name);
         m_vertexTrigger(graphContext);
     }
 }
Ejemplo n.º 9
0
        private void JoinDetachableSetup(IExecutive exec, object userData)
        {
            DateTime[] whens = new DateTime[3];
            whens[0] = new DateTime(2008, 11, 25, 12, 15, 44);
            whens[1] = new DateTime(2008, 11, 26, 12, 15, 44);
            whens[2] = new DateTime(2008, 11, 27, 12, 15, 44);
            List <long>   eventKeys = new List <long>();
            ExecEventType eet       = ExecEventType.Synchronous;

            for (int i = 0; i < 3; i++)
            {
                if (eet == ExecEventType.Synchronous)
                {
                    eventKeys.Add(exec.RequestEvent(new ExecEventReceiver(DoItWithoutSuspension), whens[i], 0.0, null, eet));
                }
                else if (eet == ExecEventType.Detachable)
                {
                    eventKeys.Add(exec.RequestEvent(new ExecEventReceiver(DoItWithSuspension), whens[i], 0.0, null, eet));
                }
            }
            Console.WriteLine(exec.Now + " : Waiting to join.");
            exec.Join(eventKeys.ToArray());
            Console.WriteLine(exec.Now + " : Done waiting to join.");
        }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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));
 }
Ejemplo n.º 13
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.");
 }
Ejemplo n.º 14
0
 public void SetStartEventType(ExecEventType eet)
 {
     m_eet = eet;
 }
Ejemplo n.º 15
0
 public void SetConfigData(DateTime when, ExecEventType eet, double priority)
 {
     SetStartTime(when);
     SetStartEventType(eet);
     SetStartEventPriority(priority);
 }
Ejemplo n.º 16
0
 public bool SelectThisEvent(ExecEventReceiver eer, DateTime when, double priority, object userData,
                             ExecEventType eet)
 {
     return(eer.Target != null && eer.Target.GetType() == m_targetType);
 }
Ejemplo n.º 17
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);
 }