Example #1
0
    internal ErlCRUDSubscription(ErlDataStore store,
                                 string name,
                                 Query query,
                                 Mailbox recipient) : base(store, name, query, recipient)
    {
       m_ErlBox = store.m_ErlNode.CreateMbox(name);

       m_ErlBox.MailboxMessage += (_, msg) => 
                                  {
                                    Task.Run( () => process(msg) );
                                    return true;
                                  };

       var handler = store.QueryResolver.Resolve(query);
       var result = handler.ExecuteWithoutFetch( new ErlCRUDQueryExecutionContext(store, m_ErlBox), query);
    }
Example #2
0
    internal ErlCRUDSubscription(ErlDataStore store,
                                 string name,
                                 Query query,
                                 Mailbox recipient,
                                 object correlate = null
                                 ) : base(store, name, query, recipient, correlate)
    {
       m_ErlBox = store.MakeMailbox();

       m_ErlBox.MailboxMessage += (_, msg) => 
                                  {
                                    Task.Run( () => process(msg) );
                                    return true;
                                  };

       m_Store = store;
       m_Query = query;
       subscribeCore();
       HasLoaded();
    }
        private void m_Mailbox_Receipt(Subscription subscription, Mailbox recipient, CRUDSubscriptionEvent data, Exception error)
        {
            if (error != null)
            {
                OnError(error);
                return;
            }

            var schema = data.Schema;
            var table  = m_Tables.GetOrRegister(schema.Name, (s) => new table(new Table(s), subscription.Query), schema).Table;

            lock (table)
            {
                var proceed = OnReceipt(SynchronizedReceiptHandlerEventArgs.EventPhase.Before, table, data.Type, data.Row);

                if (!proceed)
                {
                    return;
                }

                switch (data.Type)
                {
                case CRUDSubscriptionEvent.EventType.TableCreate: break;

                case CRUDSubscriptionEvent.EventType.TableClear: table.DeleteAll(); break;

                case CRUDSubscriptionEvent.EventType.TableDrop: m_Tables.Unregister(schema.Name); break;

                case CRUDSubscriptionEvent.EventType.RowInsert: table.Insert(data.Row); break;

                case CRUDSubscriptionEvent.EventType.RowUpdate: table.Update(data.Row); break;

                case CRUDSubscriptionEvent.EventType.RowUpsert: table.Upsert(data.Row); break;

                case CRUDSubscriptionEvent.EventType.RowDelete: table.Delete(data.Row); break;
                }

                OnReceipt(SynchronizedReceiptHandlerEventArgs.EventPhase.After, table, data.Type, data.Row);
            }
        }
Example #4
0
    protected Subscription(ICRUDSubscriptionStoreImplementation store, string name, Query query, Mailbox mailbox) : base(store)
    {
      if (store==null ||
          query==null||
          mailbox==null) 
        throw new CRUDException(StringConsts.ARGUMENT_ERROR+GetType().FullName+".ctor(args...null)");

      if (mailbox.Store!=store)
        throw new CRUDException(StringConsts.ARGUMENT_ERROR+GetType().FullName+".ctor(mailbox.Store!=this.Store)");

      m_Store = store;
      m_Name = name.IsNullOrWhiteSpace() ? Guid.NewGuid().ToString() : name;
      m_Query = query;
      m_Mailbox = mailbox;

      var reg = m_Store.Subscriptions as Registry<Subscription>;
      Subscription existing;
      if (!reg.RegisterOrReplace(this, out existing))
       existing.Dispose();

      ((Registry<Subscription>)mailbox.Subscriptions).Register(this);
    }
Example #5
0
        internal ErlCRUDSubscription(ErlDataStore store,
            string name,
            Query query,
            Mailbox recipient,
            object correlate = null
            )
            : base(store, name, query, recipient, correlate)
        {
            m_ErlBox = store.MakeMailbox();
               m_Queue  = new ConcurrentQueue<IQueable>();

               m_ErlBox.MailboxMessage += (_, msg) =>
                                  {
                                    m_Queue.Enqueue(msg);
                                    asyncProcess();
                                    return true;
                                  };

               m_Store = store;
               m_Query = query;
               subscribeCore();
               HasLoaded();
        }
Example #6
0
        protected Subscription(ICRUDSubscriptionStoreImplementation store, string name, Query query, Mailbox mailbox, object correlate) : base(store)
        {
            if (store == null ||
                query == null ||
                mailbox == null)
            {
                throw new CRUDException(StringConsts.ARGUMENT_ERROR + GetType().FullName + ".ctor(args...null)");
            }

            if (mailbox.Store != store)
            {
                throw new CRUDException(StringConsts.ARGUMENT_ERROR + GetType().FullName + ".ctor(mailbox.Store!=this.Store)");
            }

            m_Store   = store;
            m_Name    = name.IsNullOrWhiteSpace() ? Guid.NewGuid().ToString() : name;
            m_Query   = query;
            m_Mailbox = mailbox;
            Correlate = correlate;

            var          reg = m_Store.Subscriptions as Registry <Subscription>;
            Subscription existing;

            if (!reg.RegisterOrReplace(this, out existing))
            {
                existing.Dispose();
            }

            ((Registry <Subscription>)mailbox.Subscriptions).Register(this);
        }
Example #7
0
    private void m_Mailbox_Receipt(Subscription subscription, Mailbox recipient, CRUDSubscriptionEvent data, Exception error)
    {
      if (error!=null)
      {
        OnError(error);
        return;
      }
      
      var schema = data.Schema;
      var table = m_Tables.GetOrRegister(schema.Name, (s) => new table(new Table(s), subscription.Query), schema).Table;
      lock(table)
      {
        var proceed = OnReceipt(SynchronizedReceiptHandlerEventArgs.EventPhase.Before, table, data.Type, data.Row);

        if (!proceed) return;

        switch(data.Type)
        {
          case CRUDSubscriptionEvent.EventType.TableCreate: break;
          case CRUDSubscriptionEvent.EventType.TableClear: table.DeleteAll(); break;
          case CRUDSubscriptionEvent.EventType.TableDrop: m_Tables.Unregister(schema.Name); break;
          
          case CRUDSubscriptionEvent.EventType.RowInsert: table.Insert(data.Row); break;
          case CRUDSubscriptionEvent.EventType.RowUpdate: table.Update(data.Row); break;
          case CRUDSubscriptionEvent.EventType.RowUpsert: table.Upsert(data.Row); break;
          case CRUDSubscriptionEvent.EventType.RowDelete: table.Delete(data.Row); break;
        }

        OnReceipt(SynchronizedReceiptHandlerEventArgs.EventPhase.After, table, data.Type, data.Row);
      }
    }