Exemple #1
0
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    if (command == NetMQActor.EndShimMessage)
                    {
                        break;
                    }

                    //Simulate a failure that should be sent back to Actor
                    throw new InvalidOperationException("Actors Shim threw an Exception");
                }
                //You WILL need to decide what Exceptions should be caught here, this is for
                //demonstration purposes only, any unhandled fault will bubble up to caller's code
                catch (InvalidOperationException e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }
Exemple #2
0
        private void Run(PairSocket shim)
        {
            m_shim             = shim;
            shim.ReceiveReady += OnShimMessage;

            m_timeoutTimer          = new NetMQTimer(TimeOut);
            m_timeoutTimer.Elapsed += OnTimeoutTimer;

            m_reconnectTimer          = new NetMQTimer(ReconnectTimer);
            m_reconnectTimer.Elapsed += OnReconnectTimer;

            m_poller = new Poller(shim);
            m_poller.AddTimer(m_timeoutTimer);
            m_poller.AddTimer(m_reconnectTimer);

            shim.SignalOK();

            Connect();

            m_poller.PollTillCancelled();

            if (m_subscriber != null)
            {
                m_subscriber.Dispose();
            }
        }
Exemple #3
0
        private void Run(PairSocket shim)
        {
            using (m_publisherSocket = new XPublisherSocket(m_address))
            {
                m_publisherSocket.SetWelcomeMessage(WelcomeMessage);

                m_publisherSocket.ReceiveReady += DropPublisherSubscriptions;

                m_heartbeatTimer          = new NetMQTimer(HeartbeatInterval);
                m_heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;

                shim.ReceiveReady += OnShimMessage;

                // signal the actor that the shim is ready to work
                shim.SignalOK();

                m_poller = new NetMQPoller {
                    m_publisherSocket, shim
                };
                m_poller.Add(m_heartbeatTimer);

                // Polling until poller is cancelled
                m_poller.Run();
            }
        }
            public void RunPipeline(PairSocket shim)
            {
                publisherSocket = context.CreatePublisherSocket();
                publisherSocket.Bind("tcp://*:" + StreamingProtocol.Port);

                snapshotSocket = context.CreateResponseSocket();
                snapshotSocket.Bind("tcp://*:" + SnapshotProtocol.Port);
                snapshotSocket.ReceiveReady += OnSnapshotReady;

                shim.ReceiveReady += OnShimReady;

                heartbeatTimer          = new NetMQTimer(StreamingProtocol.HeartbeatInterval);
                heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;

                shim.SignalOK();

                poller = new Poller();
                poller.AddSocket(shim);
                poller.AddSocket(snapshotSocket);
                poller.AddTimer(heartbeatTimer);
                poller.Start();

                publisherSocket.Dispose();
                snapshotSocket.Dispose();
            }
Exemple #5
0
        private void RunActor(PairSocket shim)
        {
            _shim = shim;

            using (_subscriber = new SubscriberSocket())
                using (_publisher = new PublisherSocket())
                {
                    using (_beacon = new NetMQBeacon())
                    {
                        _shim.ReceiveReady += OnShimReady;

                        _subscriber.Subscribe(string.Empty);
                        _port = _subscriber.BindRandomPort("tcp://*");
                        _logger?.LogInformation($"{_id}: Peer bus is bound to {{BusPort}}", _port);
                        _subscriber.ReceiveReady += OnSubscriberReady;

                        _logger?.LogInformation($"{_id}: Peer is broadcasting UDP on port {{BeaconPort}}", _beaconPort);
                        _beacon.Configure(_beaconPort);
                        _beacon.Publish(_port.ToString(), _beaconInterval);
                        _beacon.Subscribe(string.Empty);
                        _beacon.ReceiveReady += OnBeaconReady;

                        var cleanupTimer = new NetMQTimer(_cleanupInterval);
                        cleanupTimer.Elapsed += Cleanup;

                        _poll = new NetMQPoller {
                            _shim, _subscriber, _beacon, cleanupTimer
                        };
                        _shim.SignalOK();
                        _poll.Run();
                    }
                }
        }
