Ejemplo n.º 1
0
        private PersistentMessage.Builder PersistentToProto(IPersistentRepresentation p)
        {
            var builder = PersistentMessage.CreateBuilder();

            if (p.PersistenceId != null)
            {
                builder.SetPersistenceId(p.PersistenceId);
            }
            if (p.Sender != null)
            {
                builder.SetSender(Akka.Serialization.Serialization.SerializedActorPath(p.Sender));
            }
            if (p.Manifest != null)
            {
                builder.SetManifest(p.Manifest);
            }

            builder
            .SetPayload(PersistentPayloadToProto(p.Payload))
            .SetSequenceNr(p.SequenceNr);
            // deleted is not used in new records

            if (p.WriterGuid != null)
            {
                builder.SetWriterUuid(p.WriterGuid);
            }

            return(builder);
        }
        private PersistentMessage GetPersistentMessage(IPersistentRepresentation persistent)
        {
            PersistentMessage message = new PersistentMessage();

            if (persistent.PersistenceId != null)
            {
                message.PersistenceId = persistent.PersistenceId;
            }
            if (persistent.Manifest != null)
            {
                message.Manifest = persistent.Manifest;
            }
            if (persistent.WriterGuid != null)
            {
                message.WriterGuid = persistent.WriterGuid;
            }
            if (persistent.Sender != null)
            {
                message.Sender = Akka.Serialization.Serialization.SerializedActorPath(persistent.Sender);
            }

            message.Payload    = GetPersistentPayload(persistent.Payload);
            message.SequenceNr = persistent.SequenceNr;
            message.Deleted    = persistent.IsDeleted;

            return(message);
        }
Ejemplo n.º 3
0
        public void EnqueueDirectlyTo(ITransaction transaction, string queue, string subqueue, MessagePayload payload, MessageId id = null)
        {
            var message = new PersistentMessage
            {
                Data    = payload.Data,
                Headers = payload.Headers,
                Id      = id ?? new MessageId
                {
                    SourceInstanceId  = _queueStorage.Id,
                    MessageIdentifier = GuidCombGenerator.Generate()
                },
                Queue    = queue,
                SentAt   = DateTime.Now,
                SubQueue = subqueue,
                Status   = MessageStatus.EnqueueWait
            };

            _queueStorage.Global(actions =>
            {
                var queueActions = actions.GetQueue(queue);

                var bookmark = queueActions.Enqueue(message);
                actions.RegisterUpdateToReverse(transaction.Id, bookmark, MessageStatus.EnqueueWait, subqueue);
            });

            _logger.QueuedForReceive(message);

            lock (_newMessageArrivedLock)
            {
                Monitor.PulseAll(_newMessageArrivedLock);
            }
        }
        private void ProcessMission()
        {
            if (_mission == null || _mission.PhaseList.Count < 1)
            {
                return;
            }

            CurrentPhase = _mission.PhaseList[CurrentPhaseIndex];

            // ok, we have a mission with at least 1 phase
            int currentStartPhase = 0;
            int currentEndPhase   = 0;

            foreach (var mm in _mission.MilitaryMessages)
            {
                currentStartPhase = 0;
                currentEndPhase   = -1;

                foreach (var phase in _mission.PhaseList)
                {
                    if (mm.VisibleTimeExtent.Intersects(phase.VisibleTimeExtent))
                    {
                        currentEndPhase = _mission.PhaseList.IndexOf(phase);
                    }
                    else
                    {
                        //if (_mission.PhaseList.IndexOf(phase) <= currentEndPhase)
                        if (currentEndPhase < 0)
                        {
                            //currentStartPhase = _mission.PhaseList.IndexOf(phase);
                            currentStartPhase++;
                        }
                    }
                }

                var pm = new PersistentMessage()
                {
                    ID = mm.Id, VisibleTimeExtent = mm.VisibleTimeExtent
                };

                var piList = new List <PropertyItem>();

                foreach (var item in mm)
                {
                    piList.Add(new PropertyItem()
                    {
                        Key = item.Key, Value = item.Value
                    });
                }

                pm.PropertyItems = piList;

                CreateUpdateSymbolWithPM(pm, currentStartPhase, currentEndPhase);
            }
        }
