Exemplo n.º 1
0
        public Monitor(IZmqSocket socket, IZmqContext context,
                       string monitorName   = null,
                       MonitorEvents events = MonitorEvents.All)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (monitorName != null)
            {
                if (!monitorName.StartsWith("inproc://"))
                {
                    monitorName = "inproc://" + monitorName;
                }
            }
            else
            {
                monitorName = "inproc://temp" + Rnd.Next(0, Int32.MaxValue);
            }

            this._monitorName = monitorName;

            // Creates a inproc socket pair
            var res = Native.Monitor.zmq_socket_monitor(socket.Handle(), monitorName, (int)events);

            if (res == Native.ErrorCode)
            {
                Native.ThrowZmqError("Monitor");
            }

            // Connects to the newly created socket pair
            this._pairSocket = context.Pair();
            this._pairSocket.Connect(this._monitorName);

            this._thread = new Thread(EventsWorker)
            {
                IsBackground = true
            };
            this._thread.Start();
        }
Exemplo n.º 2
0
        private void FireEvent(MonitorEvents ev, string endpoint, ZmqError error)
        {
            try
            {
                var _event = this.SocketEvent;

                if (_event != null)
                {
                    _event(this, new MonitorEventArgs()
                    {
                        Event    = ev,
                        Endpoint = endpoint,
                        Error    = error
                    });
                }
            }
            catch (Exception) { }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Spawns a <see cref="SocketType.PAIR"/> socket that publishes the specified state changes (events) for
        /// the specified socket over the inproc transport at the given endpoint.
        /// </summary>
        /// <remarks>
        /// It is recommended to connect via a <see cref="SocketType.PAIR"/> socket in another thread
        /// to handle incoming monitoring events. The <see cref="ZmqMonitor"/> class provides an event-driven
        /// abstraction over event processing.
        /// </remarks>
        /// <param name="socket">The <see cref="ZmqSocket"/> instance to monitor for state changes.</param>
        /// <param name="endpoint">The inproc endpoint on which state changes will be published.</param>
        /// <param name="eventsToMonitor">
        /// A bitwise combination of <see cref="MonitorEvents"/> values indicating which event types should be published.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="socket"/> or <see cref="endpoint"/> is null.</exception>
        /// <exception cref="ArgumentException"><see cref="endpoint"/> is an empty string.</exception>
        /// <exception cref="ZmqSocketException">An error occurred initiating socket monitoring.</exception>
        public static void Monitor(this ZmqSocket socket, string endpoint, MonitorEvents eventsToMonitor)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            if (endpoint == string.Empty)
            {
                throw new ArgumentException("Unable to publish socket events to an empty endpoint.", "endpoint");
            }

            ZmqSocket.HandleProxyResult(socket.SocketProxy.Monitor(endpoint, (int)eventsToMonitor));
        }
Exemplo n.º 4
0
		public Monitor(IZmqSocket socket, IZmqContext context, 
					   string monitorName = null, 
					   MonitorEvents events = MonitorEvents.All)
		{
			if (socket == null) throw new ArgumentNullException("socket");
			if (context == null) throw new ArgumentNullException("context");

			if (monitorName != null)
			{
				if (!monitorName.StartsWith("inproc://"))
					monitorName = "inproc://" + monitorName;
			}
			else
			{
				monitorName = "inproc://temp" + Rnd.Next(0, Int32.MaxValue);
			}

			this._monitorName = monitorName;

			// Creates a inproc socket pair
			var res = Native.Monitor.zmq_socket_monitor(socket.Handle(), monitorName, (int)events);
			if (res == Native.ErrorCode)
			{
				Native.ThrowZmqError("Monitor");
			}

			// Connects to the newly created socket pair
			this._pairSocket = context.Pair();
			this._pairSocket.Connect(this._monitorName);

			this._thread = new Thread(EventsWorker)
			{
				IsBackground = true
			};
			this._thread.Start();
		}
Exemplo n.º 5
0
		private void FireEvent(MonitorEvents ev, string endpoint, ZmqError error)
		{
			try
			{
				var _event = this.SocketEvent;

				if (_event != null)
				{
					_event(this, new MonitorEventArgs()
					{
						Event = ev,
						Endpoint = endpoint,
						Error = error
					});
				}
			}
			catch (Exception) { }
		}