예제 #1
0
 public ReqContext(BeagleWebService wsp, IQueryResult result, IQueryable iq)
 {
     this.wsp          = wsp;
     this.result       = result;
     this.iq           = iq;
     this.reqProcessed = false;
 }
예제 #2
0
        public NetBeagleHandler(string hostname, string port, IQueryable iq)
        {
            this.Hostname      = hostname;
            this.Port          = port;
            netBeagleQueryable = iq;

            log.Info("Instantiating NetBeagleHandler for " + Hostname + ":" + Port);

            wsp         = new BeagleWebService(Hostname, Port);
            wsp.Timeout = 40000;             //40 sec time limit per request
        }
예제 #3
0
		public NetBeagleHandler (string hostname, string port, IQueryable iq)
		{
			this.Hostname = hostname;
			this.Port = port;
			netBeagleQueryable = iq;
			
			log.Info ("Instantiating NetBeagleHandler for " + Hostname + ":" + Port);
			
			wsp = new BeagleWebService (Hostname, Port);
			wsp.Timeout = 40000; //40 sec time limit per request 
		}			
예제 #4
0
        public static void DoQueryResponseHandler(IAsyncResult ar)
        {
            ReqContext rc = (ReqContext)ar.AsyncState;

            IQueryable       iq     = rc.GetQueryable;
            BeagleWebService wsp    = rc.GetProxy;
            IQueryResult     result = rc.GetResult;

            int count = 0;

            //bool hitRejectsLogged = false;

            try
            {
                SearchResult resp = wsp.EndBeagleQuery(ar);

                if ((resp != null) && (resp.numResults > 0))
                {
                    if (rc.SearchToken == null)
                    {
                        rc.SearchToken = resp.searchToken;
                    }

                    //NetContext nc = new NetContext(wsp, resp.searchToken);
                    HitResult[] hres   = resp.hitResults;
                    ArrayList   nwhits = new ArrayList();

                    for (int i = 0; i < hres.Length; i++)
                    {
                        try {
                            HitResult hr  = hres[i];
                            Hit       hit = new NetworkHit();

                            //[Uri Format] netbeagle://164.99.153.134:8888/searchToken?http:///....
                            if (hr.uri.StartsWith(NetworkedBeagle.BeagleNetPrefix))
                            {
                                hit.UriAsString = hr.uri;
                            }
                            else
                            {
                                string[] fragments    = hr.uri.Split('/');
                                string   hostNamePort = fragments[2];
                                hit.UriAsString = NetworkedBeagle.BeagleNetPrefix + hostNamePort + "/" + resp.searchToken + "?" + hr.uri;
                            }

                            hit.Type     = hr.resourceType;
                            hit.MimeType = hr.mimeType;
                            hit.Source   = "Network";                                           //hit.Source = hr.source;
                            hit.Score    = hr.score;

                            if (hr.properties.Length > 0)
                            {
                                foreach (HitProperty hp in hr.properties)
                                {
                                    Property p = Property.New(hp.PKey, hp.PVal);
                                    p.IsMutable  = hp.IsMutable;
                                    p.IsSearched = hp.IsSearched;

                                    hit.AddProperty(p);
                                }
                            }

                            //Add Snippet
                            ((NetworkHit)hit).snippet = hr.snippet;

                            //if (hr.snippet != null)
                            //log.Debug("\nNBH: URI" + i + "=" + hr.uri + "\n     Snippet=" + hr.snippet);

                            ((NetworkHit)hit).context = new NetContext(hr.hashCode);

                            //Add NetBeagleQueryable instance
                            hit.SourceObject     = iq;
                            hit.SourceObjectName = ((NetworkedBeagle)iq).Name;

                            nwhits.Add(hit);

                            count++;
                        }
                        catch (Exception ex2) {
                            log.Warn("Exception in NetBeagleHandler: DoQueryResponseHandler() while processing NetworkHit: {0} from {1}\n Reason: {2} ", hres[i].uri, wsp.Hostname + ":" + wsp.Port, ex2.Message);
                            //log.Error ("Exception StackTrace: " + ex.StackTrace);
                        }
                    }                      //end for

                    if (nwhits.Count > 0)
                    {
                        result.Add(nwhits);
                    }

/*
 *                                      if ((! result.Add (nwhits)) && (! hitRejectsLogged))
 *                                      {
 *                                              hitRejectsLogged = true;
 *                                              log.Info("NetBeagleHandler: Network Hits rejected by HitRegulator. Too many Hits!");
 *                                      }
 */
                    log.Info("NetBeagleHandler: DoQueryResponseHandler() Got {0} result(s) from Index {1} from Networked Beagle at {2}", count, resp.firstResultIndex, wsp.Hostname + ":" + wsp.Port);

                    int index = resp.firstResultIndex + resp.numResults;
                    if (index < resp.totalResults)
                    {
                        log.Debug("NetBeagleHandler: DoQueryResponseHandler() invoking GetResults with index: " + index);

                        string searchToken = resp.searchToken;

                        GetResultsRequest req = new GetResultsRequest();
                        req.startIndex  = index;
                        req.searchToken = searchToken;

                        IAsyncResult ar2;
                        ar2 = wsp.BeginGetResults(req, NetBeagleHandler.DoQueryResponseHandler, rc);

                        return;
                    }
                }                 //end if
                else
                {
                    if (resp == null)
                    {
                        log.Warn("NetBeagleHandler: DoQueryResponseHandler() got Null response from EndBeagleQuery() !");
                    }
                }
            }
            catch (Exception ex) {
                log.Error("Exception in NetBeagleHandler: DoQueryResponseHandler() - {0} - for {1} ", ex.Message, wsp.Hostname + ":" + wsp.Port);
            }

            //Signal completion of request handling
            rc.RequestProcessed = true;
        }
