Exemplo n.º 1
0
        /// <summary>
        /// Inspects a target and returns a handle.
        /// </summary>
        /// <param name="target">The target to wrap.</param>
        /// <returns></returns>
        public static DebugHandle Inspect(object target)
        {
            // Fetch from the cache first
            var key = String.Format("0x{0:X}", target.GetHashCode());

            return(Tracked.GetOrAdd(key, (k) =>
            {
                var handle = new DebugHandle();
                handle.Reference = new WeakReference(target);
                return handle;
            }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the message to publish to emitter channel.
        /// </summary>
        /// <returns></returns>
        protected override void OnExecute()
        {
            // First, find all dead handles
            DebugHandle.Cleanup();

            try
            {
                // Send some objects
                var handles = new List <DebugHandle>();
                //foreach (var mesh in Service.Mesh.Members)
                //    handles.Add(DebugHandle.Inspect(mesh));
                handles.Add(
                    DebugHandle.Inspect(Service.Registry.Collection)
                    );

                /*foreach (var client in Service.Clients)
                 * {
                 *  if (client.Channel?.Binding is MeshBinding)
                 *      continue;
                 *  handles.Add(DebugHandle.Inspect(client));
                 * }*/

                if (handles.Count == 0)
                {
                    return;
                }

                // Return the serialized object
                var message = Encoding.UTF8
                              .GetBytes(JsonConvert.SerializeObject(handles))
                              .AsSegment();

                // Publish the message in the cluster, don't need to store it as it might slow everything down
                Dispatcher.Publish(SecurityLicense.Current.Contract, Info.Target, this.Channel + "root/", message, 60);
            }
            catch (Exception ex)
            {
                Service.Logger.Log(ex);
            }
        }
Exemplo n.º 3
0
        public void Inspect(string id)
        {
            try
            {
                // Get the handle
                var handle = DebugHandle.Get(id);
                if (handle == null)
                {
                    return;
                }

                // Get the measurements
                var message = Encoding.UTF8
                              .GetBytes(handle.ToString())
                              .AsSegment();

                // Publish the message in the cluster, don't need to store it as it might slow everything down
                Dispatcher.Publish(SecurityLicense.Current.Contract, Info.Target, this.Channel + "result/", message, 60);
            }
            catch (Exception ex)
            {
                Service.Logger.Log(ex);
            }
        }