コード例 #1
0
ファイル: NetMQBeacon.cs プロジェクト: NotHuza/Cerberus-v4
        /// <summary>
        ///     Create a new NetMQBeacon.
        /// </summary>
        public NetMQBeacon()
        {
            this.m_actor = NetMQActor.Create(new Shim());

            EventHandler <NetMQActorEventArgs> onReceive = (sender, e) => this.m_receiveEvent.Fire(this, new NetMQBeaconEventArgs(this));

            this.m_receiveEvent = new EventDelegator <NetMQBeaconEventArgs>(
                () => this.m_actor.ReceiveReady += onReceive,
                () => this.m_actor.ReceiveReady -= onReceive);
        }
コード例 #2
0
ファイル: NetMQActor.cs プロジェクト: NotHuza/Cerberus-v4
        private NetMQActor(PairSocket self, PairSocket shim, [NotNull] IShimHandler shimHandler)
        {
            this.m_shimHandler = shimHandler;

            this.m_self = self;
            this.m_shim = shim;

            EventHandler <NetMQSocketEventArgs> onReceive = (sender, e) => this.m_receiveEvent.Fire(this, new NetMQActorEventArgs(this));

            EventHandler <NetMQSocketEventArgs> onSend = (sender, e) => this.m_sendEvent.Fire(this, new NetMQActorEventArgs(this));

            this.m_receiveEvent = new EventDelegator <NetMQActorEventArgs>(
                () => this.m_self.ReceiveReady += onReceive,
                () => this.m_self.ReceiveReady -= onReceive);

            this.m_sendEvent = new EventDelegator <NetMQActorEventArgs>(
                () => this.m_self.SendReady += onSend,
                () => this.m_self.SendReady -= onSend);

            Random random = new Random();

            // Bind and connect pipe ends
            string actorName;
            string endPoint;

            while (true)
            {
                try
                {
                    actorName = $"NetMQActor-{random.Next(0, 10000)}-{random.Next(0, 10000)}";
                    endPoint  = $"inproc://{actorName}";
                    this.m_self.Bind(endPoint);
                    break;
                }
                catch (AddressAlreadyInUseException)
                {
                    // Loop around and try another random address
                }
            }

            this.m_shim.Connect(endPoint);

            this.m_shimThread = new Thread(this.RunShim)
            {
                Name = actorName
            };
            this.m_shimThread.Start();

            // Mandatory handshake for new actor so that constructor returns only
            // when actor has also initialised. This eliminates timing issues at
            // application start up.
            this.m_self.ReceiveSignal();
        }
コード例 #3
0
ファイル: NetMQQueue.cs プロジェクト: NotHuza/Cerberus-v4
        /// <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();
        }