private static void PrefetchSnippetsResponseHandler(IAsyncResult ar) { ReqContext2 rc = (ReqContext2)ar.AsyncState; ArrayList nwHits = rc.GetNwHits; BeagleWebService wsp = rc.GetProxy; try { Beagle.Daemon.HitSnippet[] hslist = wsp.EndGetSnippets(ar); int j = 0; if (hslist.Length > 0) { log.Debug("PrefetchSnippetsResponseHandler: Got {0} snippet responses from {1}", hslist.Length, wsp.Hostname); foreach (Beagle.Daemon.HitSnippet hs in hslist) { int i, hitHashCode; string snippet; try { hitHashCode = hs.hashCode; snippet = hs.snippet; } catch (Exception ex2) { log.Warn("Exception in WebBackEnd: PrefetchSnippetsResponseHandler(), while getting snippet from {1}\n Reason: {2} ", wsp.Hostname + ":" + wsp.Port, ex2.Message); continue; } if (snippet.StartsWith(WebServiceBackEnd.InvalidHitSnippetError)) { continue; } for (i = 0; i < nwHits.Count; i++) { if (((NetContext)((NetworkHit)nwHits[i]).context).hashCode == hitHashCode) { ((NetworkHit)nwHits[i]).snippet = snippet; //log.Debug("\nPrefetchSnippetsResponseHandler: URI" + j++ + "=" + ((NetworkHit)nwHits[i]).UriAsString + "\n Snippet=" + snippet); break; } } if (i < nwHits.Count) { nwHits.RemoveAt(i); } } //end foreach } } catch (Exception ex) { log.Error("Exception in WebBackEnd: PrefetchSnippetsResponseHandler() - {0} - for {1} ", ex.Message, wsp.Hostname + ":" + wsp.Port); } if (nwHits.Count > 0) { //Possible Error in getting snippets for these hitIds log.Warn("WebBackEnd/PrefetchSnippetsResponseHandler(): Didn't get Snippets for some network Hits"); foreach (NetworkHit nh in nwHits) { nh.snippet = ""; } } //Signal change in TileHitCollection due to addition of snippets: rc.GetHitCollection.ClearSources(null); }
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 }
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 }