Exemple #6
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer          = new NetMQTimer(interval: TimeSpan.Zero);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable   = false;

                using (m_poller = new NetMQPoller {
                    m_pipe, m_pingTimer
                })
                {
                    m_poller.Run();
                }

                // the beacon might never been configured
#if NET35
                m_udpSocket?.Close();
#else
                m_udpSocket?.Dispose();
#endif
            }
Exemple #7
0
        private void Run(PairSocket shim)
        {
            _shim = shim;
            using (_publisherSocket = new XPublisherSocket())
            {
                _publisherSocket.SetWelcomeMessage(WelcomeMessage);
                _publisherSocket.Bind(_address);

                _publisherSocket.ReceiveReady += DropPublisherSubscriptions;

                _heartbeatTimer          = new NetMQTimer(_heartbeatInterval);
                _heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;

                if (_receiveTimeout > 0)
                {
                    _receiveTimeoutTimer          = new NetMQTimer(1000);
                    _receiveTimeoutTimer.Enable   = false;
                    _receiveTimeoutTimer.Elapsed += OnReceiveTimeout;;
                }

                shim.ReceiveReady += OnShimMessage;

                // signal the actor that the shim is ready to work
                shim.SignalOK();

                _poller = new NetMQPoller {
                    _publisherSocket, shim, _heartbeatTimer, _receiveTimeoutTimer
                };
                // Polling until poller is cancelled
                _poller.Run();
            }
        }
 public void RequestStop()
 {
     lock (m_writer)
     {
         m_writer.SignalOK();
     }
 }
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            shim.ReceiveReady += OnShimReady;

            m_messagesPipe = new PairSocket();
            m_messagesPipe.Connect(string.Format("inproc://wsrouter-{0}", m_id));
            m_messagesPipe.ReceiveReady += OnMessagePipeReady;

            m_stream = new StreamSocket();
            m_stream.ReceiveReady += OnStreamReady;

            m_poller = new NetMQPoller();
            m_poller.Add(m_messagesPipe);
            m_poller.Add(shim);
            m_poller.Add(m_stream);

            m_messagesPipe.SignalOK();

            m_poller.Run();

            m_messagesPipe.Dispose();
            m_stream.Dispose();
        }
Exemple #10
0
        private void RunActor(PairSocket shim)
        {
            // save the shim to the class to use later
            m_shim = shim;

            // create all subscriber, publisher and beacon
            using (m_subscriber = new SubscriberSocket())
                using (m_publisher = new PublisherSocket())
                    using (m_beacon = new NetMQBeacon())
                    {
                        // listen to actor commands
                        m_shim.ReceiveReady += OnShimReady;

                        // subscribe to all messages
                        m_subscriber.Subscribe("");

                        // we bind to a random port, we will later publish this port
                        // using the beacon
                        m_randomPort = m_subscriber.BindRandomPort("tcp://*");
                        Console.WriteLine("Bus subscriber is bound to {0}", m_subscriber.Options.LastEndpoint);

                        // listen to incoming messages from other publishers, forward them to the shim
                        m_subscriber.ReceiveReady += OnSubscriberReady;

                        // configure the beacon to listen on the broadcast port
                        Console.WriteLine("Beacon is being configured to UDP port {0}", m_broadcastPort);
                        m_beacon.Configure(m_broadcastPort);

                        // publishing the random port to all other nodes
                        Console.WriteLine("Beacon is publishing the Bus subscriber port {0}", m_randomPort);
                        m_beacon.Publish(m_randomPort.ToString(), TimeSpan.FromSeconds(1));

                        // Subscribe to all beacon on the port
                        Console.WriteLine("Beacon is subscribing to all beacons on UDP port {0}", m_broadcastPort);
                        m_beacon.Subscribe("");

                        // listen to incoming beacons
                        m_beacon.ReceiveReady += OnBeaconReady;

                        // Create a timer to clear dead nodes
                        NetMQTimer timer = new NetMQTimer(TimeSpan.FromSeconds(1));
                        timer.Elapsed += ClearDeadNodes;

                        // Create and configure the poller with all sockets and the timer
                        m_poller = new NetMQPoller {
                            m_shim, m_subscriber, m_beacon, timer
                        };

                        // signal the actor that we finished with configuration and
                        // ready to work
                        m_shim.SignalOK();

                        // polling until cancelled
                        m_poller.Run();
                    }
        }
