Пример #1
0
        public void AddSink(string topic, string ip, int port, bool staticRoute)
        {
            IpPortPair ipp = new IpPortPair(ip, port, staticRoute);

            if (this.topicSinkMap.ContainsKey(topic))
            {
                Entry_T dict = this.topicSinkMap[topic];

                //If created as static route, we only add sinks that are static
                if ((!dict.staticRoute) || (dict.staticRoute && staticRoute))
                {
                    //Check if sink already exist
                    if (dict.portMap.ContainsKey(ipp.Key))
                    {
                        dict.portMap[ipp.Key].FeedWatchdog(staticRoute);
                    }
                    else
                    {
                        dict.portMap.Add(ipp.Key, ipp);
                    }
                }
            }
            else
            {
                Entry_T dict = new Entry_T(staticRoute);
                dict.portMap.Add(ipp.Key, ipp);
                this.topicSinkMap.Add(topic, dict);
            }
        }
Пример #2
0
        public override bool SendData(byte[] bytes, int size, Topic t)
        {
            bool result = true;

            if (this.topicSinkMap.ContainsKey(t.GetName()))
            {
                Entry_T       dict          = this.topicSinkMap[t.GetName()];
                List <string> sinksToDelete = new List <string>();

                // Loop over all sinks and send data, remove items that isn't "alive".
                foreach (KeyValuePair <string, IpPortPair> kvp in dict.portMap)
                {
                    // Check if this sink is alive
                    if (kvp.Value.IsAlive())
                    {
                        result &= SendData(bytes, size, InetAddress.GetByName(kvp.Value.Ip), kvp.Value.Port);
                    }
                    else //Remove it.
                    {
                        sinksToDelete.Add(kvp.Key);
                    }
                }
                foreach (string key in sinksToDelete)
                {
                    dict.portMap.Remove(key);
                }
            }
            return(result);
        }