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.SendFrame(string.Format("Error: Exception occurred {0}", e.Message)); } } }
public void RunPipeline(Sockets.PairSocket shim) { m_pipe = shim; shim.SignalOK(); while (!m_terminated) { PollItem[] pollItems = new PollItem[] { new PollItem(m_pipe.SocketHandle, PollEvents.PollIn), new PollItem(m_udpSocket, PollEvents.PollIn), }; long timeout = -1; if (m_transmit != null) { timeout = m_pingAt - Clock.NowMs(); if (timeout < 0) { timeout = 0; } } ZMQ.Poll(pollItems, m_udpSocket != null ? 2 : 1, (int)timeout); if (pollItems[0].ResultEvent.HasFlag(PollEvents.PollIn)) { HandlePipe(); } if (pollItems[1].ResultEvent.HasFlag(PollEvents.PollIn)) { HandleUdp(); } if (m_transmit != null && Clock.NowMs() > m_pingAt) { SendUdpFrame(m_transmit); m_pingAt = Clock.NowMs() + m_interval; } } m_udpSocket.Dispose(); }
void IShimHandler.Run(PairSocket shim) { Poller = new NetMQPoller(); Shim = shim; Shim.ReceiveReady += OnShimReady; Poller.Add(Shim); Initialize(); Shim.SignalOK(); Poller.Run(); Cleanup(); }
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); 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 fault will bubble up to caller's code. catch (Exception e) { shim.Send(string.Format("Error: Exception occurred {0}", e.Message)); } } }
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(); if (command == NetMQActor.EndShimMessage) break; if (command == "ECHO") { shim.SendFrame(string.Format("ECHO BACK : {0}", msg[1].ConvertToString())); } 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(string.Format("Error: Exception occurred {0}", e.Message)); } } }
public void RunPipeline(Sockets.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.Start(); // the beacon might never been configured if (m_udpSocket != null) { m_udpSocket.Dispose(); } }
/// <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(); reapTimer.Enable = false; reapTimer.Elapsed -= OnReapTimerElapsed; }