Example #1
0
        /**
         * Invoked when the request channel is closed.
         */
        protected void CloseHandler(object o, EventArgs args)
        {
            RequestState request = null;

            lock (_sync) {
                //retrieve the request state assiciated with the closed channel
                request = (RequestState)_channel_to_state[o];
                if (request == null)
                {
                    //cannot happen
                    Console.Error.WriteLine("VTS unable to retrieve request for a closed channel");
                    return;
                }
#if VTS_DEBUG
                Console.Error.WriteLine("VTS local: {0}, start: {1} channel closed.", _node.Address, request.Start);
#endif
                _channel_to_state.Remove(o);
                _num_requests--;
            }

            /**
             * The request object has been removed the shared data structure.
             *  Since no one alse has access to it, it can be accessed outside the lock.
             */

            SortedList sorted_result = new SortedList();
#if VTS_DEBUG
            SortedList sorted_stat = new SortedList();
#endif
            NCService.VivaldiState local_vs = _nc_service.State;
            foreach (Address target in request.ResultTable.Keys)
            {
                object[] curr_result      = (object[])request.ResultTable[target];
                NCService.VivaldiState vs = (NCService.VivaldiState)curr_result[0];
                double d = local_vs.Position.GetEucledianDistance(vs.Position);
                sorted_result[d] = target;
#if VTS_DEBUG
                Console.Error.WriteLine("VTS local: {0}, start: {1}, dest: {2}, distance: {3}",
                                        _node.Address, request.Start, target, d);
                string host = (string)curr_result[1];
                sorted_stat[d] = new object[] { d, host };
#endif
            }

#if VTS_DEBUG
            lock (_sync) {
                _query_list.Add(sorted_stat);
            }
#endif
            request.Callback(request.Start, sorted_result, request.Current);
        }
Example #2
0
        /**
         * Invoked when a result is enqueued into the channel.
         */
        protected void EnqueueHandler(object o, EventArgs args)
        {
            Channel q             = (Channel)o;
            bool    close_channel = false;

            lock (_sync) {
                try {
                    RpcResult result          = q.Dequeue() as RpcResult;
                    Hashtable ht              = (Hashtable)result.Result;
                    Hashtable ht_position     = (Hashtable)ht["position"];
                    NCService.VivaldiState vs = new NCService.VivaldiState();
                    vs.Position      = new Point((double[])((ArrayList)ht_position["side"]).ToArray(typeof(double)), (double)ht_position["height"]);
                    vs.WeightedError = (double)ht["error"];
                    ForwardingSender fs = result.ResultSender as ForwardingSender;
                    //record this information in the request state.
                    RequestState request = (RequestState)_channel_to_state[q];
                    if (request != null)
                    {
                        //make sure this is not our own reply
                        if (!fs.Destination.Equals(_node.Address))
                        {
#if VTS_DEBUG
                            Console.Error.WriteLine("VTS local: {0}, start: {1}, dest: {2}", _node.Address, request.Start, fs.Destination);
#endif
                            request.ResultTable[fs.Destination] = new object[] { vs, (string)ht["hostname"] };
                        }
                        if (request.ResultTable.Keys.Count >= (int)request.Range * 0.75)
                        {
                            close_channel = true;
                        }
                    }
                } catch {}
            }
            if (close_channel)
            {
                q.Close();
            }
        }
Example #3
0
    /**
     * Invoked when a result is enqueued into the channel.
     */
    protected void EnqueueHandler(object o, EventArgs args) {
      Channel q = (Channel) o;
      bool close_channel = false;
      lock(_sync) {
        try {
          RpcResult result = q.Dequeue() as RpcResult;
          Hashtable ht = (Hashtable) result.Result;
          Hashtable ht_position = (Hashtable) ht["position"];
          NCService.VivaldiState vs = new NCService.VivaldiState();
          vs.Position = new Point((double[]) ((ArrayList) ht_position["side"]).ToArray(typeof(double)), (double) ht_position["height"]);
          vs.WeightedError = (double) ht["error"];
          ForwardingSender fs = result.ResultSender as ForwardingSender;
          //record this information in the request state.
          RequestState request = (RequestState) _channel_to_state[q];
          if (request != null) {
            //make sure this is not our own reply
            if (!fs.Destination.Equals(_node.Address)) {
#if VTS_DEBUG
              Console.Error.WriteLine("VTS local: {0}, start: {1}, dest: {2}", _node.Address, request.Start, fs.Destination);
#endif
              request.ResultTable[fs.Destination] = new object[] {vs, (string) ht["hostname"]};
            }
            if (request.ResultTable.Keys.Count >= (int) request.Range*0.75) {
              close_channel = true;
            }
          }
        } catch {}
      }
      if (close_channel) {
        q.Close();
      }
    }