Exemple #11
0
 public void Run(PairSocket shim)
 {
     this.shim          = shim;
     shim.ReceiveReady += OnShimReady;
     shim.SignalOK();
     poller = new NetMQPoller {
         shim
     };
     poller.Run();
 }
Exemple #12
0
        private void Run(PairSocket shim)
        {
            shim.ReceiveReady += OnShimReady;
            m_receiveSocket.ReceiveReady += OnSocketReady;
            m_poller = new NetMQPoller { m_receiveSocket, shim };

            shim.SignalOK();
            m_poller.Run();

            m_receiveSocket.ReceiveReady -= OnSocketReady;
        }
Exemple #13
0
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[2] : AccountAction as JSON
                    //Frame[1] : Account as JSON
                    //
                    //Result back to actor is a JSON message of the amended Account
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    if (command == NetMQActor.EndShimMessage)
                    {
                        break;
                    }

                    if (msg[0].ConvertToString() == "AMEND ACCOUNT")
                    {
                        string accountActionJson = msg[1].ConvertToString();
                        var    accountAction     = JsonConvert.DeserializeObject <AccountAction>(accountActionJson);

                        string accountJson = msg[2].ConvertToString();
                        var    account     = JsonConvert.DeserializeObject <Account>(accountJson);
                        if (account != null && accountAction != null)
                        {
                            AmendAccount(accountAction, account);
                            shim.SendFrame(JsonConvert.SerializeObject(account));
                        }
                        else
                        {
                            shim.SendFrame("Error: incorrectly formatted message to actor");
                        }
                    }
                    else
                    {
                        shim.SendFrame("Error: invalid message to actor");
                    }
                }
                // You WILL need to decide what Exceptions should be caught here, this is for
                // demonstration purposes only, any unhandled fault will bubble up to caller's code.
                catch (Exception e)
                {
                    shim.SendFrame($"Error: Exception occurred {e.Message}");
                }
            }
        }
Exemple #14
0
        private void Run(PairSocket shim)
        {
            shim.ReceiveReady            += OnShimReady;
            m_receiveSocket.ReceiveReady += OnSocketReady;
            m_poller = new NetMQPoller {
                m_receiveSocket, shim
            };

            shim.SignalOK();
            m_poller.Run();

            m_receiveSocket.ReceiveReady -= OnSocketReady;
        }
Exemple #15
0
            public void Run(PairSocket shim)
            {
                _poller = new NetMQPoller();

                _ = Observable.FromEventPattern <NetMQSocketEventArgs>(e => shim.ReceiveReady += e, e => shim.ReceiveReady -= e)
                    .Select(e => e.EventArgs)
                    .Subscribe(OnShimReady);

                _poller.Add(shim);

                // Timer
                var timeoutTimer = new NetMQTimer(TimeSpan.FromSeconds(5));

                _ = Observable.FromEventPattern <NetMQTimerEventArgs>(e => timeoutTimer.Elapsed += e, e => timeoutTimer.Elapsed -= e)
                    .Select(e => e.EventArgs)
                    .ObserveOn(ThreadPoolScheduler.Instance)
                    .Subscribe(OnTimeoutElapsed);
                _poller.Add(timeoutTimer);

                _subscriberSocket = new SubscriberSocket();
                _subscriberSocket.Options.Linger = TimeSpan.Zero;
                _subscriberSocket.Subscribe(CoreHearbeatTopic);
                _subscriberSocket.Connect($"tcp://{_address}:{_port + 1}");
                _subject.OnNext(ConnectionStatus.Connecting);

                _ = Observable.FromEventPattern <NetMQSocketEventArgs>(e => _subscriberSocket.ReceiveReady += e, e => _subscriberSocket.ReceiveReady -= e)
                    .Select(e => e.EventArgs)
                    .Where(e => e.Socket.ReceiveFrameString() == CoreHearbeatTopic)
                    .ObserveOn(ThreadPoolScheduler.Instance)
                    .Subscribe(e =>
                {
                    timeoutTimer.Reset();
                    Thread.MemoryBarrier();
                    var status = _borgConnected
                            ? (ConnectionStatus.Online | ConnectionStatus.Connected)
                            : (ConnectionStatus.Online | ConnectionStatus.Disconnected);
                    _subject.OnNext(status);
                });

                _poller.Add(_subscriberSocket);
                timeoutTimer.Reset();
                shim.SignalOK();

                _poller.Run();

                // Cleanup stuff after stopping
                _poller.Remove(_subscriberSocket);
                _poller.Remove(timeoutTimer);
                _poller.Remove(shim);
                _poller.Dispose();
            }
