Ejemplo n.º 1
0
        private void OnServiceUp(ServiceBeacon beacon)
        {
            var handler = ServiceUp;

            if (handler != null)
            {
                EnqueueEvent(() => handler(beacon));
            }
        }
Ejemplo n.º 2
0
        private void OnServiceDataChange(ServiceBeacon beacon, string oldData)
        {
            var handler = ServiceDataChange;

            if (handler != null)
            {
                EnqueueEvent(() => handler(beacon, oldData));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Send a single heartbeat
        /// </summary>
        /// <param name="monitor"></param>
        /// <param name="serviceID"></param>
        /// <param name="serviceName"></param>
        /// <param name="serviceUri"></param>
        public static void Ping(this IServiceMonitor monitor, string serviceID, string serviceName, string serviceUri)
        {
            var service = new ServiceBeacon
            {
                MachineName = monitor.MachineName,
                ID          = serviceID,
                ServiceName = serviceName,
                Version     = SemVer.Current,
                ServiceUri  = serviceUri ?? string.Empty
            };

            monitor.Ping(service);
        }
Ejemplo n.º 4
0
        private void ProcessBeacon(ServiceBeacon beacon)
        {
            OnServiceHeartbeat(beacon);
            services.AddOrUpdate(
                beacon.ServiceKey,
                id =>
            {
                OnServiceUp(beacon);
                return(new Heartbeat(beacon));
            },
                (s, heartbeat) =>
            {
                heartbeat.Pulse();
                bool change = false;
                if ((!string.IsNullOrEmpty(beacon.Version) && heartbeat.Beacon.Version != beacon.Version))
                {
                    heartbeat.Beacon.Version = beacon.Version;
                    change = true;
                }

                if (!string.IsNullOrEmpty(beacon.ServiceUri) && heartbeat.Beacon.ServiceUri != beacon.ServiceUri)
                {
                    heartbeat.Beacon.ServiceUri = beacon.ServiceUri;
                    change = true;
                }

                if (change)
                {
                    OnServiceChange(heartbeat.Beacon);
                }
                if (heartbeat.Beacon.ServiceData != beacon.ServiceData)
                {
                    var oldData = heartbeat.Beacon.ServiceData;
                    heartbeat.Beacon.ServiceData = beacon.ServiceData;
                    OnServiceDataChange(heartbeat.Beacon, oldData);
                }

                return(heartbeat);
            }
                );
        }
Ejemplo n.º 5
0
 private void EnqueueBeacon(ServiceBeacon beacon)
 {
     if (beacon == null)
     {
         return;
     }
     if (beaconQueue.IsAddingCompleted)
     {
         return;
     }
     beaconQueue.Add(beacon);
     if (beaconQueue.Count >= 100 && beaconQueue.Count % 100 == 0)
     {
         beaconQueueWarning = true;
         Trace.TraceWarning("*** beaconQueue: length=" + beaconQueue.Count);
     }
     else if (beaconQueueWarning && beaconQueue.Count < 100)
     {
         beaconQueueWarning = false;
         Trace.TraceWarning("*** beaconQueue: returning to normal");
     }
 }
Ejemplo n.º 6
0
 public Heartbeat(ServiceBeacon beacon)
 {
     Beacon    = beacon;
     LastPulse = DateTime.UtcNow;
 }
Ejemplo n.º 7
0
 public IServiceMonitor RegisterService(ServiceBeacon beacon)
 {
     localServices[beacon.ServiceKey] = beacon;
     return(this);
 }
Ejemplo n.º 8
0
 public void Ping(ServiceBeacon beacon)
 {
     sender.Send(beacon);
 }
Ejemplo n.º 9
0
 public static bool Exists(this IServiceMonitor monitor, ServiceBeacon beacon)
 {
     return(monitor.Get(beacon.ServiceKey) != null);
 }
Ejemplo n.º 10
0
 public static ServiceBeacon Get(this IServiceMonitor monitor, ServiceBeacon beacon)
 {
     return(monitor.Get(beacon.ServiceKey));
 }