///////////////////////////////////////////////////////// private RemoteIndexerResponse SendRequest(RemoteIndexerRequest request) { RemoteIndexerResponse response = null; int exception_count = 0; bool start_helper_by_hand = false; if (Environment.GetEnvironmentVariable("BEAGLE_RUN_HELPER_BY_HAND") != null) { start_helper_by_hand = true; } request.RemoteIndexName = remote_index_name; request.RemoteIndexMinorVersion = remote_index_minor_version; while (response == null && exception_count < 5 && !Shutdown.ShutdownRequested) { bool need_helper = false; //Logger.Log.Debug ("Sending request!"); try { response = request.Send() as RemoteIndexerResponse; //Logger.Log.Debug ("Done sending request"); } catch (ResponseMessageException ex) { Logger.Log.Debug("Caught ResponseMessageException: {0}", ex.Message); if (ex.InnerException is System.Net.Sockets.SocketException) { Logger.Log.Debug("InnerException is SocketException -- we probably need to launch a helper"); need_helper = true; } else if (ex.InnerException is IOException) { Logger.Log.Debug("InnerException is IOException -- we probably need to launch a helper"); need_helper = true; } else { Logger.Log.Debug(ex, "Unexpected exception from IndexHelper. Giving up sending this request."); return(null); } } // If we caught an exception... if (response == null) { if (!start_helper_by_hand || !need_helper) { ++exception_count; } if (start_helper_by_hand) { // Sleep briefly before trying again. Thread.Sleep(1000); } else { // Try to activate the helper. LaunchHelper(); } } } if (response == null && exception_count >= 5) { Logger.Log.Error("Exception limit exceeded trying to activate a helper. Giving up on indexing!"); } return(response); }
public override ResponseMessage Execute (RequestMessage raw_request) { RemoteIndexerRequest remote_request = (RemoteIndexerRequest) raw_request; IndexHelperTool.ReportActivity (); // Find the appropriate driver for this request. LuceneIndexingDriver indexer; lock (indexer_table) { indexer = (LuceneIndexingDriver) indexer_table [remote_request.RemoteIndexName]; if (indexer == null) { indexer = new LuceneIndexingDriver (remote_request.RemoteIndexName, remote_request.RemoteIndexMinorVersion); indexer.DisableTextCache = IndexHelperTool.DisableTextCache; indexer_table [remote_request.RemoteIndexName] = indexer; indexer.FileFilterNotifier += delegate (Uri display_uri, Uri content_uri, Filter filter) { IndexHelperTool.ReportActivity (); IndexHelperTool.CurrentDisplayUri = display_uri; IndexHelperTool.CurrentContentUri = content_uri; IndexHelperTool.CurrentFilter = filter; }; } } IndexerReceipt [] receipts = null; int item_count = 0; try { if (remote_request.Request != null) // If we just want the item count, this will be null receipts = indexer.Flush (remote_request.Request); item_count = indexer.GetItemCount (); } catch (Exception e) { // Send error response ++Count; return new ErrorResponse (e); } // Construct a response containing the item count and // the receipts produced by the actual indexing. RemoteIndexerResponse response = new RemoteIndexerResponse (); response.ItemCount = item_count; response.Receipts = receipts; ++Count; IndexHelperTool.ReportActivity (); return response; }