private void CleanUpIfClosed(uint target_handle, object key)
        {
            if (target_handle < 1)
            {
                throw new ArgumentException("target_handle should be > 0");
            }
            else if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            Contact         contact = Connection.Roster.GetContact(target_handle);
            DispatchManager dm      = contact.DispatchManager;

            Dispatchable d = dm.Get(contact, key, DispatchObject);

            if (d != null)
            {
                if (d.IsClosed)
                {
                    dm.Remove(contact, key, DispatchObject);
                }
                else
                {
                    throw new InvalidOperationException(String.Format("{0} already has dispatchable object type {1} with key {2}",
                                                                      contact.Name, DispatchObject.FullName, key)
                                                        );
                }
            }
        }
        public void Notify(Dispatchable msg)
        {
            //Insert the message to the message queue
            _messagesQueue.Enqueue(msg);

            //Signal the waiting object
            _notifyEvent.Set();
        }
Esempio n. 3
0
 public void Dispatch(Dispatchable dispatchable)
 {
     if (_processDispatch.Get())
     {
         var dispatchId = dispatchable.Id;
         _access.WriteUsing("dispatched", dispatchId, new Dispatch(dispatchable.TypedState <TextState>(), dispatchable.Entries));
     }
 }
Esempio n. 4
0
 public void Unlock(Dispatchable dispatchable)
 {
     if (m_State && m_Active == dispatchable)
     {
         m_State  = false;
         m_Active = null;
     }
 }
Esempio n. 5
0
        private void OnDispatched(Dispatchable d, EventArgs args)
        {
            var handler = Dispatched;

            if (handler != null)
            {
                handler(d, args);
            }
        }
Esempio n. 6
0
        private void Dispatch(string streamName, int streamVersion, IEnumerable <TEntry> entries, TState?snapshot)
        {
            var dispatchableEntries = entries as TEntry[] ?? entries.ToArray();
            var id           = GetDispatchId(streamName, streamVersion, dispatchableEntries);
            var dispatchable = new Dispatchable <TEntry, TState>(id, DateTimeOffset.Now, snapshot, dispatchableEntries);

            _dispatchables.Add(dispatchable);
            _dispatcher.Dispatch(dispatchable);
        }
 public void Dispatch(Dispatchable dispatchable)
 {
     _dispatchAttemptCount++;
     if (_processDispatch.Get())
     {
         var dispatchId = dispatchable.Id;
         _access.WriteUsing("dispatched", dispatchable);
         _control.ConfirmDispatched(dispatchId, _confirmDispatchedResultInterest);
     }
 }
Esempio n. 8
0
 public void Dispatch(Dispatchable <TEntry, TState> dispatchable)
 {
     _dispatchAttemptCount++;
     if (_processDispatch.Get())
     {
         var dispatchId = dispatchable.Id;
         _access.WriteUsing("dispatched", dispatchId, new DispatchInternal(dispatchable.TypedState <TState>(), dispatchable.Entries));
         _control.ConfirmDispatched(dispatchId, _confirmDispatchedResultInterest);
     }
 }
Esempio n. 9
0
 public void Remove(Dispatchable Job)
 {
     lock (DispatchQueue.SyncRoot)
     {
         var array = DispatchQueue.ToArray();
         var list  = new ArrayList(array);
         list.Remove(Job);
         DispatchQueue = new Queue(list);
     }
 }
Esempio n. 10
0
    public void Register(float priority, Dispatchable dispatchable)
    {
        List <Dispatchable> dispatchables;

        if (!m_Dispatchables.TryGetValue(priority, out dispatchables))
        {
            dispatchables             = new List <Dispatchable>();
            m_Dispatchables[priority] = dispatchables;
        }
        dispatchables.Add(dispatchable);
    }
Esempio n. 11
0
        private void ValidateDispatchedState(Person persistedObject, Dispatchable <ObjectEntry <Test1Source>, State <string> > dispatched)
        {
            Assert.NotNull(dispatched);
            Assert.NotNull(dispatched.Id);

            Assert.NotNull(dispatched.State.Get());
            var state = dispatched.TypedState <State <string> >();

            Assert.Equal(persistedObject.PersistenceId.ToString(), state.Id);
            Assert.Equal(persistedObject.GetType().AssemblyQualifiedName, state.Type);
            Assert.Equal(Metadata.NullMetadata(), state.Metadata);
        }
Esempio n. 12
0
        public void Append(Dispatchable Job, object Parameter, int Repeats, bool Wait)
        {
            JobItem NewJob = new JobItem();

            NewJob.Repeats   = Repeats;
            NewJob.Wait      = Wait;
            NewJob.Job       = Job;
            NewJob.Parameter = Parameter;
            lock (DispatchQueue.SyncRoot)
            {
                DispatchQueue.Enqueue(NewJob);
            }
        }
