Esempio n. 1
0
    public RBSubscriber(string t, SubscribeDelegate <T> h)
    {
        Topic = t;
        SubscribeManager <T> manager = new SubscribeManager <T>(t, h, RBSocket.Instance.IDCount.ToString());

        RBSocket.Instance.AddSubscribeManager(manager);
    }
Esempio n. 2
0
 public void add(int id, SubscribeDelegate callback)
 {
     lock (subscribes)
     {
         if (!subscribes.ContainsKey(id))
         {
             subscribes[id] = new List <SubscribeDelegate>();
         }
         subscribes[id].Add(callback);
     }
 }
Esempio n. 3
0
        private void Subscribe()
        {
            if (ConnectionState != ConnctionStates.Init)
            {
                throw new InvalidOperationException("Estado incorrecto, no puede suscribir.");
            }
            ConnectionState = ConnctionStates.Trying;
            var d = new SubscribeDelegate(AsyncSubscribe);

            d.BeginInvoke(AsyncSubscribeComplete, d);
        }
Esempio n. 4
0
    public bool SubscribeToRoutingKey(string routingKey, SubscribeDelegate callback)
    {
        if (!isConnected)
        {
            return(false);
        }

        lock (_lock)
        {
            if (RabbitNativeMethods.ConnectToExchange(serverConnection, "stealth", routingKey) == IntPtr.Zero)
            {
                Debug.LogWarning("Failed to connect to exchange");
            }
            funcDict[routingKey] = callback;
        }

        return(true);
    }
Esempio n. 5
0
        public void subscribe(string channel, SubscribeDelegate callback)
        {
            var         sub  = GetInstanceID();
            Subscribers subs = null;

            lock (channelsByKey)
            {
                if (!channelsByKey.ContainsKey(channel))
                {
                    channelsByKey[channel] = new Subscribers(channel);
                }
                subs = channelsByKey[channel];
            }
            subs.add(sub, callback);
            lock (channelsBySub)
            {
                if (!channelsBySub.ContainsKey(sub))
                {
                    channelsBySub[sub] = new List <Subscribers>();
                }
                channelsBySub[sub].Add(subs);
            }
        }
Esempio n. 6
0
 public void RemoveSubscriber(SubscribeDelegate sub)
 {
     //Console.WriteLine("....Removing Subscriber");
     Subscribe -= sub;
 }
Esempio n. 7
0
 public void AddSubscriber(SubscribeDelegate sub)
 {
     Subscribe += sub;
 }
 public int Subscribe(SubscribeDelegate sd)
 {
     m_sd = sd;
     return 0;
 }
        protected void EnqueueWaitEventEventAction(Func <FrameworkElement> getElementDelegate, Action action, SubscribeDelegate subscribeDelegate)
        {
#if SILVERLIGHT
            bool eventFired = false;
            EnqueueCallback(() => subscribeDelegate(getElementDelegate, delegate { eventFired = true; }));
            EnqueueCallback(action);
            EnqueueConditional(() => eventFired);
#else
            action();
#endif
        }
Esempio n. 10
0
 public RabbitChannel(SubscribeDelegate handler, AliveObject <IModel> model)
 {
     Handler = handler;
     Model   = model;
     _       = model.Value;
 }
Esempio n. 11
0
 protected void EnqueueWaitEventEventAction(Func <FrameworkElement> getElementDelegate, Action action, SubscribeDelegate subscribeDelegate)
 {
     action();
 }
Esempio n. 12
0
        public void subscribe(SubscribeMessage msg)
        {
            string origin_site = msg.interested_site;
            int en = getEventnum();

            if (origin_site == null)
            {
                lock (_topicSubscribers)
                {
                    if (!_topicSubscribers.ContainsKey(msg.topic))
                    {
                        _topicSubscribers.Add(msg.topic, new List<string>());
                    }
                    //Discart possible duplicates
                    if (_topicSubscribers[msg.topic].Contains(msg.uri))
                        return;
                    else
                    {
                        _topicSubscribers[msg.topic].Add(msg.uri);
                    }

                }
            }
            else
            {
                lock (_topicSites)
                {
                    if (!_topicSites.ContainsKey(msg.topic))
                    {
                        _topicSites.Add(msg.topic, new List<string>());
                    }
                    //Discart possible duplicates
                    if (_topicSites[msg.topic].Contains(msg.interested_site))
                        return;
                    else
                    {
                        _topicSites[msg.topic].Add(msg.interested_site);
                    }
                }
            }
            //Doon't print discarted msg
            if (origin_site == null)
            {
                log(en, "[Subscribe] received" + msg.ToString());
            }
            else
            {
                log(en, "[Propagate subscribe] received" + msg.ToString());
            }

            msg.interested_site = _site;
            // propagate subscribe to parent, taking advantage of tree strucure
            lock (_parentSiteLock)
            {
                if (_parentSite != null)
                {
                    if (origin_site == null || _parentSite.name != origin_site)
                    {
                        lock (_siteToPropagatedSub)
                        {
                            if (!_siteToPropagatedSub.ContainsKey(_parentSite.name))
                            {
                                _siteToPropagatedSub.Add(_parentSite.name, new Dictionary<string, int>());
                            }

                            if (!_siteToPropagatedSub[_parentSite.name].ContainsKey(msg.topic))
                            {
                                _siteToPropagatedSub[_parentSite.name].Add(msg.topic, 1);
                                log(en, string.Format("[Subscribe] Sending {0} to parent site {1}", msg, _parentSite.name));
                                foreach (var b in _parentSite.brokers)
                                {
                                    SubscribeDelegate sd = new SubscribeDelegate(b.subscribe);
                                    sd.BeginInvoke(msg, null, null);
                                }
                            }
                            else
                            {
                                var num = _siteToPropagatedSub[_parentSite.name][msg.topic];
                                num++;
                                _siteToPropagatedSub[_parentSite.name][msg.topic] = num;

                            }
                        }
                    }
                }
            }

            lock (_childSites)
            {
                foreach (var s in _childSites)
                {

                    lock (s)
                    {
                        if (origin_site == null || s.name != origin_site)
                        {
                            lock (_siteToPropagatedSub)
                            {
                                if (!_siteToPropagatedSub.ContainsKey(s.name))
                                {
                                    _siteToPropagatedSub.Add(s.name, new Dictionary<string, int>());
                                }

                                if (!_siteToPropagatedSub[s.name].ContainsKey(msg.topic))
                                {
                                    _siteToPropagatedSub[s.name].Add(msg.topic, 1);
                                    log(en, string.Format("[Subscribe] Sending {0} to child site {1}", msg, s.name));
                                    foreach (var b in s.brokers)
                                    {
                                        SubscribeDelegate sd = new SubscribeDelegate(b.subscribe);
                                        sd.BeginInvoke(msg, null, null);
                                    }
                                }
                                else
                                {
                                    var num = _siteToPropagatedSub[s.name][msg.topic];
                                    num++;
                                    _siteToPropagatedSub[s.name][msg.topic] = num;

                                }
                            }
                        }

                    }
                }
            }

            /* if (origin_site == null)
             {
                 log(en, "Subscribe finished");
             }
             else
             {
                 log(en, "Propagate subscribe finished");
             }*/
        }