Ejemplo n.º 5
0
        private IPersistentRepresentation PersistentMessageFrom(byte[] bytes)
        {
            var persistentMessage = PersistentMessage.ParseFrom(bytes);

            return(new Persistent(
                       payload: PayloadFromProto(persistentMessage.Payload),
                       sequenceNr: persistentMessage.SequenceNr,
                       persistenceId: persistentMessage.HasPersistenceId ? persistentMessage.PersistenceId : null,
                       isDeleted: persistentMessage.Deleted,
                       sender: persistentMessage.HasSender ? system.Provider.ResolveActorRef(persistentMessage.Sender) : null));
        }
Ejemplo n.º 6
0
 private IPersistentRepresentation PersistentMessageFrom(PersistentMessage persistentMessage)
 {
     return(new Persistent(
                payload: PayloadFromProto(persistentMessage.Payload),
                sequenceNr: persistentMessage.SequenceNr,
                persistenceId: persistentMessage.HasPersistenceId ? persistentMessage.PersistenceId : null,
                manifest: persistentMessage.HasManifest ? persistentMessage.Manifest : null,
                // isDeleted is not used in new records from 1.5
                sender: persistentMessage.HasSender ? system.Provider.ResolveActorRef(persistentMessage.Sender) : null,
                writerGuid: persistentMessage.HasWriterUuid ? persistentMessage.WriterUuid : null));
 }
Ejemplo n.º 7
0
        public PersistentMessage PeekById(string queueName, MessageId id)
        {
            PersistentMessage message = null;

            _queueStorage.Global(actions =>
            {
                var queue = actions.GetQueue(queueName);

                message = queue.PeekById(id);
            });
            return(message);
        }
Ejemplo n.º 8
0
        private void InsertPersistentMessage(PeerId peerId, DateTime timestamp, AckState ackState = AckState.Acked)
        {
            var message = new PersistentMessage
            {
                PeerId   = peerId.ToString(),
                BucketId = BucketIdHelper.GetBucketId(timestamp),
                IsAcked  = ackState == AckState.Acked,
                UniqueTimestampInTicks = timestamp.Ticks,
                TransportMessage       = new byte[0]
            };

            DataContext.PersistentMessages.Insert(message).Execute();
        }
Ejemplo n.º 9
0
        private void InsertPersistentMessage(PeerId peerId, DateTime timestamp, Action <PersistentMessage> updateMessage = null)
        {
            var message = new PersistentMessage
            {
                PeerId   = peerId.ToString(),
                BucketId = BucketIdHelper.GetBucketId(timestamp),
                IsAcked  = true,
                UniqueTimestampInTicks = timestamp.Ticks,
                TransportMessage       = new byte[0]
            };

            updateMessage?.Invoke(message);
            DataContext.PersistentMessages.Insert(message).Execute();
        }
Ejemplo n.º 10
0
        public MessageBookmark MoveTo(string subQueue, PersistentMessage message)
        {
            _messages.MoveTo(message.Bookmark);
            var id       = _messages.GetMessageId();
            var bookmark = _messages.Update(() =>
            {
                _messages.ForColumnType <IntColumn>().Set("status", (int)MessageStatus.SubqueueChanged);
                _messages.ForColumnType <StringColumn>().Set("subqueue", subQueue);
            });

            bookmark.QueueName = _queueName;
            _logger.Debug("Moving message {0} to subqueue {1}", id, _queueName);
            return(bookmark);
        }
Ejemplo n.º 11
0
        private PersistentMessage PeekMessageFromQueue(string queueName, string subqueue)
        {
            AssertNotDisposedOrDisposing();
            PersistentMessage message = null;

            queueStorage.Global(actions =>
            {
                message = actions.GetQueue(queueName).Peek(subqueue);

                actions.Commit();
            });
            if (message != null)
            {
                logger.DebugFormat("Peeked message with id '{0}' from '{1}/{2}'",
                                   message.Id, queueName, subqueue);
            }
            return(message);
        }
        private IPersistentRepresentation GetPersistentRepresentation(PersistentMessage message)
        {
            IActorRef sender = ActorRefs.NoSender;

            if (message.Sender != null)
            {
                sender = system.Provider.ResolveActorRef(message.Sender);
            }

            return(new Persistent(
                       GetPayload(message.Payload),
                       message.SequenceNr,
                       message.PersistenceId,
                       message.Manifest,
                       message.Deleted,
                       sender,
                       message.WriterGuid));
        }
