Ejemplo n.º 1
0
 /// <summary>
 /// Constructs the reactor for the VCAP component.
 /// </summary>
 protected virtual void ConstructReactor()
 {
     if (VCAPReactor == null)
     {
         VCAPReactor = new VCAPReactor();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs this the VCAP component. This method is non-blocking.
        /// </summary>
        public virtual void Run()
        {
            this.Discover = new Dictionary <string, object>()
            {
                { "type", this.ComponentType },
                { "index", this.Index },
                { "uuid", this.UUID },
                { "host", string.Format(CultureInfo.InvariantCulture, "{0}:{1}", this.Host, this.Port) },
                { "credentials", this.Authentication },
                { "start", RubyCompatibility.DateTimeToRubyString(this.StartedAt = DateTime.Now) }
            };

            // Listen for discovery requests
            VCAPReactor.OnComponentDiscover += delegate(string msg, string reply, string subject)
            {
                this.UpdateDiscoverUptime();
                VCAPReactor.SendReply(reply, JsonConvertibleObject.SerializeToJson(this.Discover));
            };

            VCAPReactor.Start();

            // Varz is customizable
            this.Varz = new Dictionary <string, object>();
            foreach (string key in this.Discover.Keys)
            {
                this.Varz[key] = this.Discover[key];
            }

            this.Varz["num_cores"] = Environment.ProcessorCount;

            // todo: change this to a more accurate method
            // consider:
            // PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
            // upTime.NextValue();
            // TimeSpan ts2 = TimeSpan.FromSeconds(upTime.NextValue());
            // Console.WriteLine("{0}d {1}h {2}m {3}s", ts2.Days, ts2.Hours, ts2.Minutes, ts2.Seconds);
            this.Varz["system_start"] = RubyCompatibility.DateTimeToRubyString(DateTime.Now.AddMilliseconds(-Environment.TickCount));

            this.CpuPerformance = new PerformanceCounter();
            this.CpuPerformance.CategoryName = "Processor Information";
            this.CpuPerformance.CounterName  = "% Processor Time";
            this.CpuPerformance.InstanceName = "_Total";
            this.CpuPerformance.NextValue();

            this.Healthz = "ok\n";

            this.StartHttpServer();

            // Also announce ourselves on startup..
            VCAPReactor.SendVCAPComponentAnnounce(JsonConvertibleObject.SerializeToJson(this.Discover));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructs the reactor for the VCAP component.
 /// </summary>
 protected virtual void ConstructReactor()
 {
     if (VCAPReactor == null)
     {
         VCAPReactor = new VCAPReactor();
     }
 }