Esempio n. 1
0
        /// <summary>
        /// Create a Zyre API that communicates with a node on the ZRE bus.
        /// </summary>
        /// <param name="name">The name of the node</param>
        /// <param name="useEvents">Set this to true to disable Receive() and instead subscribe to events for getting messages from peers. Default is true.</param>
        /// <param name="loggerDelegate">An action to take for logging when _verbose is true. Default is null.</param>
        public Zyre(string name, bool useEvents = true, Action <string> loggerDelegate = null)
        {
            _useEvents = useEvents;
            // Create front-to-back pipe pair for data traffic
            // outbox is passed to ZyreNode for sending Zyre message traffic back to _inbox
            PairSocket outbox;

            PairSocket.CreateSocketPair(out outbox, out _inbox);

            // Start node engine and wait for it to be ready
            // All node control is done through _actor

            _actor = ZyreNode.Create(outbox, loggerDelegate);

            if (useEvents)
            {
                _inboxPoller         = new NetMQPoller();
                _inbox.ReceiveReady += InboxReceiveReady;
                _inboxPoller.RunAsync();
            }

            // Send name, if any, to node ending
            if (!string.IsNullOrEmpty(name))
            {
                _actor.SendMoreFrame("SET NAME").SendFrame(name);
            }
        }
Esempio n. 2
0
        public StopSignaler()
        {
            PairSocket.CreateSocketPair(out m_writer, out m_reader);
            m_reader.ReceiveReady += delegate
            {
                m_reader.SkipFrame();
                IsStopRequested = true;
            };

            IsStopRequested = false;
        }
Esempio n. 3
0
        /// <summary>
        ///     Create new NetMQQueue.
        /// </summary>
        /// <param name="capacity">The capacity of the queue, use zero for unlimited</param>
        public NetMQQueue(int capacity = 0)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity));
            }

            this.m_queue = new ConcurrentQueue <T>();
            PairSocket.CreateSocketPair(out this.m_writer, out this.m_reader);

            this.m_writer.Options.SendHighWatermark = this.m_reader.Options.ReceiveHighWatermark = capacity / 2;

            this.m_eventDelegator = new EventDelegator <NetMQQueueEventArgs <T> >(() => { this.m_reader.ReceiveReady += this.OnReceiveReady; }, () => { this.m_reader.ReceiveReady -= this.OnReceiveReady; });

            this.m_dequeueMsg = new Msg();
            this.m_dequeueMsg.InitEmpty();
        }