Ejemplo n.º 13
0
        private PersistentMessage.Builder PersistentToProto(IPersistentRepresentation p)
        {
            var builder = PersistentMessage.CreateBuilder();

            if (p.PersistenceId != null)
            {
                builder.SetPersistenceId(p.PersistenceId);
            }
            if (p.Sender != null)
            {
                builder.SetSender(Akka.Serialization.Serialization.SerializedActorPath(p.Sender));
            }

            builder
            .SetPayload(PersistentPayloadToProto(p.Payload))
            .SetSequenceNr(p.SequenceNr)
            .SetDeleted(p.IsDeleted);

            return(builder);
        }
Ejemplo n.º 14
0
        private PersistentMessage GetMessageFromQueue(ITransaction transaction, string queueName, string subqueue)
        {
            AssertNotDisposedOrDisposing();
            PersistentMessage message = null;

            queueStorage.Global(actions =>
            {
                message = actions.GetQueue(queueName).Dequeue(subqueue);

                if (message != null)
                {
                    actions.RegisterUpdateToReverse(
                        transaction.Id,
                        message.Bookmark,
                        MessageStatus.ReadyToDeliver,
                        subqueue);
                }

                actions.Commit();
            });
            return(message);
        }
        private void CreateUpdateSymbolWithPM(PersistentMessage pm, int currentStartPhase, int currentEndPhase)
        {
            // is this an update or a new symbol
            var foundSymbol = _phaseSymbols.FirstOrDefault(sl => sl.ItemSVM.Model.Values.ContainsKey(Message.IdPropertyName) && sl.ItemSVM.Model.Values[Message.IdPropertyName] == pm.ID);

            //if (foundSymbol != null && foundSymbol.Any())
            if (foundSymbol != null)
            {
                // symbol is in list, do an update
                var ps = foundSymbol;//.ElementAt(0);

                ps.EndPhase = currentEndPhase;
            }
            else
            {
                // symbol is missing, ADD a new one
                PropertyItem first = pm.PropertyItems.FirstOrDefault(pi => pi.Key == "sic");

                if (first != null)
                {
                    var psvm = new PhaseSymbolViewModel
                    {
                        StartPhase        = currentStartPhase,
                        EndPhase          = currentEndPhase,
                        ItemSVM           = SymbolLoader.Search(first.Value),
                        VisibleTimeExtent = pm.VisibleTimeExtent
                    };

                    // create SVM
                    if (!psvm.ItemSVM.Model.Values.ContainsKey(Message.IdPropertyName))
                    {
                        psvm.ItemSVM.Model.Values.Add(Message.IdPropertyName, pm.ID);
                    }

                    _phaseSymbols.Add(psvm);
                }
            }
        }
Ejemplo n.º 16
0
        public MessageBookmark MoveTo(string subQueue, PersistentMessage message)
        {
            Api.JetGotoBookmark(session, msgs, message.Bookmark.Bookmark, message.Bookmark.Size);
            var id = new MessageId
            {
                MessageIdentifier = new Guid(Api.RetrieveColumn(session, msgs, msgsColumns["msg_id"])),
                SourceInstanceId  = new Guid(Api.RetrieveColumn(session, msgs, msgsColumns["instance_id"]))
            };

            using (var update = new Update(session, msgs, JET_prep.Replace))
            {
                Api.SetColumn(session, msgs, msgsColumns["status"], (int)MessageStatus.SubqueueChanged);
                Api.SetColumn(session, msgs, msgsColumns["subqueue"], subQueue, Encoding.Unicode);

                var bookmark = new MessageBookmark {
                    QueueName = queueName
                };
                update.Save(bookmark.Bookmark, bookmark.Size, out bookmark.Size);

                logger.DebugFormat("Moving message {0} to subqueue {1}",
                                   id, queueName);
                return(bookmark);
            }
        }
Ejemplo n.º 17
0
        public void EnqueueDirectlyTo(string queue, string subqueue, MessagePayload payload)
        {
            EnsureEnlistment();

            var message = new PersistentMessage
            {
                Data    = payload.Data,
                Headers = payload.Headers,
                Id      = new MessageId
                {
                    SourceInstanceId  = queueStorage.Id,
                    MessageIdentifier = GuidCombGenerator.Generate()
                },
                Queue    = queue,
                SentAt   = DateTime.Now,
                SubQueue = subqueue,
                Status   = MessageStatus.EnqueueWait
            };

            queueStorage.Global(actions =>
            {
                var queueActions = actions.GetQueue(queue);

                var bookmark = queueActions.Enqueue(message);
                actions.RegisterUpdateToReverse(Enlistment.Id, bookmark, MessageStatus.EnqueueWait, subqueue);

                actions.Commit();
            });

            OnMessageQueuedForReceive(message);

            lock (newMessageArrivedLock)
            {
                Monitor.PulseAll(newMessageArrivedLock);
            }
        }
