Exemple #1
0
        private NetMQActor(PairSocket self, PairSocket shim, IShimHandler shimHandler)
        {
            m_shimHandler = shimHandler;

            m_self = self;
            m_shim = shim;

            var args = new NetMQActorEventArgs(this);

            void OnReceive(object sender, NetMQSocketEventArgs e) => m_receiveEvent !.Fire(this, args);
            void OnSend(object sender, NetMQSocketEventArgs e) => m_sendEvent   !.Fire(this, args);

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

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

            var 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}";
                    m_self.Bind(endPoint);
                    break;
                }
                catch (AddressAlreadyInUseException)
                {
                    // Loop around and try another random address
                }
            }

            m_shim.Connect(endPoint);

            m_shimThread = new Thread(RunShim)
            {
                Name = actorName
            };
            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.
            m_self.ReceiveSignal();
        }
Exemple #2
0
 void OnReceive(object sender, NetMQActorEventArgs e)
 {
     m_receiveEvent.Fire(this, new NetMQBeaconEventArgs(this));
 }
Exemple #3
0
 private void OnReceiveReady(object sender, NetMQActorEventArgs args)
 {
     m_receiveEventHelper.Fire(this, new NetMQBeaconEventArgs(this));
 }