Esempio n. 13
0
        internal void Add(Contact contact, object key, Dispatchable d, bool replace)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }
            else if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            else if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            else if (!conn.Equals(contact.Connection))
            {
                throw new InvalidOperationException(String.Format("Contact does not belong to connection {0}",
                                                                  conn.AccountId));
            }

            string type = d.GetType().FullName;

            //Hyena.Log.DebugFormat ("DispatchManager.Add dispatchable type {0}", type);

            lock (dispatchables) {
                if (!dispatchables.ContainsKey(contact))
                {
                    dispatchables.Add(contact, new Dictionary <string, IDictionary <object, Dispatchable> > ());
                }
                if (!dispatchables[contact].ContainsKey(type))
                {
                    dispatchables[contact].Add(type, new Dictionary <object, Dispatchable> ());
                }
                if (!dispatchables[contact][type].ContainsKey(key))
                {
                    dispatchables[contact][type].Add(key, d);
                }
                else if (replace)
                {
                    Remove(contact, key, d.GetType());
                    Add(contact, key, d, false);
                }
                else
                {
                    throw new InvalidOperationException("Dispatchable could not be added to dispatch manager.");
                }

                OnDispatched(d, EventArgs.Empty);
                d.Initialize();
            }
        }
        public override void Dispatch(Dispatchable dispatchable)
        {
            dispatchable.State.IfPresent(state =>
            {
                if (HasProjectionsFor(state.Metadata.Operation))
                {
                    Dispatch(dispatchable.Id, new BinaryProjectable(state, dispatchable.Entries, dispatchable.Id));
                }
            });

            var entries = dispatchable.Entries.Where(entry => HasProjectionsFor(entry.TypeName)).ToList();

            if (entries.Any())
            {
                Dispatch(dispatchable.Id, new BinaryProjectable(dispatchable.State.OrElse(null !), entries, dispatchable.Id));
            }
        }
Esempio n. 15
0
 public bool Lock(Dispatchable dispatchable)
 {
     if (!m_State)
     {
         m_State  = true;
         m_Active = dispatchable;
         return(true);
     }
     else
     {
         bool yield = m_Active.Yield(dispatchable);
         if (yield)
         {
             Yield(dispatchable);
         }
         return(yield);
     }
 }
 /// <inheritdoc />
 public void PersistDispatchable(Dispatchable <TEntry, TState> dispatchable) => _dispatchables.Add(dispatchable);
Esempio n. 17
0
 /// <inheritdoc />
 public void PersistDispatchable(Dispatchable dispatchable) => _dispatchables.Add(dispatchable);
Esempio n. 18
0
 /// <summary>
 /// Add an item to be dispatched.  The item is added to
 /// the external dispatch queue.
 /// </summary>
 /// <param name="dispatchable">to execute later</param>
 public void AddExternal(Dispatchable dispatchable)
 {
     _threadDispatchQueue
     .GetOrCreate()
     .Enqueue(dispatchable);
 }
Esempio n. 19
0
 public void Dispatch(Dispatchable dispatchable) => _control?.ConfirmDispatched(dispatchable.Id, this);
Esempio n. 20
0
 private void Dispatch(Dispatchable <TEntry, TState> dispatchable) => _dispatcher.Dispatch(dispatchable);
 public void Dispatch(Dispatchable dispatchable)
 {
 }
Esempio n. 22
0
 public void Dispatch(Dispatchable dispatchable)
 {
     dispatchableQueue.Enqueue(dispatchable);
     StartDispatchLoop();
 }
Esempio n. 23
0
 internal void Add(Contact contact, object key, Dispatchable d)
 {
     Add(contact, key, d, true);
 }
Esempio n. 24
0
 public void AddExternal(Dispatchable dispatchable)
 {
     ArrayDeque<Dispatchable> dispatchQueue = dispatchStateThreadLocal.GetOrCreate();
     AddToQueue(dispatchable, dispatchQueue);
 }
Esempio n. 25
0
 private static void AddToQueue(
     Dispatchable dispatchable,
     ICollection<Dispatchable> dispatchQueue)
 {
     dispatchQueue.Add(dispatchable);
 }
 public void Dispatch(Dispatchable dispatchable) =>
 _access.WriteUsing("appendedAll", dispatchable.Entries);
 private void Dispatch(Dispatchable dispatchable) => _dispatcher.Dispatch(dispatchable);
Esempio n. 28
0
 public virtual bool Yield(Dispatchable dispatchable)
 {
     return(false);
 }
Esempio n. 29
0
 private void Yield(Dispatchable dispatchable)
 {
     m_Active = dispatchable;
 }
Esempio n. 30
0
 public abstract void Dispatch(Dispatchable dispatchable);