public ReqContext2(BeagleWebService wsp, ArrayList nwHits, BT.TileHitCollection thc) { this._thc = thc; this._wsp = wsp; this._nwHits = nwHits; }
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 }