public static void Pause(int src, double delay)
        {
            SimEvent ev = new SimEvent(SimEvent.HOLD_DONE, _clock + delay, src);

            _futureQueue.AddEvent(ev);
            _entities.Find(e => e.Id == src).State = SimEntity.HOLDING;
        }
        public static void SendFirst(int src, int dest, double delay, int tag, object data)
        {
            ValidateDelay(delay);
            SimEvent e = new SimEvent(SimEvent.SEND, _clock + delay, src, dest, tag, data);

            _futureQueue.AddEventFirst(e);
        }
Exemple #3
0
        public void AddEvent(SimEvent newEvent)
        {
            double eventTime = newEvent.EventTime;

            if (eventTime >= _maxTime)
            {
                _list.Add(newEvent);
                _maxTime = eventTime;
                return;
            }

            var      enumerator   = _list.GetEnumerator();
            SimEvent current      = null;
            var      listAsLinked = (_list as LinkedList <SimEvent>);

            do
            {
                current = enumerator.Current;
                if (current.EventTime > eventTime)
                {
                    if (listAsLinked != null)
                    {
                        var currentNode =
                            listAsLinked.Find(current);

                        listAsLinked.AddBefore(currentNode, newEvent);
                        return;
                    }
                }
            }while (enumerator.MoveNext());

            _list.Add(newEvent);
        }
 public override void ProcessEvent(SimEvent e)
 {
     _numUser--;
     if (_numUser == 0 || e.Tag == CloudSimTags.ABRUPT_END_OF_SIMULATION)
     {
         CloudSim.AbruptlyTerminate();
     }
 }
Exemple #5
0
        protected void ProcessOtherEvent(SimEvent e)
        {
            var methodName = MethodBase.GetCurrentMethod().Name;
            var className  = GetType().Name;

            if (e == null)
            {
                Log.WriteConcatLine(className, ".", methodName, "(): Unable to handle a request since the event is null.");
                return;
            }

            Log.WriteLine($"{className}.{methodName}(): Unable to handle a request from {CloudSim.GetEntityName(e.Source)} with event tag = {e.Tag}");
        }
        public virtual void Run()
        {
            SimEvent ev = _eventBuffer != null ?
                          _eventBuffer : GetNextEvent();

            while (ev != null)
            {
                ProcessEvent(ev);
                if (State != RUNNABLE)
                {
                    break;
                }
                ev = GetNextEvent();
            }

            _eventBuffer = null;
        }
        public static void AddEntity(SimEntity e)
        {
            SimEvent evt;

            if (_running)
            {
                evt = new SimEvent(SimEvent.CREATE, _clock, src: 1, dest: 0, tag: 0, edata: e);
                _futureQueue.AddEvent(evt);
            }
            if (e.Id == -1)
            {
                int id = _entities.Count;
                e.Id = id;
                _entities.Add(e);
                _entitiesByName.Add(e.Name, e);
            }
        }
        public static SimEvent Cancel(int src, Predicate p)
        {
            SimEvent ev = null;
            IEnumerator <SimEvent> enumerator = _futureQueue.GetEnumerator();

            do
            {
                ev = enumerator.Current;
                if (ev.Source == src && p.Match(ev))
                {
                    _futureQueue.Remove(ev);
                    break;
                }
            } while (enumerator.MoveNext());

            return(ev);
        }
        public static SimEvent Select(int src, Predicate p)
        {
            SimEvent ev = null;
            IEnumerator <SimEvent> enumerator = _deferedQueue.GetEnumerator();

            do
            {
                var current = enumerator.Current;
                if (current != null)
                {
                    ev = current;
                    if (current.Destination == src && p.Match(ev))
                    {
                        _deferedQueue.Remove(ev);
                        break;
                    }
                }
            } while (enumerator.MoveNext());
            return(ev);
        }
Exemple #10
0
        public override void ProcessEvent(SimEvent e)
        {
            int id = -1;

            switch (e.Tag)
            {
            case CloudSimTags.REGISTER_REGIONAL_GIS:
                _gisList.Add((int)e.Data);
                break;

            case CloudSimTags.REQUEST_REGIONAL_GIS:
                id = (int)e.Data;
                Send(id, 0, e.Tag, _gisList);
                break;

            case CloudSimTags.REGISTER_RESOURCE:
                _resList.Add((int)e.Data);
                break;

            case CloudSimTags.REGISTER_RESOURCE_AR:
                _resList.Add((int)e.Data);
                _arList.Add((int)e.Data);
                break;

            case CloudSimTags.RESOURCE_LIST:
                id = (int)e.Data;
                Send(id, 0, e.Tag, _resList);
                break;

            case CloudSimTags.RESOURCE_AR_LIST:
                id = (int)e.Data;
                Send(id, 0, e.Tag, _arList);
                break;

            default:
                ProcessOtherEvent(e);
                break;
            }
        }
        public static bool CancelAll(int src, Predicate p)
        {
            SimEvent ev       = null;
            int      prevSize = _futureQueue.Size();
            IEnumerator <SimEvent> enumerator = _futureQueue.GetEnumerator();

            do
            {
                ev = enumerator.Current;
                if (ev.Source == src && p.Match(ev))
                {
                    _futureQueue.Remove(ev);
                }
            } while (enumerator.MoveNext());

            // In original CloudSim code on Java
            // the comparison has such representation
            // Not sure whether it is correct,
            // because in case if at least one event
            // will be removed, then prevSize will
            // always be greater than actual size
            return(prevSize < _futureQueue.Size());
        }
 public abstract void ProcessEvent(SimEvent e);
        private static void ProcessEvent(SimEvent e)
        {
            int       dest, src;
            SimEntity destEnt;

            if (e.EventTime < _clock)
            {
                throw new ArgumentException("Past event detected.");
            }

            _clock = e.EventTime;

            switch (e.InternalType)
            {
            case SimEvent.ENULL:
                throw new ArgumentException("Event has a null type.");

            case SimEvent.CREATE:
                SimEntity newEntity = (SimEntity)e.Data;
                AddEntityDynamically(newEntity);
                break;

            case SimEvent.SEND:
                dest = e.Destination;
                if (dest < 0)
                {
                    throw new ArgumentException("Attempt to send to null entity detected.");
                }
                else
                {
                    int tag = e.Tag;
                    destEnt = _entities.Find(ent => ent.Id == dest);
                    if (destEnt.State == SimEntity.WAITING)
                    {
                        Predicate p;
                        if (_waitPredicates.TryGetValue(dest, out p))
                        {
                            if (p == null || tag == 9999 || p.Match(e))
                            {
                                destEnt.EventBuffer = (SimEvent)e.Clone();
                                destEnt.State       = SimEntity.RUNNABLE;
                                _waitPredicates.Remove(dest);
                            }
                            else
                            {
                                _deferedQueue.AddEvent(e);
                            }
                        }
                    }
                    else
                    {
                        _deferedQueue.AddEvent(e);
                    }
                }
                break;

            case SimEvent.HOLD_DONE:
                src = e.Source;
                if (src < 0)
                {
                    throw new ArgumentException("Null entity holding.");
                }
                else
                {
                    _entities.Find(ent => ent.Id == src).State = SimEntity.RUNNABLE;
                }
                break;
            }
        }
Exemple #14
0
 public bool Remove(SimEvent e)
 {
     return(_list.Remove(e));
 }