コード例 #1
0
ファイル: NetMQBeacon.cs プロジェクト: lovmoen/netmq
        public NetMQBeacon(NetMQContext context)
        {
            m_agent = new Agent();
            m_actor = new Actor <object>(context, m_agent, null);

            m_receiveEventHelper = new EventDelegatorHelper <NetMQBeaconEventArgs>(() => m_actor.ReceiveReady += OnReceiveReady,
                                                                                   () => m_actor.ReceiveReady -= OnReceiveReady);
        }
コード例 #2
0
        public NetMQBeacon(NetMQContext context)
        {
            m_shim  = new Shim();
            m_actor = NetMQActor.Create(context, m_shim);

            m_receiveEventHelper = new EventDelegatorHelper <NetMQBeaconEventArgs>(() => m_actor.ReceiveReady += OnReceiveReady,
                                                                                   () => m_actor.ReceiveReady -= OnReceiveReady);
        }
コード例 #3
0
        private NetMQActor([NotNull] NetMQContext context, [NotNull] IShimHandler shimHandler)
        {
            m_shimHandler = shimHandler;

            m_self = context.CreatePairSocket();
            m_shim = context.CreatePairSocket();

            m_receiveEventDelegatorHelper  = new EventDelegatorHelper <NetMQActorEventArgs>(
                () => m_self.ReceiveReady += OnReceive,
                () => m_self.ReceiveReady += OnReceive);

            m_sendEventDelegatorHelper  = new EventDelegatorHelper <NetMQActorEventArgs>(
                () => m_self.SendReady += OnReceive,
                () => m_self.SendReady += OnSend);

            var random = new Random();

            //now binding and connect pipe ends
            string endPoint;

            while (true)
            {
                try
                {
                    endPoint = string.Format("inproc://NetMQActor-{0}-{1}", random.Next(0, 10000), random.Next(0, 10000));
                    m_self.Bind(endPoint);
                    break;
                }
                catch (AddressAlreadyInUseException)
                {
                    // In case address already in use we continue searching for an address
                }
            }

            m_shim.Connect(endPoint);

            m_shimThread = new Thread(RunShim);
            m_shimThread.Start();

            //  Mandatory handshake for new actor so that constructor returns only
            //  when actor has also initialized. This eliminates timing issues at
            //  application start up.
            m_self.WaitForSignal();
        }