Esempio n. 1
0
		public IndexerReceipt [] Flush (IndexerRequest request)
		{
			// If there isn't actually any work to do, just return
			// an empty array.
			if (request.IsEmpty)
				return new IndexerReceipt [0];

			// Iterate through the items in the IndexerRequest to
			// store the streams before passing them to the helper.
			foreach (Indexable indexable in request.Indexables) {
				if (indexable.Type == IndexableType.Add)
					indexable.StoreStream ();
			}

			RemoteIndexerRequest remote_request;
			remote_request = new RemoteIndexerRequest ();
			remote_request.RemoteIndexName = this.remote_index_name;
			remote_request.RemoteIndexMinorVersion = this.remote_index_minor_version;
			remote_request.Request = request;
			
			RemoteIndexerResponse response;
			response = SendRequest (remote_request);

			if (response == null) {
				Logger.Log.Error ("Something terrible happened --- Flush failed");
				request.Cleanup ();
				return null;
			}
			
			last_item_count = response.ItemCount;

			return response.Receipts;
		}
Esempio n. 2
0
        public IndexerReceipt [] Flush(IndexerRequest request)
        {
            // If there isn't actually any work to do, just return
            // an empty array.
            if (request.IsEmpty)
            {
                return(new IndexerReceipt [0]);
            }

            // Iterate through the items in the IndexerRequest to
            // store the streams before passing them to the helper.
            foreach (Indexable indexable in request.Indexables)
            {
                if (indexable.Type == IndexableType.Add)
                {
                    indexable.StoreStream();
                }
            }

            RemoteIndexerRequest remote_request;

            remote_request = new RemoteIndexerRequest();
            remote_request.RemoteIndexName         = this.remote_index_name;
            remote_request.RemoteIndexMinorVersion = this.remote_index_minor_version;
            remote_request.Request = request;

            RemoteIndexerResponse response;

            response = SendRequest(remote_request);

            if (response == null)
            {
                Logger.Log.Error("Something terrible happened --- Flush failed");
                request.Cleanup();
                return(null);
            }

            last_item_count = response.ItemCount;

            return(response.Receipts);
        }
Esempio n. 3
0
        public int GetItemCount()
        {
            if (last_item_count == -1)
            {
                // Send an empty indexing request to cause the last item count to be
                // initialized.
                RemoteIndexerRequest request;
                request = new RemoteIndexerRequest();

                RemoteIndexerResponse response;
                response = SendRequest(request);
                if (response != null)
                {
                    last_item_count = response.ItemCount;
                }
                else
                {
                    Logger.Log.Error("Something terrible happened --- GetItemCount failed");
                }
            }

            return(last_item_count);
        }
Esempio n. 4
0
		/////////////////////////////////////////////////////////

		private RemoteIndexerResponse SendRequest (RemoteIndexerRequest request)
		{
			RemoteIndexerResponse response = null;
			int exception_count = 0;
			bool start_helper_by_hand = false;

			if (Environment.GetEnvironmentVariable ("BEAGREP_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;
		}
Esempio n. 5
0
		public int GetItemCount ()
		{
			if (last_item_count == -1) {
				// Send an empty indexing request to cause the last item count to be
				// initialized.
				RemoteIndexerRequest request;
				request = new RemoteIndexerRequest ();

				RemoteIndexerResponse response;
				response = SendRequest (request);
				if (response != null)
					last_item_count = response.ItemCount;
				else
					Logger.Log.Error ("Something terrible happened --- GetItemCount failed");
			}

			return last_item_count;
		}
Esempio n. 6
0
        /////////////////////////////////////////////////////////

        private RemoteIndexerResponse SendRequest(RemoteIndexerRequest request)
        {
            RemoteIndexerResponse response = null;
            int  exception_count           = 0;
            bool start_helper_by_hand      = false;

            if (Environment.GetEnvironmentVariable("BEAGREP_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);
        }