Exemple #16
0
        void IShimHandler.Run(PairSocket pipe)
        {
            _pipe = pipe;
            _pipe.SignalOK();
            _pipe.ReceiveReady += OnPipeReady;

            _zre = Zre.Create(_ctx, _name);
            _zre.ReceiveReady += OnZreReady;

            _poller = new Poller();
            _poller.AddSocket(_zre);
            _poller.AddSocket(_pipe);
            _poller.PollTillCancelled();
        }
Exemple #17
0
        private NetMQActor CreateActor()
        {
            return(NetMQActor.Create(shim =>
            {
                Shim = shim;
                Shim.ReceiveReady += ShimOnReceiveReady;

                Poller.Add(ListeningSocket);
                Poller.Add(InitTimer);
                Poller.Add(Shim);

                Shim.SignalOK();
                Poller.Run();
            }));
        }
Exemple #18
0
        void IShimHandler.Run(PairSocket shim)
        {
            _pipe = shim;
            _pipe.SignalOK();
            _pipe.ReceiveReady += OnPipeReady;

            _timer = new NetMQTimer(TimeSpan.FromSeconds(1));
            _timer.Elapsed += OnPingPeer;

            _inbox = _context.CreateRouterSocket();
            _inbox.ReceiveReady += OnInboxReady;

            _poller = new Poller(_pipe);
            _poller.AddTimer(_timer);
            _poller.PollTillCancelled();
        }
Exemple #19
0
        public void RunPipeline(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[2] : AccountAction as JSON
                    //Frame[1] : Account as JSON
                    //
                    //Result back to actor is a JSON message of the amended Account
                    NetMQMessage msg = shim.ReceiveMessage();

                    string command = msg[0].ConvertToString();

                    if (command == ActorKnownMessages.END_PIPE)
                    {
                        break;
                    }

                    if (msg[0].ConvertToString() == "AMEND ACCOUNT")
                    {
                        string        accountActionJson = msg[1].ConvertToString();
                        AccountAction accountAction     = JsonConvert.DeserializeObject <AccountAction>(accountActionJson);

                        string  accountJson = msg[2].ConvertToString();
                        Account account     = JsonConvert.DeserializeObject <Account>(accountJson);
                        AmmendAccount(accountAction, account);
                        shim.Send(JsonConvert.SerializeObject(account));
                    }

                    else
                    {
                        shim.Send("Error: invalid message to actor");
                    }
                }
                //You WILL need to decide what Exceptions should be caught here, this is for
                //demonstration purposes only, any unhandled falut will bubble up to callers code
                catch (Exception e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }
Exemple #20
0
        void IShimHandler.Run(PairSocket shim)
        {
            Poller = new NetMQPoller();


            Shim = shim;
            Shim.ReceiveReady += OnShimReady;
            Poller.Add(Shim);

            Initialize();

            Shim.SignalOK();

            Poller.Run();

            Cleanup();
        }
Exemple #21
0
        private void Run(PairSocket shim)
        {
            using (var router = new RouterSocket())
            {
                router.Bind(_address);

                router.ReceiveReady += SendSnapshot;
                shim.ReceiveReady   += OnShimMessage;

                // signal the actor that the shim is ready to work
                shim.SignalOK();

                _poller = new NetMQPoller {
                    router, _actor
                };
                _poller.Run();
            }
        }
