protected void Enqueue(IQueable data) { if (!OnMailboxMessage(data)) { m_Queue.Enqueue(data); } }
private void process(IQueable msg) { try { if (msg is ErlException) { this.Mailbox.DeliverError(this, (ErlException)msg); return; } var erlMsg = msg as ErlMsg; if (erlMsg == null) throw new ErlException("Invalid message type: " + msg.GetType()); var map = ((ErlDataStore)Store).Map; var binding = new ErlVarBind(); //{Schema, ChangeType :: $d | $w, [{schema, Flds...}]} if (erlMsg.Msg==null || !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding)) return; var schemaName = ((ErlAtom)binding[SCHEMA]).Value; var op = ((ErlByte)binding[TYPE]).Value; var rows = ((ErlList)binding[ROWS]).Value; var schema = map.GetCRUDSchemaForName(schemaName); foreach(var rowTuple in rows.Cast<ErlTuple>()) { var row = map.ErlTupleToRow(schemaName, rowTuple, schema); var ctp = op == 'd' ? RowChangeType.Delete : RowChangeType.Upsert; var data = new RowChange(ctp, row, null); this.Mailbox.Deliver(this, data); } } catch(Exception err) { App.Log.Write( new Log.Message { Type = Log.MessageType.Error, Topic = CoreConsts.ERLANG_TOPIC, From = "{0}.process()".Args(GetType().Name), Text = err.ToMessageWithType(), Exception = err } ); } }
public void ProcessSegment(IQueable<Element> minPQ) { while (!_readComplete || !_concurentQueue.IsEmpty) { Element aux = _concurentQueue.Dequeue(); if (aux != null) { byte[] processedData = _gzip.DoWork(aux.Data); minPQ.Enqueue(new Element { Number = aux.Number, Data = processedData }); aux = null; } } Interlocked.Increment(ref _processDone); }
public BaseEngine(IGzipAction gzip, int queueCapacity) { _gzip = gzip; _q = new SimpleQueue(queueCapacity); _minPQ = new MinPriorityQueue<Element>(queueCapacity); //_concurentQueue = new ConcurrentQueue<Element>(_q); //_concurentMinPQ = new ConcurrentQueue<Element>(_minPQ); _concurentQueue = _q; _concurentMinPQ = _minPQ; _processors = Environment.ProcessorCount; _capacity = queueCapacity; _processDone = 0; }
protected virtual bool OnMailboxMessage(IQueable msg) { return(MailboxMessage != null && MailboxMessage(this, msg)); }
protected virtual bool OnMailboxMessage(IQueable msg) { return MailboxMessage != null && MailboxMessage(this, msg); }
protected void Enqueue(IQueable data) { if (!OnMailboxMessage(data)) m_Queue.Enqueue(data); }
private void process(IQueable msg) { try { if (msg is ErlException) { this.Mailbox.DeliverError(this, (ErlException)msg); return; } var erlMsg = msg as ErlMsg; if (erlMsg == null) { throw new ErlException("Invalid message type: " + msg.GetType()); } var map = ((ErlDataStore)Store).Map; var binding = new ErlVarBind(); //{Schema, TS, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert) //{Schema, TS, ChangeType :: $D | $C | $c, []} %% Drop, Create, Clear if (erlMsg.Msg == null || !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding)) { return; } var schemaName = ((ErlAtom)binding[SCHEMA]).Value; var ts = binding[TIMESTAMP].ValueAsLong; var op = (char)((ErlByte)binding[TYPE]).Value; var rows = ((ErlList)binding[ROWS]).Value; var schema = map.GetCRUDSchemaForName(schemaName); m_LastTimeStamp = new DataTimeStamp(ts); CRUDSubscriptionEvent.EventType etp; switch (op) { case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break; case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break; case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break; case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break; default: etp = CRUDSubscriptionEvent.EventType.RowUpsert; break; } if (rows.Count > 0) { int errors = 0; foreach (var rowTuple in rows.Cast <ErlTuple>()) { try { var row = map.ErlTupleToRow(schemaName, rowTuple, schema); var data = new CRUDSubscriptionEvent(etp, schema, row, m_LastTimeStamp); this.Mailbox.Deliver(this, data); } catch (Exception ie) { errors++; log(ie); } } // TODO: Add error reporting to user } else { //used to clear data, no rows are fetched var data = new CRUDSubscriptionEvent(etp, schema, null, m_LastTimeStamp); this.Mailbox.Deliver(this, data); } } catch (Exception err) { log(err); } }
private void process(IQueable msg) { try { if (msg is ErlException) { this.Mailbox.DeliverError(this, (ErlException)msg); return; } var erlMsg = msg as ErlMsg; if (erlMsg == null) throw new ErlException("Invalid message type: " + msg.GetType()); var map = ((ErlDataStore)Store).Map; var binding = new ErlVarBind(); //{Schema, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert) //{Schema, ChangeType :: $D | $C | $c, []} %% Drop, Create, Clear if (erlMsg.Msg==null || !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding)) return; var schemaName = ((ErlAtom)binding[SCHEMA]).Value; var op = (char)((ErlByte)binding[TYPE]).Value; var rows = ((ErlList)binding[ROWS]).Value; var schema = map.GetCRUDSchemaForName(schemaName); CRUDSubscriptionEvent.EventType etp; switch(op) { case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break; case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break; case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break; case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break; default: etp = CRUDSubscriptionEvent.EventType.RowUpsert; break; } if (rows.Count>0) { foreach(var rowTuple in rows.Cast<ErlTuple>()) { var row = map.ErlTupleToRow(schemaName, rowTuple, schema); var data = new CRUDSubscriptionEvent(etp, schema, row); this.Mailbox.Deliver(this, data); } } else { var data = new CRUDSubscriptionEvent(etp, schema, null); this.Mailbox.Deliver(this, data); } } catch(Exception err) { App.Log.Write( new Log.Message { Type = Log.MessageType.Error, Topic = CoreConsts.ERLANG_TOPIC, From = "{0}.process()".Args(GetType().Name), Text = err.ToMessageWithType(), Exception = err } ); } }
private void process(IQueable msg) { try { if (msg is ErlException) { this.Mailbox.DeliverError(this, (ErlException)msg); return; } var erlMsg = msg as ErlMsg; if (erlMsg == null) throw new ErlException("Invalid message type: " + msg.GetType()); var map = ((ErlDataStore)Store).Map; var binding = new ErlVarBind(); //{Schema, TS, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert) //{Schema, TS, ChangeType :: $D | $C | $c, []} %% Drop, Create, Clear if (erlMsg.Msg==null || !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding)) return; var schemaName = ((ErlAtom)binding[SCHEMA]).Value; var ts = binding[TIMESTAMP].ValueAsLong; var op = (char)((ErlByte)binding[TYPE]).Value; var rows = ((ErlList)binding[ROWS]).Value; var schema = map.GetCRUDSchemaForName(schemaName); m_LastTimeStamp = new DataTimeStamp(ts); CRUDSubscriptionEvent.EventType etp; switch(op) { case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break; case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break; case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break; case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break; default: etp = CRUDSubscriptionEvent.EventType.RowUpsert; break; } if (rows.Count>0) { int errors = 0; foreach(var rowTuple in rows.Cast<ErlTuple>()) { try { var row = map.ErlTupleToRow(schemaName, rowTuple, schema); var data = new CRUDSubscriptionEvent(etp, schema, row, new DataTimeStamp(ts)); this.Mailbox.Deliver(this, data); } catch(Exception ie) { errors++; log(MessageType.Error, "prcs().forea(rTpl)", ie.ToMessageWithType(), ie); } } // TODO: Add error reporting to user } else { //used to clear data, no rows are fetched var data = new CRUDSubscriptionEvent(etp, schema, null, new DataTimeStamp(ts)); this.Mailbox.Deliver(this, data); } } catch(Exception err) { log(MessageType.Error, "prcs().outcatch{}", err.ToMessageWithType(), err); } }
protected void Enqueue(IQueable data) { m_Queue.Enqueue(data); }
private void process(IQueable msg) { try { if (msg is ErlException) { this.Mailbox.DeliverError(this, (ErlException)msg); return; } var erlMsg = msg as ErlMsg; if (erlMsg == null) { throw new ErlException("Invalid message type: " + msg.GetType()); } var map = ((ErlDataStore)Store).Map; var binding = new ErlVarBind(); //{Schema, TS, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert) //{Schema, TS, ChangeType :: $D | $C | $c, []} %% Drop, Create, Clear if (erlMsg.Msg == null || !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding)) { return; } var schemaName = ((ErlAtom)binding[SCHEMA]).Value; var ts = binding[TIMESTAMP].ValueAsLong; var op = (char)((ErlByte)binding[TYPE]).Value; var rows = ((ErlList)binding[ROWS]).Value; var schema = map.GetCRUDSchemaForName(schemaName); m_LastTimeStamp = new DataTimeStamp(ts); CRUDSubscriptionEvent.EventType etp; switch (op) { case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break; case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break; case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break; case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break; default: etp = CRUDSubscriptionEvent.EventType.RowUpsert; break; } if (rows.Count > 0) { foreach (var rowTuple in rows.Cast <ErlTuple>()) { var row = map.ErlTupleToRow(schemaName, rowTuple, schema); var data = new CRUDSubscriptionEvent(etp, schema, row, new DataTimeStamp(ts)); this.Mailbox.Deliver(this, data); } } else { //used to clear data, no rows are fetched var data = new CRUDSubscriptionEvent(etp, schema, null, new DataTimeStamp(ts)); this.Mailbox.Deliver(this, data); } } catch (Exception err) { App.Log.Write( new Log.Message { Type = Log.MessageType.Error, Topic = CoreConsts.ERLANG_TOPIC, From = "{0}.process()".Args(GetType().Name), Text = err.ToMessageWithType(), Exception = err } ); } }