コード例 #1
0
ファイル: RemoteDispatcher.cs プロジェクト: Kidify/L4p
        bool IRemoteDispatcher.DispatchRemoteMsg(Topic topic, object msg)
        {
            var agents = _rrepo.GetAgents();

            if (agents.IsEmpty())
                return false;

            var json = _json.MsgToJson(msg);
            var hasListeners = false;

            foreach (var agent in agents)
            {
                bool msgShouldBeSent = msg_shoould_be_sent(topic, agent, msg);

                if (msgShouldBeSent == false)
                {
                    Interlocked.Increment(ref _counters.MsgsFiltered);
                    continue;
                }

                hasListeners = true;

                dispatch_to_remote(agent.AgentUri, topic, json);
                Interlocked.Increment(ref _counters.MsgsDispatched);
            }

            return hasListeners;
        }
コード例 #2
0
ファイル: LocalDispatcher.cs プロジェクト: Kidify/L4p
        bool ILocalDispatcher.DispatchLocalMsg(Topic topic, object msg)
        {
            int snapshotId;
            var handlers = _lrepo.GetHandlers(topic.Guid, out snapshotId);

            var hasListeners = dispatch_to_handlers(msg, handlers);
            Interlocked.Increment(ref _counters.LocalMsgs);

            if (hasListeners)
                Interlocked.Increment(ref _counters.LocalMsgsDispatched);

            return hasListeners;
        }
コード例 #3
0
ファイル: JsonEngine.cs プロジェクト: Kidify/L4p
        object IJsonEngine.MsgFromJson(Topic topic, string json)
        {
            var type = topic.Type;

            try
            {
                return
                    JsonConvert.DeserializeObject(json, type);
            }
            catch (Exception ex)
            {
                _log.Warn(ex, "Failed to parse type '{0}' of topic '{1}' from {2}", type.Name, topic.Name, json);
                throw;
            }
        }
コード例 #4
0
ファイル: RemoteDispatcher.cs プロジェクト: Kidify/L4p
        private bool msg_shoould_be_sent(Topic topic, RemoteAgent agent, object msg)
        {
            var topicFilter = get_topic_filter(topic.Guid, agent);

            if (topicFilter == null)
                return true;

            if (topicFilter.Filters.IsEmpty())
                return false;               // topic has no listeners on target

            if (topicFilter.FilterThrows)
                return true;                // there is a local filter but it throws (remote will recalculate filter)

            try
            {
                var filterIsMatched = filter_is_matched(topicFilter.Filters, msg);

                if (filterIsMatched)
                    return true;
            }
            catch (Exception ex)
            {
                topicFilter.FilterThrows = true;
                _log.Warn(ex, "Failed to invoke remote filter for topic {0}", topic.ToJson());
            }

            // no matched filters

            return false;
        }
コード例 #5
0
ファイル: RemoteDispatcher.cs プロジェクト: Kidify/L4p
        private void dispatch_to_remote(string agent, Topic topic, string json)
        {
            var msg = new comm.PublishMsg {
                Topic = topic,
                TopicName = topic.Name,
                TopicGuid = topic.Guid,
                Json = json,
                FromAgent = _myself
            };

            _messenger.SendPublishMsg(agent, msg);
        }