Exemple #22
0
            public void Run(PairSocket shim)
            {
                using (subscriberSocket = new SubscriberSocket())
                {
                    subscriberSocket.Options.ReceiveHighWatermark = 1000;
                    subscriberSocket.ReceiveReady += ResultSubscriber_ReceiveReady;
                    subscriberSocket.Connect(connectionString);
                    subscriberSocket.Subscribe("");     //Subscribe to all messages

                    this.shim          = shim;
                    shim.ReceiveReady += OnShimReady;
                    shim.SignalOK();
                    poller = new NetMQPoller {
                        shim, subscriberSocket
                    };
                    poller.Run();
                }
            }
        private void Run(PairSocket shim)
        {
            using (_publisherSocket = new PublisherSocket(_address))
            {
                //_publisherSocket.Bind(_address);
                //_publisherSocket.ReceiveReady += DropPublisherSubscriptions;
                shim.ReceiveReady += OnShimMessage;

                _heartbeatTimer          = new NetMQTimer(TimeSpan.FromSeconds(10));
                _heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;

                // signal the actor that the shim is ready to work
                shim.SignalOK();

                _poller = new NetMQPoller {
                    shim, _publisherSocket, _heartbeatTimer
                };
                _poller.Run();
            }
        }
Exemple #24
0
        public void RunPipeline(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[1] : Payload
                    //
                    //Result back to actor is a simple echoing of the Payload, where
                    //the payload is prefixed with "ECHO BACK "
                    NetMQMessage msg = shim.ReceiveMessage();

                    string command = msg[0].ConvertToString();

                    if (command == ActorKnownMessages.END_PIPE)
                    {
                        break;
                    }

                    if (command == "ECHO")
                    {
                        shim.Send(string.Format("ECHO BACK : {0}",
                                                msg[1].ConvertToString()));
                    }
                    else
                    {
                        shim.Send("Error: invalid message to actor");
                    }
                }
                //You WILL need to decide what Exceptions should be caught here, this is for
                //demonstration purposes only, any unhandled falut will bubble up to callers code
                catch (Exception e)
                {
                    shim.Send(string.Format("Error: Exception occurred {0}", e.Message));
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Execute the shimhandler's Run method, signal ok and then dispose of the shim.
        /// </summary>
        private void RunShim()
        {
            try
            {
                m_shimHandler.Run(m_shim);
            }
            catch (TerminatingException)
            {}

            // Do not block, if the other end of the pipe is already deleted
            m_shim.Options.SendTimeout = TimeSpan.Zero;

            try
            {
                m_shim.SignalOK();
            }
            catch (AgainException)
            {}

            m_shim.Dispose();
        }
        public void Run(PairSocket shim)
        {
            shim.SignalOK();

            while (true)
            {
                try
                {
                    //Message for this actor/shim handler is expected to be
                    //Frame[0] : Command
                    //Frame[1] : Payload
                    //
                    //Result back to actor is a simple echoing of the Payload, where
                    //the payload is prefixed with "ECHO BACK "
                    NetMQMessage msg = shim.ReceiveMultipartMessage();

                    string command = msg[0].ConvertToString();

                    switch (command)
                    {
                    case NetMQActor.EndShimMessage:
                        return;

                    case "ECHO":
                        shim.SendFrame($"ECHO BACK : {msg[1].ConvertToString()}");
                        break;

                    default:
                        shim.SendFrame("Error: invalid message to actor");
                        break;
                    }
                }
                // You WILL need to decide what Exceptions should be caught here, this is for
                // demonstration purposes only, any unhandled fault will bubble up to caller's code
                catch (Exception e)
                {
                    shim.SendFrame($"Error: Exception occurred {e.Message}");
                }
            }
        }
        public void RunPipeline(PairSocket shim)
        {
            shim.SignalOK();

            shim.ReceiveReady += OnShimReady;

            m_messagesPipe = m_context.CreatePairSocket();
            m_messagesPipe.Connect(string.Format("inproc://wsrouter-{0}", m_id));
            m_messagesPipe.ReceiveReady += OnMessagePipeReady;

            m_stream = m_context.CreateStreamSocket();
            m_stream.ReceiveReady += OnStreamReady;

            m_poller = new Poller(m_messagesPipe, shim, m_stream);

            m_messagesPipe.SignalOK();

            m_poller.Start();

            m_messagesPipe.Dispose();
            m_stream.Dispose();
        }
Exemple #28
0
        public void Run(PairSocket shim)
        {
            string shimAdd = $"inproc://wsrouter-{Id}";

            Monitor.Enter(this);
            try
            {
                isRuning = true;
                shim.SignalOK();

                shim.ReceiveReady += OnShimReady;

                MessagesPipe = new PairSocket();
                MessagesPipe.Connect(shimAdd);
                MessagesPipe.ReceiveReady += OnMessagePipeReady;

                Stream = new StreamSocket();
                Stream.Bind(Address);
                Stream.ReceiveReady += OnStreamReady;

                Poller = new NetMQPoller
                {
                    MessagesPipe,
                    shim,
                    Stream
                };
                MessagesPipe.SignalOK();
                Poller.Run();
                shim.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                Monitor.Exit(this);
            }
        }
Exemple #29
0
        /// <summary>
        /// This method is being run asynchronously by m_actor.
        /// </summary>
        /// <param name="shim"></param>
        private void RunActor(PairSocket shim)
        {
            _pipe = shim;
            _pipe.ReceiveReady += OnPipeReceiveReady;

            var reapTimer = new NetMQTimer(TimeSpan.FromMilliseconds(1000));

            reapTimer.Elapsed += OnReapTimerElapsed;

            // Start poller, but poll only the _pipe. Start() and Stop() will add/remove other items to poll
            _poller = new NetMQPoller {
                _pipe, reapTimer
            };

            // Signal the actor that we're ready to work
            _pipe.SignalOK();

            // polling until cancelled
            _poller.Run();

            Dispose();
        }
        private void Run(PairSocket shim)
        {
            _shim              = shim;
            shim.ReceiveReady += OnShimMessage;

            _timeoutTimer          = new NetMQTimer(_heartbeatTimeOut);
            _timeoutTimer.Elapsed += OnTimeoutTimer;

            _reconnectTimer          = new NetMQTimer(_reconnectInterval);
            _reconnectTimer.Elapsed += OnReconnectTimer;

            _poller = new NetMQPoller {
                shim, _timeoutTimer, _reconnectTimer
            };

            shim.SignalOK();

            Connect();

            _poller.Run();

            _subscriber?.Dispose();
        }
            public void RunPipeline(PairSocket shim)
            {
                // we should signal before running the poller but this will block the application
                shim.SignalOK();

                this.poller = new Poller();

                shim.ReceiveReady += OnShimReady;
                poller.AddSocket(shim);

                timeoutTimer          = new NetMQTimer(StreamingProtocol.Timeout);
                timeoutTimer.Elapsed += TimeoutElapsed;
                poller.AddTimer(timeoutTimer);

                Connect();

                poller.Start();

                if (subscriberSocket != null)
                {
                    subscriberSocket.Dispose();
                }
            }
Exemple #32
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer          = new NetMQTimer(0);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable   = false;

                m_poller = new Poller();
                m_poller.AddSocket(m_pipe);
                m_poller.AddTimer(m_pingTimer);

                m_poller.PollTillCancelled();

                // the beacon might never been configured
                if (m_udpSocket != null)
                {
                    m_udpSocket.Close();
                }
            }
