Example #1
0
            private bool OurTimeoutHandler()
            {
#if false
                // Oops, process.HasExited doesn't work in mono.  Grrr.
                if (process.HasExited)
                {
                    Log.Failure("Beagle daemon has terminated unexpectedly - exit code {0}",
                                process.ExitCode);
                    if (started != null)
                    {
                        started(null);
                    }
                    return(false);
                }
#endif

                Beagle.RequestMessage request;
                request = new Beagle.DaemonInformationRequest();

                Beagle.ResponseMessage response = null;
                try {
                    //Log.Spew ("Pinging daemon!");
                    response = request.Send();
                } catch { }

                if (response == null)
                {
                    ++failure_count;
                    if (failure_count % 20 == 0)
                    {
                        Log.Info("Ping attempt {0} failed", failure_count);
                    }

                    // If we've already tried a bunch of times, just give up.
                    if (failure_count >= 100)
                    {
                        Log.Failure("Could not contact daemon after {0} pings", failure_count);
                        if (started != null)
                        {
                            started(null);
                        }
                        return(false);
                    }

                    return(true);                    // wait a bit, then try again
                }

                Beagle.DaemonInformationResponse info;
                info = (Beagle.DaemonInformationResponse)response;

                Log.Spew("Successfully pinged daemon (version={0})", info.Version);

                SetupIndexListener();

                if (started != null)
                {
                    started(info.Version);
                }

                return(false);                // all done
            }
Example #2
0
            private bool OurTimeoutHandler()
            {
                if (sw == null)
                {
                    sw = new Stopwatch();
                    sw.Start();
                }

                Beagle.RequestMessage request;
                request = new Beagle.DaemonInformationRequest();

                Beagle.ResponseMessage response = null;
                try {
                    response = request.Send();
                } catch { }

                if (response == null)
                {
                    ++failure_count;
                    // FIXME: we should abort if we have too many failures
                    if (failure_count > 9)
                    {
                        Log.Info("Status request attempt {0} failed", failure_count);
                    }
                    return(true);                    // wait a bit, then try again
                }

                string status_str;

                status_str = ((Beagle.DaemonInformationResponse)response).HumanReadableStatus;

                if (status_str.IndexOf("Waiting on empty queue") == -1)
                {
                    if (busy_count == 0)
                    {
                        Log.Spew("Waiting for daemon to become idle");
                    }
                    ++busy_count;
                    if (busy_count % 10 == 0)
                    {
                        Log.Spew("Still waiting for daemon to become idle...");
                    }
                    return(true);                    // wait a bit, then try again
                }

                if (failure_count > 0 || busy_count > 0)
                {
                    Log.Spew("Daemon is idle after {0}", sw);
                }
                else
                {
                    Log.Spew("Daemon is idle");
                }

                if (!optimized)
                {
                    Log.Spew("Requesting index optimization");
                    optimized     = true;
                    failure_count = 0;
                    busy_count    = 0;
                    sw.Reset();

                    request = new Beagle.OptimizeIndexesRequest();
                    try {
                        request.Send();
                    } catch {
                        Log.Failure("Optimize request failed");
                        // FIXME: we should probably terminate here, or something
                    }

                    return(true);                    // wait for optimize to finish
                }

                if (idle != null)
                {
                    idle();
                }

                return(false);                // all done
            }