Пример #1
0
        override public void Start()
        {
            Channel returns = new Channel();

            returns.EnqueueEvent += delegate(object o, EventArgs ea) {
                while (returns.Count > 0)
                {
                    Hashtable result = null;
                    try {
                        result = returns.Dequeue() as Hashtable;
                    } catch {
                        continue;
                    }

                    byte[] res = result["value"] as byte[];
                    if (res != null)
                    {
                        Results.Enqueue(MemBlock.Reference(res));
                    }
                }
                if (_enqueue != null)
                {
                    _enqueue(this, EventArgs.Empty);
                }
            };

            returns.CloseEvent += delegate(object o, EventArgs ea) {
                Finished();
            };

            Dht dht = new Dht(Node, 3, 20);

            dht.AsyncGet(Key, returns);
        }
Пример #2
0
        public void SerialAsyncGet(object data)
        {
            Hashtable ht = (Hashtable)data;

            byte[]   key = (byte[])ht["key"];
            byte[][] expected_results = (byte[][])ht["results"];
            int      op = (int)ht["op"];

            try {
                BlockingQueue queue = new BlockingQueue();
                default_dht.AsyncGet(key, queue);
                bool found       = false;
                int  found_count = 0;
                while (true)
                {
                    Hashtable dgr = null;
                    try {
                        dgr = (Hashtable)queue.Dequeue();
                    }
                    catch (Exception) {
                        break;
                    }
                    for (int j = 0; j < expected_results.Length; j++)
                    {
                        if (ArrayComparer((byte[])dgr["value"], expected_results[j]))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        found_count++;
                        found = false;
                    }
                }
                if (found_count != expected_results.Length)
                {
                    lock (_lock) {
                        Console.WriteLine("Failed get... attempted to get " +
                                          expected_results.Length + " found " + found_count +
                                          " operation: " + op);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine("Failure at operation: " + op);
                Console.WriteLine(e);
                throw e;
            }
        }