Exemple #33
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer          = new NetMQTimer(interval: TimeSpan.Zero);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable   = false;

                m_poller = new NetMQPoller {
                    m_pipe, m_pingTimer
                };

                m_poller.Run();

                // the beacon might never been configured
                if (m_udpSocket != null)
                {
                    m_udpSocket.Close();
                }
            }
Exemple #34
0
        private void RunActor(PairSocket shim)
        {
            // save the shim to the class to use later
            m_shim = shim;

            // create all subscriber, publisher and beacon
            using (m_subscriber = new SubscriberSocket())
            using (m_publisher = new PublisherSocket())
            using (m_beacon = new NetMQBeacon())
            {
                // listen to actor commands
                m_shim.ReceiveReady += OnShimReady;

                // subscribe to all messages
                m_subscriber.Subscribe("");

                // we bind to a random port, we will later publish this port
                // using the beacon
                m_randomPort = m_subscriber.BindRandomPort("tcp://*");
                Console.WriteLine("Bus subscriber is bound to {0}", m_subscriber.Options.LastEndpoint);

                // listen to incoming messages from other publishers, forward them to the shim
                m_subscriber.ReceiveReady += OnSubscriberReady;

                // configure the beacon to listen on the broadcast port
                Console.WriteLine("Beacon is being configured to UDP port {0}", m_broadcastPort);
                m_beacon.Configure(m_broadcastPort);

                // publishing the random port to all other nodes
                Console.WriteLine("Beacon is publishing the Bus subscriber port {0}", m_randomPort);
                m_beacon.Publish(m_randomPort.ToString(), TimeSpan.FromSeconds(1));

                // Subscribe to all beacon on the port
                Console.WriteLine("Beacon is subscribing to all beacons on UDP port {0}", m_broadcastPort);
                m_beacon.Subscribe("");

                // listen to incoming beacons
                m_beacon.ReceiveReady += OnBeaconReady;

                // Create a timer to clear dead nodes
                NetMQTimer timer = new NetMQTimer(TimeSpan.FromSeconds(1));
                timer.Elapsed += ClearDeadNodes;

                // Create and configure the poller with all sockets and the timer
                m_poller = new NetMQPoller { m_shim, m_subscriber, m_beacon, timer };

                // signal the actor that we finished with configuration and
                // ready to work
                m_shim.SignalOK();

                // polling until cancelled
                m_poller.Run();
            }
        }