Ejemplo n.º 18
0
        public PersistentMessage Dequeue(string subqueue)
        {
            Api.JetSetCurrentIndex(session, msgs, "by_sub_queue");
            Api.MakeKey(session, msgs, subqueue, Encoding.Unicode, MakeKeyGrbit.NewKey);

            if (Api.TrySeek(session, msgs, SeekGrbit.SeekGE) == false)
            {
                return(null);
            }

            Api.MakeKey(session, msgs, subqueue, Encoding.Unicode, MakeKeyGrbit.NewKey | MakeKeyGrbit.FullColumnEndLimit);
            try
            {
                Api.JetSetIndexRange(session, msgs, SetIndexRangeGrbit.RangeInclusive | SetIndexRangeGrbit.RangeUpperLimit);
            }
            catch (EsentErrorException e)
            {
                if (e.Error != JET_err.NoCurrentRecord)
                {
                    throw;
                }
                return(null);
            }

            do
            {
                var id = new MessageId
                {
                    MessageIdentifier = new Guid(Api.RetrieveColumn(session, msgs, msgsColumns["msg_id"])),
                    SourceInstanceId  = new Guid(Api.RetrieveColumn(session, msgs, msgsColumns["instance_id"]))
                };

                var status = (MessageStatus)Api.RetrieveColumnAsInt32(session, msgs, msgsColumns["status"]).Value;

                logger.DebugFormat("Scanning incoming message {2} on '{0}/{1}' with status {3}",
                                   queueName, subqueue, id, status);

                if (status != MessageStatus.ReadyToDeliver)
                {
                    continue;
                }

                try
                {
                    using (var update = new Update(session, msgs, JET_prep.Replace))
                    {
                        Api.SetColumn(session, msgs, msgsColumns["status"], (int)MessageStatus.Processing);
                        update.Save();
                    }
                }
                catch (EsentErrorException e)
                {
                    logger.DebugFormat("Write conflict on '{0}/{1}' for {2}, skipping message",
                                       queueName, subqueue, id);
                    if (e.Error == JET_err.WriteConflict)
                    {
                        continue;
                    }
                    throw;
                }
                var bookmark = new MessageBookmark {
                    QueueName = queueName
                };
                Api.JetGetBookmark(session, msgs, bookmark.Bookmark, bookmark.Size, out bookmark.Size);
                changeNumberOfMessages(-1);

                logger.DebugFormat("Dequeuing message {2} from '{0}/{1}'",
                                   queueName, subqueue, id);

                var headersAsQueryString = Api.RetrieveColumnAsString(session, msgs, msgsColumns["headers"]);

                var message = new PersistentMessage
                {
                    Bookmark = bookmark,
                    Headers  = HttpUtility.ParseQueryString(headersAsQueryString),
                    Queue    = queueName,
                    SentAt   = DateTime.FromOADate(Api.RetrieveColumnAsDouble(session, msgs, msgsColumns["timestamp"]).Value),
                    Data     = Api.RetrieveColumn(session, msgs, msgsColumns["data"]),
                    Id       = id,
                    SubQueue = subqueue,
                    Status   = (MessageStatus)Api.RetrieveColumnAsInt32(session, msgs, msgsColumns["status"]).Value
                };
                return(message);
            } while (Api.TryMoveNext(session, msgs));

            return(null);
        }
Ejemplo n.º 19
0
 private IPersistentRepresentation PersistentMessageFrom(PersistentMessage persistentMessage)
 {
     return new Persistent(
         payload: PayloadFromProto(persistentMessage.Payload),
         sequenceNr: persistentMessage.SequenceNr,
         persistenceId: persistentMessage.HasPersistenceId ? persistentMessage.PersistenceId : null,
         manifest: persistentMessage.HasManifest ? persistentMessage.Manifest : null,
         // isDeleted is not used in new records from 1.5
         sender: persistentMessage.HasSender ? system.Provider.ResolveActorRef(persistentMessage.Sender) : null,
         writerGuid: persistentMessage.HasWriterUuid ? persistentMessage.WriterUuid : null);
 }
Ejemplo n.º 20
0
        private IPersistentRepresentation PersistentMessageFrom(byte[] bytes)
        {
            var persistentMessage = PersistentMessage.ParseFrom(bytes);

            return(PersistentMessageFrom(persistentMessage));
        }