예제 #5
0
			public ReqContext2(BeagleWebService wsp, ArrayList nwHits, BT.TileHitCollection thc)
			{
				this._thc = thc;				
				this._wsp = wsp;
				this._nwHits = nwHits;
			}
예제 #6
0
		private bool tenHits = false;		//Flag to do Prefetch check only every 10 hits
		
		private void PrefetchSnippetsForNetworkHits(BT.TileHitCollection thc) 
		{		
			int lastDisplayed = 0;
			
			if (maxDisplayed != 0)
				lastDisplayed = thc.LastDisplayed + 1;
			
			//We have cached snippets for network hits upto maxDisplayed
			if (lastDisplayed < maxDisplayed)	
				return;

			maxDisplayed = thc.LastDisplayed + 1;
			
			//Do Prefetch check once every ten hits
			tenHits = !tenHits;
			if (!tenHits)					
				return; 
				
			if (lastDisplayed < thc.NumResults) {
			
				int limit = 0;
				ArrayList networkHits = new ArrayList();				
				
				if ((thc.NumResults - lastDisplayed) > MAX_HITS_AHEAD)
					limit = lastDisplayed + MAX_HITS_AHEAD;
				else
					limit = thc.NumResults;

				ArrayList hits = _rp.hitsCopy;
				lock (hits.SyncRoot) {
				
					if (limit > hits.Count)
						limit = hits.Count;

					log.Debug("PrefetchSnippets: Scanning result set for Network Hits from {0} to {1}", lastDisplayed, limit); 					
							
					//Get all NetworkHits with snippets field not initialized:
					for (int si = lastDisplayed;  si < limit ; si++)
					{
						if ((hits[si] is NetworkHit) && (((NetworkHit)hits[si]).snippet == null)) 
							networkHits.Add((NetworkHit)hits[si]);
					}
				}

				log.Debug("PrefetchSnippets: Found {0} NetworkHits without snippets", networkHits.Count);
				 
				while (networkHits.Count > 0) {
				
					ArrayList nwHitsPerNode = new ArrayList();
					string hostnamePort = GetHostnamePort((NetworkHit)networkHits[0]);
					
					//Gather NetworkHits from a specific target Networked Beagle
					foreach	(NetworkHit nh in networkHits) 
					{
						string hnp = GetHostnamePort(nh);
						if (hnp == null)
							continue;
							
						if (hnp.Equals(hostnamePort)) {

							if (nwHitsPerNode.Count < MAX_HIT_IDS_PER_REQ)
								nwHitsPerNode.Add(nh);
							else
								break;
						}
					}
											
					//Remove NetworkHits for this Networked Beagle	
					int i = networkHits.Count;
					while (--i >= 0) { 

						string hnp = GetHostnamePort((NetworkHit)networkHits[i]);							
						if ((hnp == null) || hnp.Equals(hostnamePort))
							networkHits.RemoveAt(i);
					}
			
					if (nwHitsPerNode.Count > 0)
					{
						string[] f3 = hostnamePort.Split(':');
						if (f3.Length < 2)
						{
							log.Warn("PrefetchSnippets: Invalid format netBeagle URI in NetworkHit");
							continue; 
						}
						BeagleWebService wsp = new BeagleWebService(f3[0], f3[1]);
							
						string searchToken = GetSearchToken((NetworkHit)nwHitsPerNode[0]);
						
						if (searchToken.Equals("beagle"))  //Check if it is Older version of Beagle networking
							searchToken = null;
							 			
						if (searchToken != null) {
						
							int[] hitHashCodes = new int [nwHitsPerNode.Count];
							for (int j = 0; j < hitHashCodes.Length; j++)
								hitHashCodes[j] = ((NetContext) ((NetworkHit)nwHitsPerNode[j]).context).hashCode;
							
							log.Debug("PrefetchSnippets: Invoking GetSnippets on {0} for {1} hits", wsp.Hostname, nwHitsPerNode.Count);
					
							GetSnippetsRequest sreq = new GetSnippetsRequest();
							sreq.searchToken = searchToken;
							sreq.hitHashCodes = hitHashCodes;
											
							ReqContext2 rc = new ReqContext2(wsp, nwHitsPerNode, thc);
							wsp.BeginGetSnippets(sreq, PrefetchSnippetsResponseHandler, rc);
						}	
						
						//Signal change in TileHitCollection due to addition of snippets:
						//_rp.rootTile.HitCollection.ClearSources(null);										
					}
				} //end while								
			} //end if 
		} 
예제 #7
0
		public ReqContext(BeagleWebService wsp, IQueryResult result, IQueryable iq)
		{
			this.wsp = wsp;
			this.result = result;
			this.iq = iq;
			this.reqProcessed = false;
		}