Exemple #35
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer = new NetMQTimer(interval: TimeSpan.Zero);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable = false;

                m_poller = new NetMQPoller { m_pipe, m_pingTimer };

                m_poller.Run();

                // the beacon might never been configured
                if (m_udpSocket != null)
                    m_udpSocket.Close();
            }
Exemple #36
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer = new NetMQTimer(0);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable = false;

                m_poller = new Poller();
                m_poller.AddSocket(m_pipe);
                m_poller.AddTimer(m_pingTimer);

                m_poller.PollTillCancelled();

                // the beacon might never been configured
                if (m_udpSocket != null)
                {
                    m_udpSocket.Close();
                }
            }
        private void Run(PairSocket shim)
        {
            m_shim = shim;
            shim.ReceiveReady += OnShimMessage;

            m_timeoutTimer = new NetMQTimer(TimeOut);
            m_timeoutTimer.Elapsed += OnTimeoutTimer;

            m_reconnectTimer = new NetMQTimer(ReconnectTimer);
            m_reconnectTimer.Elapsed += OnReconnectTimer;

            m_poller = new Poller(shim);
            m_poller.AddTimer(m_timeoutTimer);
            m_poller.AddTimer(m_reconnectTimer);

            shim.SignalOK();

            Connect();

            m_poller.PollTillCancelled();

            if (m_subscriber != null)
                m_subscriber.Dispose();
        }
Exemple #38
0
            public void Run(PairSocket shim)
            {
                m_pipe = shim;

                shim.SignalOK();

                m_pipe.ReceiveReady += OnPipeReady;

                m_pingTimer = new NetMQTimer(interval: TimeSpan.Zero);
                m_pingTimer.Elapsed += PingElapsed;
                m_pingTimer.Enable = false;

                using (m_poller = new NetMQPoller { m_pipe, m_pingTimer })
                {
                    m_poller.Run();
                }

                // the beacon might never been configured
                #if NET35
                m_udpSocket?.Close();
                #else
                m_udpSocket?.Dispose();
                #endif
            }
        private void Run(PairSocket shim)
        {
            using (m_publisherSocket = m_context.CreateXPublisherSocket())
            {
                m_publisherSocket.SetWelcomeMessage(WelcomeMessage);
                m_publisherSocket.Bind(m_address);

                m_publisherSocket.ReceiveReady += DropPublisherSubscriptions;

                m_heartbeatTimer = new NetMQTimer(HeartbeatInterval);
                m_heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;

                shim.ReceiveReady += OnShimMessage;

                // signal the actor that the shim is ready to work
                shim.SignalOK();

                m_poller = new Poller(m_publisherSocket, shim);
                m_poller.AddTimer(m_heartbeatTimer);

                // Polling until poller is cancelled
                m_poller.PollTillCancelled();
            }
        }